mirror of
https://github.com/weaveworks/scope.git
synced 2026-07-19 05:19:35 +00:00
Update IDList
- MakeIDList rather than NewIDList - Iterate on test coverage - Drop Copy method, for now
This commit is contained in:
@@ -27,8 +27,8 @@ func TestAPITopologyApplications(t *testing.T) {
|
||||
t.Errorf("missing curl node")
|
||||
}
|
||||
equals(t, 1, len(node.Adjacency))
|
||||
equals(t, report.NewIDList("pid:node-b.local:215"), node.Adjacency)
|
||||
equals(t, report.NewIDList("hostA"), node.OriginHosts)
|
||||
equals(t, report.MakeIDList("pid:node-b.local:215"), node.Adjacency)
|
||||
equals(t, report.MakeIDList("hostA"), node.OriginHosts)
|
||||
equals(t, "curl", node.LabelMajor)
|
||||
equals(t, "node-a.local (23128)", node.LabelMinor)
|
||||
equals(t, "23128", node.Rank)
|
||||
@@ -78,8 +78,8 @@ func TestAPITopologyHosts(t *testing.T) {
|
||||
if !ok {
|
||||
t.Errorf("missing host:host-b node")
|
||||
}
|
||||
equals(t, report.NewIDList("host:host-a"), node.Adjacency)
|
||||
equals(t, report.NewIDList("hostB"), node.OriginHosts)
|
||||
equals(t, report.MakeIDList("host:host-a"), node.Adjacency)
|
||||
equals(t, report.MakeIDList("hostB"), node.OriginHosts)
|
||||
equals(t, "host-b", node.LabelMajor)
|
||||
equals(t, "", node.LabelMinor)
|
||||
equals(t, "host-b", node.Rank)
|
||||
|
||||
@@ -18,10 +18,10 @@ func (s StaticReport) Report() report.Report {
|
||||
var testReport = report.Report{
|
||||
Process: report.Topology{
|
||||
Adjacency: report.Adjacency{
|
||||
report.MakeAdjacencyID("hostA", report.MakeEndpointNodeID("hostA", "192.168.1.1", "12345")): report.NewIDList(report.MakeEndpointNodeID("hostB", "192.168.1.2", "80")),
|
||||
report.MakeAdjacencyID("hostA", report.MakeEndpointNodeID("hostA", "192.168.1.1", "12346")): report.NewIDList(report.MakeEndpointNodeID("hostB", "192.168.1.2", "80")),
|
||||
report.MakeAdjacencyID("hostA", report.MakeEndpointNodeID("hostA", "192.168.1.1", "8888")): report.NewIDList(report.MakeEndpointNodeID("", "1.2.3.4", "22")),
|
||||
report.MakeAdjacencyID("hostB", report.MakeEndpointNodeID("hostB", "192.168.1.2", "80")): report.NewIDList(report.MakeEndpointNodeID("hostA", "192.168.1.1", "12345")),
|
||||
report.MakeAdjacencyID("hostA", report.MakeEndpointNodeID("hostA", "192.168.1.1", "12345")): report.MakeIDList(report.MakeEndpointNodeID("hostB", "192.168.1.2", "80")),
|
||||
report.MakeAdjacencyID("hostA", report.MakeEndpointNodeID("hostA", "192.168.1.1", "12346")): report.MakeIDList(report.MakeEndpointNodeID("hostB", "192.168.1.2", "80")),
|
||||
report.MakeAdjacencyID("hostA", report.MakeEndpointNodeID("hostA", "192.168.1.1", "8888")): report.MakeIDList(report.MakeEndpointNodeID("", "1.2.3.4", "22")),
|
||||
report.MakeAdjacencyID("hostB", report.MakeEndpointNodeID("hostB", "192.168.1.2", "80")): report.MakeIDList(report.MakeEndpointNodeID("hostA", "192.168.1.1", "12345")),
|
||||
},
|
||||
EdgeMetadatas: report.EdgeMetadatas{
|
||||
report.MakeEdgeID(report.MakeEndpointNodeID("hostA", "192.168.1.1", "12345"), report.MakeEndpointNodeID("hostB", "192.168.1.2", "80")): report.EdgeMetadata{
|
||||
@@ -79,8 +79,8 @@ func (s StaticReport) Report() report.Report {
|
||||
|
||||
Network: report.Topology{
|
||||
Adjacency: report.Adjacency{
|
||||
report.MakeAdjacencyID("hostA", report.MakeAddressNodeID("hostA", "192.168.1.1")): report.NewIDList(report.MakeAddressNodeID("hostB", "192.168.1.2"), report.MakeAddressNodeID("", "1.2.3.4")),
|
||||
report.MakeAdjacencyID("hostB", report.MakeAddressNodeID("hostB", "192.168.1.2")): report.NewIDList(report.MakeAddressNodeID("hostA", "192.168.1.1")),
|
||||
report.MakeAdjacencyID("hostA", report.MakeAddressNodeID("hostA", "192.168.1.1")): report.MakeIDList(report.MakeAddressNodeID("hostB", "192.168.1.2"), report.MakeAddressNodeID("", "1.2.3.4")),
|
||||
report.MakeAdjacencyID("hostB", report.MakeAddressNodeID("hostB", "192.168.1.2")): report.MakeIDList(report.MakeAddressNodeID("hostA", "192.168.1.1")),
|
||||
},
|
||||
EdgeMetadatas: report.EdgeMetadatas{
|
||||
report.MakeEdgeID(report.MakeAddressNodeID("hostA", "192.168.1.1"), report.MakeAddressNodeID("hostB", "192.168.1.2")): report.EdgeMetadata{
|
||||
|
||||
@@ -86,7 +86,7 @@ func parseEdge(t *testing.T, p []byte) map[string]interface{} {
|
||||
}
|
||||
|
||||
func assertAdjacent(t *testing.T, n report.RenderableNode, ids ...string) {
|
||||
want := report.NewIDList(ids...)
|
||||
want := report.MakeIDList(ids...)
|
||||
|
||||
if have := n.Adjacency; !reflect.DeepEqual(want, have) {
|
||||
t.Fatalf("want adjacency list %v, have %v", want, have)
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
package report
|
||||
|
||||
import (
|
||||
"sort"
|
||||
)
|
||||
import "sort"
|
||||
|
||||
// IDList is a list of string IDs, which are always sorted and
|
||||
// without duplicates.
|
||||
// IDList is a list of string IDs, which are always sorted and unique.
|
||||
type IDList []string
|
||||
|
||||
// NewIDList makes a new IDList.
|
||||
func NewIDList(ids ...string) IDList {
|
||||
// MakeIDList makes a new IDList.
|
||||
func MakeIDList(ids ...string) IDList {
|
||||
sort.Strings(ids)
|
||||
return IDList(ids)
|
||||
}
|
||||
22
report/id_list_test.go
Normal file
22
report/id_list_test.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package report_test
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/weaveworks/scope/report"
|
||||
)
|
||||
|
||||
func TestIDList(t *testing.T) {
|
||||
have := report.MakeIDList("alpha", "mu", "zeta")
|
||||
have = have.Add("alpha")
|
||||
have = have.Add("nu")
|
||||
have = have.Add("mu")
|
||||
have = have.Add("alpha")
|
||||
have = have.Add("alpha")
|
||||
have = have.Add("epsilon")
|
||||
have = have.Add("delta")
|
||||
if want := report.IDList([]string{"alpha", "delta", "epsilon", "mu", "nu", "zeta"}); !reflect.DeepEqual(want, have) {
|
||||
t.Errorf("want %+v, have %+v", want, have)
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
package report
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestidList(t *testing.T) {
|
||||
var have IDList
|
||||
have = have.Add("aap")
|
||||
have = have.Add("noot")
|
||||
have = have.Add("mies")
|
||||
have = have.Add("aap")
|
||||
have = have.Add("aap")
|
||||
have = have.Add("wim")
|
||||
have = have.Add("vuur")
|
||||
|
||||
if want := IDList([]string{"aap", "mies", "noot", "vuur", "wim"}); !reflect.DeepEqual(want, have) {
|
||||
t.Errorf("want %+v, have %+v", want, have)
|
||||
}
|
||||
}
|
||||
@@ -12,53 +12,53 @@ func TestMergeAdjacency(t *testing.T) {
|
||||
}{
|
||||
"Empty b": {
|
||||
a: Adjacency{
|
||||
"hostA|:192.168.1.1:12345": NewIDList(":192.168.1.2:80"),
|
||||
"hostA|:192.168.1.1:8888": NewIDList(":1.2.3.4:22"),
|
||||
"hostB|:192.168.1.2:80": NewIDList(":192.168.1.1:12345"),
|
||||
"hostA|:192.168.1.1:12345": MakeIDList(":192.168.1.2:80"),
|
||||
"hostA|:192.168.1.1:8888": MakeIDList(":1.2.3.4:22"),
|
||||
"hostB|:192.168.1.2:80": MakeIDList(":192.168.1.1:12345"),
|
||||
},
|
||||
b: Adjacency{},
|
||||
want: Adjacency{
|
||||
"hostA|:192.168.1.1:12345": NewIDList(":192.168.1.2:80"),
|
||||
"hostA|:192.168.1.1:8888": NewIDList(":1.2.3.4:22"),
|
||||
"hostB|:192.168.1.2:80": NewIDList(":192.168.1.1:12345"),
|
||||
"hostA|:192.168.1.1:12345": MakeIDList(":192.168.1.2:80"),
|
||||
"hostA|:192.168.1.1:8888": MakeIDList(":1.2.3.4:22"),
|
||||
"hostB|:192.168.1.2:80": MakeIDList(":192.168.1.1:12345"),
|
||||
},
|
||||
},
|
||||
"Empty a": {
|
||||
a: Adjacency{},
|
||||
b: Adjacency{
|
||||
"hostA|:192.168.1.1:12345": NewIDList(":192.168.1.2:80"),
|
||||
"hostA|:192.168.1.1:8888": NewIDList(":1.2.3.4:22"),
|
||||
"hostB|:192.168.1.2:80": NewIDList(":192.168.1.1:12345"),
|
||||
"hostA|:192.168.1.1:12345": MakeIDList(":192.168.1.2:80"),
|
||||
"hostA|:192.168.1.1:8888": MakeIDList(":1.2.3.4:22"),
|
||||
"hostB|:192.168.1.2:80": MakeIDList(":192.168.1.1:12345"),
|
||||
},
|
||||
want: Adjacency{
|
||||
"hostA|:192.168.1.1:12345": NewIDList(":192.168.1.2:80"),
|
||||
"hostA|:192.168.1.1:8888": NewIDList(":1.2.3.4:22"),
|
||||
"hostB|:192.168.1.2:80": NewIDList(":192.168.1.1:12345"),
|
||||
"hostA|:192.168.1.1:12345": MakeIDList(":192.168.1.2:80"),
|
||||
"hostA|:192.168.1.1:8888": MakeIDList(":1.2.3.4:22"),
|
||||
"hostB|:192.168.1.2:80": MakeIDList(":192.168.1.1:12345"),
|
||||
},
|
||||
},
|
||||
"Same address": {
|
||||
a: Adjacency{
|
||||
"hostA|:192.168.1.1:12345": NewIDList(":192.168.1.2:80"),
|
||||
"hostA|:192.168.1.1:12345": MakeIDList(":192.168.1.2:80"),
|
||||
},
|
||||
b: Adjacency{
|
||||
"hostA|:192.168.1.1:12345": NewIDList(":192.168.1.2:8080"),
|
||||
"hostA|:192.168.1.1:12345": MakeIDList(":192.168.1.2:8080"),
|
||||
},
|
||||
want: Adjacency{
|
||||
"hostA|:192.168.1.1:12345": NewIDList(
|
||||
"hostA|:192.168.1.1:12345": MakeIDList(
|
||||
":192.168.1.2:80", ":192.168.1.2:8080",
|
||||
),
|
||||
},
|
||||
},
|
||||
"No duplicates": {
|
||||
a: Adjacency{
|
||||
"hostA|:192.168.1.1:12345": NewIDList(
|
||||
"hostA|:192.168.1.1:12345": MakeIDList(
|
||||
":192.168.1.2:80",
|
||||
":192.168.1.2:8080",
|
||||
":192.168.1.2:555",
|
||||
),
|
||||
},
|
||||
b: Adjacency{
|
||||
"hostA|:192.168.1.1:12345": NewIDList(
|
||||
"hostA|:192.168.1.1:12345": MakeIDList(
|
||||
":192.168.1.2:8080",
|
||||
":192.168.1.2:80",
|
||||
":192.168.1.2:444",
|
||||
@@ -75,17 +75,17 @@ func TestMergeAdjacency(t *testing.T) {
|
||||
},
|
||||
"Double keys": {
|
||||
a: Adjacency{
|
||||
"key1": NewIDList("a", "c", "d", "b"),
|
||||
"key2": NewIDList("c", "a"),
|
||||
"key1": MakeIDList("a", "c", "d", "b"),
|
||||
"key2": MakeIDList("c", "a"),
|
||||
},
|
||||
b: Adjacency{
|
||||
"key1": NewIDList("a", "b", "e"),
|
||||
"key3": NewIDList("e", "a", "a", "a", "e"),
|
||||
"key1": MakeIDList("a", "b", "e"),
|
||||
"key3": MakeIDList("e", "a", "a", "a", "e"),
|
||||
},
|
||||
want: Adjacency{
|
||||
"key1": NewIDList("a", "b", "c", "d", "e"),
|
||||
"key2": NewIDList("a", "c"),
|
||||
"key3": NewIDList("a", "e"),
|
||||
"key1": MakeIDList("a", "b", "c", "d", "e"),
|
||||
"key2": MakeIDList("a", "c"),
|
||||
"key3": MakeIDList("a", "e"),
|
||||
},
|
||||
},
|
||||
} {
|
||||
|
||||
@@ -36,9 +36,9 @@ var (
|
||||
report = Report{
|
||||
Process: Topology{
|
||||
Adjacency: Adjacency{
|
||||
MakeAdjacencyID("client.hostname.com", client54001): NewIDList(server80),
|
||||
MakeAdjacencyID("client.hostname.com", client54002): NewIDList(server80),
|
||||
MakeAdjacencyID("server.hostname.com", server80): NewIDList(client54001, client54002, unknownClient1, unknownClient2, unknownClient3),
|
||||
MakeAdjacencyID("client.hostname.com", client54001): MakeIDList(server80),
|
||||
MakeAdjacencyID("client.hostname.com", client54002): MakeIDList(server80),
|
||||
MakeAdjacencyID("server.hostname.com", server80): MakeIDList(client54001, client54002, unknownClient1, unknownClient2, unknownClient3),
|
||||
},
|
||||
NodeMetadatas: NodeMetadatas{
|
||||
// NodeMetadata is arbitrary. We're free to put only precisely what we
|
||||
@@ -101,9 +101,9 @@ var (
|
||||
},
|
||||
Network: Topology{
|
||||
Adjacency: Adjacency{
|
||||
MakeAdjacencyID("client.hostname.com", clientIP): NewIDList(serverIP),
|
||||
MakeAdjacencyID("random.hostname.com", randomIP): NewIDList(serverIP),
|
||||
MakeAdjacencyID("server.hostname.com", serverIP): NewIDList(clientIP, unknownIP), // no backlink to random
|
||||
MakeAdjacencyID("client.hostname.com", clientIP): MakeIDList(serverIP),
|
||||
MakeAdjacencyID("random.hostname.com", randomIP): MakeIDList(serverIP),
|
||||
MakeAdjacencyID("server.hostname.com", serverIP): MakeIDList(clientIP, unknownIP), // no backlink to random
|
||||
},
|
||||
NodeMetadatas: NodeMetadatas{
|
||||
clientIP: NodeMetadata{
|
||||
@@ -146,9 +146,9 @@ func TestRenderByProcessPID(t *testing.T) {
|
||||
LabelMinor: "client-54001-domain (10001)",
|
||||
Rank: "10001",
|
||||
Pseudo: false,
|
||||
Adjacency: NewIDList("pid:server-80-domain:215"),
|
||||
OriginHosts: NewIDList("client.hostname.com"),
|
||||
OriginNodes: NewIDList("client.hostname.com;10.10.10.20;54001"),
|
||||
Adjacency: MakeIDList("pid:server-80-domain:215"),
|
||||
OriginHosts: MakeIDList("client.hostname.com"),
|
||||
OriginNodes: MakeIDList("client.hostname.com;10.10.10.20;54001"),
|
||||
Metadata: AggregateMetadata{
|
||||
KeyBytesIngress: 100,
|
||||
KeyBytesEgress: 10,
|
||||
@@ -160,9 +160,9 @@ func TestRenderByProcessPID(t *testing.T) {
|
||||
LabelMinor: "client-54002-domain (10001)",
|
||||
Rank: "10001", // same process
|
||||
Pseudo: false,
|
||||
Adjacency: NewIDList("pid:server-80-domain:215"),
|
||||
OriginHosts: NewIDList("client.hostname.com"),
|
||||
OriginNodes: NewIDList("client.hostname.com;10.10.10.20;54002"),
|
||||
Adjacency: MakeIDList("pid:server-80-domain:215"),
|
||||
OriginHosts: MakeIDList("client.hostname.com"),
|
||||
OriginNodes: MakeIDList("client.hostname.com;10.10.10.20;54002"),
|
||||
Metadata: AggregateMetadata{
|
||||
KeyBytesIngress: 200,
|
||||
KeyBytesEgress: 20,
|
||||
@@ -174,14 +174,14 @@ func TestRenderByProcessPID(t *testing.T) {
|
||||
LabelMinor: "server-80-domain (215)",
|
||||
Rank: "215",
|
||||
Pseudo: false,
|
||||
Adjacency: NewIDList(
|
||||
Adjacency: MakeIDList(
|
||||
"pid:client-54001-domain:10001",
|
||||
"pid:client-54002-domain:10001",
|
||||
"pseudo;10.10.10.10;192.168.1.1;80",
|
||||
"pseudo;10.10.10.11;192.168.1.1;80",
|
||||
),
|
||||
OriginHosts: NewIDList("server.hostname.com"),
|
||||
OriginNodes: NewIDList("server.hostname.com;192.168.1.1;80"),
|
||||
OriginHosts: MakeIDList("server.hostname.com"),
|
||||
OriginNodes: MakeIDList("server.hostname.com;192.168.1.1;80"),
|
||||
Metadata: AggregateMetadata{
|
||||
KeyBytesIngress: 150,
|
||||
KeyBytesEgress: 1500,
|
||||
@@ -217,9 +217,9 @@ func TestRenderByProcessPIDGrouped(t *testing.T) {
|
||||
LabelMinor: "",
|
||||
Rank: "curl",
|
||||
Pseudo: false,
|
||||
Adjacency: NewIDList("apache"),
|
||||
OriginHosts: NewIDList("client.hostname.com"),
|
||||
OriginNodes: NewIDList("client.hostname.com;10.10.10.20;54001", "client.hostname.com;10.10.10.20;54002"),
|
||||
Adjacency: MakeIDList("apache"),
|
||||
OriginHosts: MakeIDList("client.hostname.com"),
|
||||
OriginNodes: MakeIDList("client.hostname.com;10.10.10.20;54001", "client.hostname.com;10.10.10.20;54002"),
|
||||
Metadata: AggregateMetadata{
|
||||
KeyBytesIngress: 300,
|
||||
KeyBytesEgress: 30,
|
||||
@@ -231,13 +231,13 @@ func TestRenderByProcessPIDGrouped(t *testing.T) {
|
||||
LabelMinor: "",
|
||||
Rank: "apache",
|
||||
Pseudo: false,
|
||||
Adjacency: NewIDList(
|
||||
Adjacency: MakeIDList(
|
||||
"curl",
|
||||
"pseudo;10.10.10.10;apache",
|
||||
"pseudo;10.10.10.11;apache",
|
||||
),
|
||||
OriginHosts: NewIDList("server.hostname.com"),
|
||||
OriginNodes: NewIDList("server.hostname.com;192.168.1.1;80"),
|
||||
OriginHosts: MakeIDList("server.hostname.com"),
|
||||
OriginNodes: MakeIDList("server.hostname.com;192.168.1.1;80"),
|
||||
Metadata: AggregateMetadata{
|
||||
KeyBytesIngress: 150,
|
||||
KeyBytesEgress: 1500,
|
||||
@@ -270,9 +270,9 @@ func TestRenderByNetworkHostname(t *testing.T) {
|
||||
LabelMinor: "hostname.com", // after first .
|
||||
Rank: "client",
|
||||
Pseudo: false,
|
||||
Adjacency: NewIDList("host:server.hostname.com"),
|
||||
OriginHosts: NewIDList("client.hostname.com"),
|
||||
OriginNodes: NewIDList("client.hostname.com;10.10.10.20"),
|
||||
Adjacency: MakeIDList("host:server.hostname.com"),
|
||||
OriginHosts: MakeIDList("client.hostname.com"),
|
||||
OriginNodes: MakeIDList("client.hostname.com;10.10.10.20"),
|
||||
Metadata: AggregateMetadata{
|
||||
KeyMaxConnCountTCP: 3,
|
||||
},
|
||||
@@ -283,9 +283,9 @@ func TestRenderByNetworkHostname(t *testing.T) {
|
||||
LabelMinor: "hostname.com", // after first .
|
||||
Rank: "random",
|
||||
Pseudo: false,
|
||||
Adjacency: NewIDList("host:server.hostname.com"),
|
||||
OriginHosts: NewIDList("random.hostname.com"),
|
||||
OriginNodes: NewIDList("random.hostname.com;172.16.11.9"),
|
||||
Adjacency: MakeIDList("host:server.hostname.com"),
|
||||
OriginHosts: MakeIDList("random.hostname.com"),
|
||||
OriginNodes: MakeIDList("random.hostname.com;172.16.11.9"),
|
||||
Metadata: AggregateMetadata{
|
||||
KeyMaxConnCountTCP: 20,
|
||||
},
|
||||
@@ -296,9 +296,9 @@ func TestRenderByNetworkHostname(t *testing.T) {
|
||||
LabelMinor: "hostname.com", // after first .
|
||||
Rank: "server",
|
||||
Pseudo: false,
|
||||
Adjacency: NewIDList("host:client.hostname.com", "pseudo;10.10.10.10;192.168.1.1;"),
|
||||
OriginHosts: NewIDList("server.hostname.com"),
|
||||
OriginNodes: NewIDList("server.hostname.com;192.168.1.1"),
|
||||
Adjacency: MakeIDList("host:client.hostname.com", "pseudo;10.10.10.10;192.168.1.1;"),
|
||||
OriginHosts: MakeIDList("server.hostname.com"),
|
||||
OriginNodes: MakeIDList("server.hostname.com;192.168.1.1"),
|
||||
Metadata: AggregateMetadata{
|
||||
KeyMaxConnCountTCP: 10,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user