Skip to content

Commit

Permalink
fixing up some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbellamy committed Nov 5, 2015
1 parent 35069a0 commit 74dd5d3
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 60 deletions.
119 changes: 63 additions & 56 deletions render/detailed_node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
},
},
} {
Expand All @@ -47,22 +49,22 @@ 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: {
Title: `Container "server"`,
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"},
},
},
} {
Expand Down Expand Up @@ -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: "",
},
},
},
Expand All @@ -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,
},
},
Expand All @@ -149,22 +160,22 @@ 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`},
},
},
{
Title: `Container "server"`,
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"},
},
},
{
Expand All @@ -178,53 +189,49 @@ 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"},
},
},
{
Title: "Connections",
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,
},
},
},
Expand Down
4 changes: 2 additions & 2 deletions render/expected/expected.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ var (
fixture.ServerHostNodeID,
fixture.ServerAddressNodeID,
),
Node: report.MakeNode(),
Node: report.MakeNode().WithMetrics(fixture.LoadMetrics),
EdgeMetadata: report.EdgeMetadata{
MaxConnCountTCP: newu64(3),
},
Expand All @@ -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),
},
Expand Down
5 changes: 5 additions & 0 deletions report/topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
19 changes: 17 additions & 2 deletions test/fixture/report_fixture.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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,
}),
},
},
Expand Down

0 comments on commit 74dd5d3

Please sign in to comment.