From 74dd5d3852a99dedbdd7f684bc974ec64292a911 Mon Sep 17 00:00:00 2001 From: Paul Bellamy Date: Thu, 5 Nov 2015 16:44:45 +0000 Subject: [PATCH] fixing up some tests --- render/detailed_node_test.go | 119 +++++++++++++++++---------------- render/expected/expected.go | 4 +- report/topology.go | 5 ++ test/fixture/report_fixture.go | 19 +++++- 4 files changed, 87 insertions(+), 60 deletions(-) diff --git a/render/detailed_node_test.go b/render/detailed_node_test.go index d3be039c51..6c49ff6a58 100644 --- a/render/detailed_node_test.go +++ b/render/detailed_node_test.go @@ -25,8 +25,10 @@ func TestOriginTable(t *testing.T) { Numeric: false, Rank: 1, Rows: []render.Row{ - {"Load", "0.01 0.01 0.01", "", false}, - {"Operating system", "Linux", "", false}, + {Key: "Load (1m)", ValueMajor: "0.01", Metric: fixture.LoadMetric, ValueType: "sparkline"}, + {Key: "Load (5m)", ValueMajor: "0.01", Metric: fixture.LoadMetric, ValueType: "sparkline"}, + {Key: "Load (15m)", ValueMajor: "0.01", Metric: fixture.LoadMetric, ValueType: "sparkline"}, + {Key: "Operating system", ValueMajor: "Linux"}, }, }, } { @@ -47,8 +49,8 @@ func TestOriginTable(t *testing.T) { Numeric: false, Rank: 2, Rows: []render.Row{ - {"Host", fixture.ServerHostID, "", false}, - {"Container ID", fixture.ServerContainerID, "", false}, + {Key: "Host", ValueMajor: fixture.ServerHostID}, + {Key: "Container ID", ValueMajor: fixture.ServerContainerID}, }, }, fixture.ServerContainerNodeID: { @@ -56,13 +58,13 @@ func TestOriginTable(t *testing.T) { Numeric: false, Rank: 3, Rows: []render.Row{ - {"Host", fixture.ServerHostID, "", false}, - {"ID", fixture.ServerContainerID, "", false}, - {"Image ID", fixture.ServerContainerImageID, "", false}, - {fmt.Sprintf(`Label %q`, render.AmazonECSContainerNameLabel), `server`, "", false}, - {`Label "foo1"`, `bar1`, "", false}, - {`Label "foo2"`, `bar2`, "", false}, - {`Label "io.kubernetes.pod.name"`, "ping/pong-b", "", false}, + {Key: "Host", ValueMajor: fixture.ServerHostID}, + {Key: "ID", ValueMajor: fixture.ServerContainerID}, + {Key: "Image ID", ValueMajor: fixture.ServerContainerImageID}, + {Key: fmt.Sprintf(`Label %q`, render.AmazonECSContainerNameLabel), ValueMajor: `server`}, + {Key: `Label "foo1"`, ValueMajor: `bar1`}, + {Key: `Label "foo2"`, ValueMajor: `bar2`}, + {Key: `Label "io.kubernetes.pod.name"`, ValueMajor: "ping/pong-b"}, }, }, } { @@ -93,14 +95,26 @@ func TestMakeDetailedHostNode(t *testing.T) { Rank: 1, Rows: []render.Row{ { - Key: "Load", - ValueMajor: "0.01 0.01 0.01", - ValueMinor: "", + Key: "Load (1m)", + ValueMajor: "0.01", + Metric: fixture.LoadMetric, + ValueType: "sparkline", + }, + { + Key: "Load (5m)", + ValueMajor: "0.01", + Metric: fixture.LoadMetric, + ValueType: "sparkline", + }, + { + Key: "Load (15m)", + ValueMajor: "0.01", + Metric: fixture.LoadMetric, + ValueType: "sparkline", }, { Key: "Operating system", ValueMajor: "Linux", - ValueMinor: "", }, }, }, @@ -112,18 +126,15 @@ func TestMakeDetailedHostNode(t *testing.T) { { Key: "TCP connections", ValueMajor: "3", - ValueMinor: "", }, { Key: "Client", ValueMajor: "Server", - ValueMinor: "", Expandable: true, }, { Key: "10.10.10.20", ValueMajor: "192.168.1.1", - ValueMinor: "", Expandable: true, }, }, @@ -149,9 +160,9 @@ func TestMakeDetailedContainerNode(t *testing.T) { Numeric: false, Rank: 4, Rows: []render.Row{ - {"Image ID", fixture.ServerContainerImageID, "", false}, - {`Label "foo1"`, `bar1`, "", false}, - {`Label "foo2"`, `bar2`, "", false}, + {Key: "Image ID", ValueMajor: fixture.ServerContainerImageID}, + {Key: `Label "foo1"`, ValueMajor: `bar1`}, + {Key: `Label "foo2"`, ValueMajor: `bar2`}, }, }, { @@ -159,12 +170,12 @@ func TestMakeDetailedContainerNode(t *testing.T) { Numeric: false, Rank: 3, Rows: []render.Row{ - {"ID", fixture.ServerContainerID, "", false}, - {"Image ID", fixture.ServerContainerImageID, "", false}, - {fmt.Sprintf(`Label %q`, render.AmazonECSContainerNameLabel), `server`, "", false}, - {`Label "foo1"`, `bar1`, "", false}, - {`Label "foo2"`, `bar2`, "", false}, - {`Label "io.kubernetes.pod.name"`, "ping/pong-b", "", false}, + {Key: "ID", ValueMajor: fixture.ServerContainerID}, + {Key: "Image ID", ValueMajor: fixture.ServerContainerImageID}, + {Key: fmt.Sprintf(`Label %q`, render.AmazonECSContainerNameLabel), ValueMajor: `server`}, + {Key: `Label "foo1"`, ValueMajor: `bar1`}, + {Key: `Label "foo2"`, ValueMajor: `bar2`}, + {Key: `Label "io.kubernetes.pod.name"`, ValueMajor: "ping/pong-b"}, }, }, { @@ -178,8 +189,10 @@ func TestMakeDetailedContainerNode(t *testing.T) { Numeric: false, Rank: 1, Rows: []render.Row{ - {"Load", "0.01 0.01 0.01", "", false}, - {"Operating system", "Linux", "", false}, + {Key: "Load (1m)", ValueMajor: "0.01", Metric: fixture.LoadMetric, ValueType: "sparkline"}, + {Key: "Load (5m)", ValueMajor: "0.01", Metric: fixture.LoadMetric, ValueType: "sparkline"}, + {Key: "Load (15m)", ValueMajor: "0.01", Metric: fixture.LoadMetric, ValueType: "sparkline"}, + {Key: "Operating system", ValueMajor: "Linux"}, }, }, { @@ -187,44 +200,38 @@ func TestMakeDetailedContainerNode(t *testing.T) { Numeric: false, Rank: 0, Rows: []render.Row{ - {"Ingress packet rate", "105", "packets/sec", false}, - {"Ingress byte rate", "1.0", "KBps", false}, - {"Client", "Server", "", true}, + {Key: "Ingress packet rate", ValueMajor: "105", ValueMinor: "packets/sec"}, + {Key: "Ingress byte rate", ValueMajor: "1.0", ValueMinor: "KBps"}, + {Key: "Client", ValueMajor: "Server", Expandable: true}, { - fmt.Sprintf("%s:%s", fixture.UnknownClient1IP, fixture.UnknownClient1Port), - fmt.Sprintf("%s:%s", fixture.ServerIP, fixture.ServerPort), - "", - true, + Key: fmt.Sprintf("%s:%s", fixture.UnknownClient1IP, fixture.UnknownClient1Port), + ValueMajor: fmt.Sprintf("%s:%s", fixture.ServerIP, fixture.ServerPort), + Expandable: true, }, { - fmt.Sprintf("%s:%s", fixture.UnknownClient2IP, fixture.UnknownClient2Port), - fmt.Sprintf("%s:%s", fixture.ServerIP, fixture.ServerPort), - "", - true, + Key: fmt.Sprintf("%s:%s", fixture.UnknownClient2IP, fixture.UnknownClient2Port), + ValueMajor: fmt.Sprintf("%s:%s", fixture.ServerIP, fixture.ServerPort), + Expandable: true, }, { - fmt.Sprintf("%s:%s", fixture.UnknownClient3IP, fixture.UnknownClient3Port), - fmt.Sprintf("%s:%s", fixture.ServerIP, fixture.ServerPort), - "", - true, + Key: fmt.Sprintf("%s:%s", fixture.UnknownClient3IP, fixture.UnknownClient3Port), + ValueMajor: fmt.Sprintf("%s:%s", fixture.ServerIP, fixture.ServerPort), + Expandable: true, }, { - fmt.Sprintf("%s:%s", fixture.ClientIP, fixture.ClientPort54001), - fmt.Sprintf("%s:%s", fixture.ServerIP, fixture.ServerPort), - "", - true, + Key: fmt.Sprintf("%s:%s", fixture.ClientIP, fixture.ClientPort54001), + ValueMajor: fmt.Sprintf("%s:%s", fixture.ServerIP, fixture.ServerPort), + Expandable: true, }, { - fmt.Sprintf("%s:%s", fixture.ClientIP, fixture.ClientPort54002), - fmt.Sprintf("%s:%s", fixture.ServerIP, fixture.ServerPort), - "", - true, + Key: fmt.Sprintf("%s:%s", fixture.ClientIP, fixture.ClientPort54002), + ValueMajor: fmt.Sprintf("%s:%s", fixture.ServerIP, fixture.ServerPort), + Expandable: true, }, { - fmt.Sprintf("%s:%s", fixture.RandomClientIP, fixture.RandomClientPort), - fmt.Sprintf("%s:%s", fixture.ServerIP, fixture.ServerPort), - "", - true, + Key: fmt.Sprintf("%s:%s", fixture.RandomClientIP, fixture.RandomClientPort), + ValueMajor: fmt.Sprintf("%s:%s", fixture.ServerIP, fixture.ServerPort), + Expandable: true, }, }, }, diff --git a/render/expected/expected.go b/render/expected/expected.go index f977fcf702..6877e01d4b 100644 --- a/render/expected/expected.go +++ b/render/expected/expected.go @@ -323,7 +323,7 @@ var ( fixture.ServerHostNodeID, fixture.ServerAddressNodeID, ), - Node: report.MakeNode(), + Node: report.MakeNode().WithMetrics(fixture.LoadMetrics), EdgeMetadata: report.EdgeMetadata{ MaxConnCountTCP: newu64(3), }, @@ -338,7 +338,7 @@ var ( fixture.ClientHostNodeID, fixture.ClientAddressNodeID, ), - Node: report.MakeNode().WithAdjacent(ServerHostRenderedID), + Node: report.MakeNode().WithAdjacent(ServerHostRenderedID).WithMetrics(fixture.LoadMetrics), EdgeMetadata: report.EdgeMetadata{ MaxConnCountTCP: newu64(3), }, diff --git a/report/topology.go b/report/topology.go index 8c82ddd424..a0f845d070 100644 --- a/report/topology.go +++ b/report/topology.go @@ -373,6 +373,11 @@ func MakeMetric() Metric { return Metric{} } +func (m Metric) WithFirst(t time.Time) Metric { + m.First = t + return m +} + // Add adds the sample to the Metric. Add is the only valid way to grow a // Metric. Add returns the Metric to enable chaining. func (m Metric) Add(t time.Time, v float64) Metric { diff --git a/test/fixture/report_fixture.go b/test/fixture/report_fixture.go index 15b2aab6a9..ce5bfb3380 100644 --- a/test/fixture/report_fixture.go +++ b/test/fixture/report_fixture.go @@ -15,6 +15,8 @@ import ( // This is an example Report: // 2 hosts with probes installed - client & server. var ( + Now = time.Now() + ClientHostID = "client.hostname.com" ServerHostID = "server.hostname.com" UnknownHostID = "" @@ -96,6 +98,13 @@ var ( ServiceID = "ping/pongservice" ServiceNodeID = report.MakeServiceNodeID("ping", "pongservice") + LoadMetric = report.MakeMetric().Add(Now, 0.01).WithFirst(Now.Add(-15 * time.Second)) + LoadMetrics = report.Metrics{ + host.Load1: LoadMetric, + host.Load5: LoadMetric, + host.Load15: LoadMetric, + } + Report = report.Report{ Endpoint: report.Topology{ Nodes: report.Nodes{ @@ -284,18 +293,24 @@ var ( ClientHostNodeID: report.MakeNodeWith(map[string]string{ "host_name": ClientHostName, "os": "Linux", - "load": "0.01 0.01 0.01", report.HostNodeID: ClientHostNodeID, }).WithSets(report.Sets{ host.LocalNetworks: report.MakeStringSet("10.10.10.0/24"), + }).WithMetrics(report.Metrics{ + host.Load1: LoadMetric, + host.Load5: LoadMetric, + host.Load15: LoadMetric, }), ServerHostNodeID: report.MakeNodeWith(map[string]string{ "host_name": ServerHostName, "os": "Linux", - "load": "0.01 0.01 0.01", report.HostNodeID: ServerHostNodeID, }).WithSets(report.Sets{ host.LocalNetworks: report.MakeStringSet("10.10.10.0/24"), + }).WithMetrics(report.Metrics{ + host.Load1: LoadMetric, + host.Load5: LoadMetric, + host.Load15: LoadMetric, }), }, },