mirror of
https://github.com/weaveworks/scope.git
synced 2026-07-18 21:09:38 +00:00
Review feedback.
This commit is contained in:
@@ -8,14 +8,9 @@ import (
|
||||
)
|
||||
|
||||
func TestCountersAdd(t *testing.T) {
|
||||
want := EmptyCounters.
|
||||
Add("foo", 3)
|
||||
have := EmptyCounters.
|
||||
Add("foo", 1).
|
||||
Add("foo", 2)
|
||||
if !reflect.DeepEqual(want, have) {
|
||||
t.Errorf(test.Diff(want, have))
|
||||
}
|
||||
if v, ok := have.Lookup("foo"); !ok || v != 3 {
|
||||
t.Errorf("foo != 3")
|
||||
}
|
||||
@@ -24,6 +19,16 @@ func TestCountersAdd(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCountersDeepEquals(t *testing.T) {
|
||||
want := EmptyCounters.
|
||||
Add("foo", 3)
|
||||
have := EmptyCounters.
|
||||
Add("foo", 3)
|
||||
if !reflect.DeepEqual(want, have) {
|
||||
t.Errorf(test.Diff(want, have))
|
||||
}
|
||||
}
|
||||
|
||||
func TestCountersMerge(t *testing.T) {
|
||||
for name, c := range map[string]struct {
|
||||
a, b, want Counters
|
||||
@@ -42,7 +47,7 @@ func TestCountersMerge(t *testing.T) {
|
||||
want: EmptyCounters.
|
||||
Add("foo", 1),
|
||||
},
|
||||
"Disparate keys": {
|
||||
"Disjoin a & b": {
|
||||
a: EmptyCounters.
|
||||
Add("foo", 1),
|
||||
b: EmptyCounters.
|
||||
@@ -51,7 +56,7 @@ func TestCountersMerge(t *testing.T) {
|
||||
Add("foo", 1).
|
||||
Add("bar", 2),
|
||||
},
|
||||
"Key merge": {
|
||||
"Overlapping a & b": {
|
||||
a: EmptyCounters.
|
||||
Add("foo", 1),
|
||||
b: EmptyCounters.
|
||||
|
||||
@@ -8,11 +8,6 @@ import (
|
||||
)
|
||||
|
||||
func TestEdgeMetadatasAdd(t *testing.T) {
|
||||
want := EmptyEdgeMetadatas.
|
||||
Add("foo",
|
||||
EdgeMetadata{
|
||||
EgressPacketCount: newu64(3),
|
||||
})
|
||||
have := EmptyEdgeMetadatas.
|
||||
Add("foo",
|
||||
EdgeMetadata{
|
||||
@@ -22,9 +17,6 @@ func TestEdgeMetadatasAdd(t *testing.T) {
|
||||
EdgeMetadata{
|
||||
EgressPacketCount: newu64(2),
|
||||
})
|
||||
if !reflect.DeepEqual(want, have) {
|
||||
t.Errorf(test.Diff(want, have))
|
||||
}
|
||||
if emd, ok := have.Lookup("foo"); !ok || *emd.EgressPacketCount != 3 {
|
||||
t.Errorf("foo.EgressPacketCount != 3")
|
||||
}
|
||||
@@ -45,6 +37,22 @@ func TestEdgeMetadatasAddNil(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestEdgeMetadatasDeepEquals(t *testing.T) {
|
||||
want := EmptyEdgeMetadatas.
|
||||
Add("foo",
|
||||
EdgeMetadata{
|
||||
EgressPacketCount: newu64(3),
|
||||
})
|
||||
have := EmptyEdgeMetadatas.
|
||||
Add("foo",
|
||||
EdgeMetadata{
|
||||
EgressPacketCount: newu64(3),
|
||||
})
|
||||
if !reflect.DeepEqual(want, have) {
|
||||
t.Errorf(test.Diff(want, have))
|
||||
}
|
||||
}
|
||||
|
||||
func TestEdgeMetadatasMerge(t *testing.T) {
|
||||
for name, c := range map[string]struct {
|
||||
a, b, want EdgeMetadatas
|
||||
@@ -84,7 +92,7 @@ func TestEdgeMetadatasMerge(t *testing.T) {
|
||||
EgressByteCount: newu64(999),
|
||||
}),
|
||||
},
|
||||
"Host merge": {
|
||||
"Disjoint a & b": {
|
||||
a: EmptyEdgeMetadatas.
|
||||
Add("hostA|:192.168.1.1:12345|:192.168.1.2:80",
|
||||
EdgeMetadata{
|
||||
@@ -113,7 +121,7 @@ func TestEdgeMetadatasMerge(t *testing.T) {
|
||||
MaxConnCountTCP: newu64(6),
|
||||
}),
|
||||
},
|
||||
"Edge merge": {
|
||||
"Overlapping a & b": {
|
||||
a: EmptyEdgeMetadatas.
|
||||
Add("hostA|:192.168.1.1:12345|:192.168.1.2:80",
|
||||
EdgeMetadata{
|
||||
@@ -146,6 +154,7 @@ func TestEdgeMetadatasMerge(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestEdgeMetadataFlatten(t *testing.T) {
|
||||
// Test two EdgeMetadatas flatten to the correct values
|
||||
{
|
||||
have := (EdgeMetadata{
|
||||
EgressPacketCount: newu64(1),
|
||||
@@ -165,6 +174,8 @@ func TestEdgeMetadataFlatten(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// Test an EdgeMetadatas flatten to the correct value (should
|
||||
// just sum)
|
||||
{
|
||||
have := EmptyEdgeMetadatas.
|
||||
Add("foo", EdgeMetadata{
|
||||
|
||||
@@ -10,14 +10,9 @@ import (
|
||||
|
||||
func TestLatestMapAdd(t *testing.T) {
|
||||
now := time.Now()
|
||||
want := EmptyLatestMap.
|
||||
Set("foo", now, "Bar")
|
||||
have := EmptyLatestMap.
|
||||
Set("foo", now.Add(-1), "Baz").
|
||||
Set("foo", now, "Bar")
|
||||
if !reflect.DeepEqual(want, have) {
|
||||
t.Errorf(test.Diff(want, have))
|
||||
}
|
||||
if v, ok := have.Lookup("foo"); !ok || v != "Bar" {
|
||||
t.Errorf("v != Bar")
|
||||
}
|
||||
@@ -30,6 +25,18 @@ func TestLatestMapAdd(t *testing.T) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestLatestMapDeepEquals(t *testing.T) {
|
||||
now := time.Now()
|
||||
want := EmptyLatestMap.
|
||||
Set("foo", now, "Bar")
|
||||
have := EmptyLatestMap.
|
||||
Set("foo", now, "Bar")
|
||||
if !reflect.DeepEqual(want, have) {
|
||||
t.Errorf(test.Diff(want, have))
|
||||
}
|
||||
}
|
||||
|
||||
func TestLatestMapDelete(t *testing.T) {
|
||||
now := time.Now()
|
||||
want := EmptyLatestMap
|
||||
@@ -62,7 +69,7 @@ func TestLatestMapMerge(t *testing.T) {
|
||||
want: EmptyLatestMap.
|
||||
Set("foo", now, "bar"),
|
||||
},
|
||||
"Host merge": {
|
||||
"Disjoint a & b": {
|
||||
a: EmptyLatestMap.
|
||||
Set("foo", now, "bar"),
|
||||
b: EmptyLatestMap.
|
||||
@@ -71,7 +78,7 @@ func TestLatestMapMerge(t *testing.T) {
|
||||
Set("foo", now, "bar").
|
||||
Set("baz", now, "bop"),
|
||||
},
|
||||
"Edge merge": {
|
||||
"Common a & b": {
|
||||
a: EmptyLatestMap.
|
||||
Set("foo", now, "bar"),
|
||||
b: EmptyLatestMap.
|
||||
|
||||
Reference in New Issue
Block a user