-
Notifications
You must be signed in to change notification settings - Fork 712
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package report | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/weaveworks/scope/test" | ||
"github.com/weaveworks/scope/test/reflect" | ||
) | ||
|
||
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)) | ||
} | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
tomwilkie
Author
Contributor
|
||
if v, ok := have.Lookup("foo"); !ok || v != 3 { | ||
t.Errorf("foo != 3") | ||
} | ||
if v, ok := have.Lookup("bar"); ok || v != 0 { | ||
t.Errorf("bar != nil") | ||
} | ||
} | ||
|
||
func TestCountersMerge(t *testing.T) { | ||
for name, c := range map[string]struct { | ||
a, b, want Counters | ||
}{ | ||
"Empty a": { | ||
a: EmptyCounters, | ||
b: EmptyCounters. | ||
Add("foo", 1), | ||
want: EmptyCounters. | ||
Add("foo", 1), | ||
}, | ||
"Empty b": { | ||
a: EmptyCounters. | ||
Add("foo", 1), | ||
b: EmptyCounters, | ||
want: EmptyCounters. | ||
Add("foo", 1), | ||
}, | ||
"Disparate keys": { | ||
a: EmptyCounters. | ||
Add("foo", 1), | ||
b: EmptyCounters. | ||
Add("bar", 2), | ||
want: EmptyCounters. | ||
Add("foo", 1). | ||
Add("bar", 2), | ||
}, | ||
"Key merge": { | ||
a: EmptyCounters. | ||
Add("foo", 1), | ||
b: EmptyCounters. | ||
Add("foo", 2), | ||
want: EmptyCounters. | ||
Add("foo", 3), | ||
}, | ||
} { | ||
if have := c.a.Merge(c.b); !reflect.DeepEqual(c.want, have) { | ||
t.Errorf("%s:\n%s", name, test.Diff(c.want, have)) | ||
} | ||
} | ||
} | ||
|
||
func TestCountersEncoding(t *testing.T) { | ||
want := EmptyCounters. | ||
Add("foo", 1). | ||
Add("bar", 2) | ||
|
||
{ | ||
gobs, err := want.GobEncode() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
have := EmptyCounters | ||
have.GobDecode(gobs) | ||
if !reflect.DeepEqual(want, have) { | ||
t.Error(test.Diff(want, have)) | ||
} | ||
} | ||
|
||
{ | ||
json, err := want.MarshalJSON() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
have := EmptyCounters | ||
have.UnmarshalJSON(json) | ||
if !reflect.DeepEqual(want, have) { | ||
t.Error(test.Diff(want, have)) | ||
} | ||
} | ||
} |
File renamed without changes.
This check is covered by the two cases below.