本文整理汇总了Golang中github.com/weaveworks/scope/test/reflect.DeepEqual函数的典型用法代码示例。如果您正苦于以下问题:Golang DeepEqual函数的具体用法?Golang DeepEqual怎么用?Golang DeepEqual使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了DeepEqual函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestEdgeMetadatasEncoding
func TestEdgeMetadatasEncoding(t *testing.T) {
want := EmptyEdgeMetadatas.
Add("foo", EdgeMetadata{
EgressPacketCount: newu64(1),
MaxConnCountTCP: newu64(2),
}).
Add("bar", EdgeMetadata{
EgressPacketCount: newu64(3),
MaxConnCountTCP: newu64(5),
})
{
gobs, err := want.GobEncode()
if err != nil {
t.Fatal(err)
}
have := EmptyEdgeMetadatas
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 := EmptyEdgeMetadatas
have.UnmarshalJSON(json)
if !reflect.DeepEqual(want, have) {
t.Error(test.Diff(want, have))
}
}
}
开发者ID:pauloheck,项目名称:scope,代码行数:35,代码来源:edge_metadatas_internal_test.go
示例2: TestMemoise
func TestMemoise(t *testing.T) {
calls := 0
r := renderFunc(func(rpt report.Report) render.RenderableNodes {
calls++
return render.RenderableNodes{rpt.ID: render.NewRenderableNode(rpt.ID)}
})
m := render.Memoise(r)
rpt1 := report.MakeReport()
result1 := m.Render(rpt1)
// it should have rendered it.
if _, ok := result1[rpt1.ID]; !ok {
t.Errorf("Expected rendered report to contain a node, but got: %v", result1)
}
if calls != 1 {
t.Errorf("Expected renderer to have been called the first time")
}
result2 := m.Render(rpt1)
if !reflect.DeepEqual(result1, result2) {
t.Errorf("Expected memoised result to be returned: %s", test.Diff(result1, result2))
}
if calls != 1 {
t.Errorf("Expected renderer to not have been called the second time")
}
rpt2 := report.MakeReport()
result3 := m.Render(rpt2)
if reflect.DeepEqual(result1, result3) {
t.Errorf("Expected different result for different report, but were the same")
}
if calls != 2 {
t.Errorf("Expected renderer to have been called again for a different report")
}
}
开发者ID:pauloheck,项目名称:scope,代码行数:35,代码来源:memoise_test.go
示例3: TestLatestMapEncoding
func TestLatestMapEncoding(t *testing.T) {
now := time.Now()
want := EmptyLatestMap.
Set("foo", now, "bar").
Set("bar", now, "baz")
{
gobs, err := want.GobEncode()
if err != nil {
t.Fatal(err)
}
have := EmptyLatestMap
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 := EmptyLatestMap
have.UnmarshalJSON(json)
if !reflect.DeepEqual(want, have) {
t.Error(test.Diff(want, have))
}
}
}
开发者ID:pauloheck,项目名称:scope,代码行数:30,代码来源:latest_map_internal_test.go
示例4: TestCountersEncoding
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))
}
}
}
开发者ID:pauloheck,项目名称:scope,代码行数:29,代码来源:counters_internal_test.go
示例5: TestCollector
func TestCollector(t *testing.T) {
window := time.Millisecond
c := app.NewCollector(window)
r1 := report.MakeReport()
r1.Endpoint.AddNode("foo", report.MakeNode())
r2 := report.MakeReport()
r2.Endpoint.AddNode("bar", report.MakeNode())
if want, have := report.MakeReport(), c.Report(); !reflect.DeepEqual(want, have) {
t.Error(test.Diff(want, have))
}
c.Add(r1)
if want, have := r1, c.Report(); !reflect.DeepEqual(want, have) {
t.Error(test.Diff(want, have))
}
c.Add(r2)
merged := report.MakeReport()
merged = merged.Merge(r1)
merged = merged.Merge(r2)
if want, have := merged, c.Report(); !reflect.DeepEqual(want, have) {
t.Error(test.Diff(want, have))
}
}
开发者ID:pauloheck,项目名称:scope,代码行数:28,代码来源:collector_test.go
示例6: TestFilterUnconnectedPseudoNodes
func TestFilterUnconnectedPseudoNodes(t *testing.T) {
// Test pseudo nodes that are made unconnected by filtering
// are also removed.
{
nodes := render.RenderableNodes{
"foo": {ID: "foo", Node: report.MakeNode().WithAdjacent("bar")},
"bar": {ID: "bar", Node: report.MakeNode().WithAdjacent("baz")},
"baz": {ID: "baz", Node: report.MakeNode(), Pseudo: true},
}
renderer := render.Filter{
FilterFunc: func(node render.RenderableNode) bool {
return true
},
Renderer: mockRenderer{RenderableNodes: nodes},
}
want := nodes.Prune()
have := renderer.Render(report.MakeReport()).Prune()
if !reflect.DeepEqual(want, have) {
t.Error(test.Diff(want, have))
}
}
{
renderer := render.Filter{
FilterFunc: func(node render.RenderableNode) bool {
return node.ID != "bar"
},
Renderer: mockRenderer{RenderableNodes: render.RenderableNodes{
"foo": {ID: "foo", Node: report.MakeNode().WithAdjacent("bar")},
"bar": {ID: "bar", Node: report.MakeNode().WithAdjacent("baz")},
"baz": {ID: "baz", Node: report.MakeNode(), Pseudo: true},
}},
}
want := render.RenderableNodes{
"foo": {ID: "foo", Node: report.MakeNode()},
}
have := renderer.Render(report.MakeReport()).Prune()
if !reflect.DeepEqual(want, have) {
t.Error(test.Diff(want, have))
}
}
{
renderer := render.Filter{
FilterFunc: func(node render.RenderableNode) bool {
return node.ID != "bar"
},
Renderer: mockRenderer{RenderableNodes: render.RenderableNodes{
"foo": {ID: "foo", Node: report.MakeNode()},
"bar": {ID: "bar", Node: report.MakeNode().WithAdjacent("foo")},
"baz": {ID: "baz", Node: report.MakeNode().WithAdjacent("bar"), Pseudo: true},
}},
}
want := render.RenderableNodes{
"foo": {ID: "foo", Node: report.MakeNode()},
}
have := renderer.Render(report.MakeReport()).Prune()
if !reflect.DeepEqual(want, have) {
t.Error(test.Diff(want, have))
}
}
}
开发者ID:pauloheck,项目名称:scope,代码行数:60,代码来源:filters_test.go
示例7: TestSets
func TestSets(t *testing.T) {
sets := EmptySets.Add("foo", MakeStringSet("bar"))
if v, _ := sets.Lookup("foo"); !reflect.DeepEqual(v, MakeStringSet("bar")) {
t.Fatal(v)
}
sets = sets.Merge(EmptySets.Add("foo", MakeStringSet("baz")))
if v, _ := sets.Lookup("foo"); !reflect.DeepEqual(v, MakeStringSet("bar", "baz")) {
t.Fatal(v)
}
}
开发者ID:CNDonny,项目名称:scope,代码行数:11,代码来源:sets_internal_test.go
示例8: TestMetricCopy
func TestMetricCopy(t *testing.T) {
want := report.MakeMetric()
have := want.Copy()
if !reflect.DeepEqual(want, have) {
t.Errorf("diff: %s", test.Diff(want, have))
}
want = report.MakeMetric().Add(time.Now(), 1)
have = want.Copy()
if !reflect.DeepEqual(want, have) {
t.Errorf("diff: %s", test.Diff(want, have))
}
}
开发者ID:CNDonny,项目名称:scope,代码行数:13,代码来源:metrics_test.go
示例9: TestEdgeMetadataFlatten
func TestEdgeMetadataFlatten(t *testing.T) {
// Test two EdgeMetadatas flatten to the correct values
{
have := (EdgeMetadata{
EgressPacketCount: newu64(1),
MaxConnCountTCP: newu64(2),
}).Flatten(EdgeMetadata{
EgressPacketCount: newu64(4),
EgressByteCount: newu64(8),
MaxConnCountTCP: newu64(16),
})
want := EdgeMetadata{
EgressPacketCount: newu64(1 + 4),
EgressByteCount: newu64(8),
MaxConnCountTCP: newu64(2 + 16), // flatten should sum MaxConnCountTCP
}
if !reflect.DeepEqual(want, have) {
t.Error(test.Diff(want, have))
}
}
// Test an EdgeMetadatas flatten to the correct value (should
// just sum)
{
have := EmptyEdgeMetadatas.
Add("foo", EdgeMetadata{
EgressPacketCount: newu64(1),
MaxConnCountTCP: newu64(2),
}).
Add("bar", EdgeMetadata{
EgressPacketCount: newu64(3),
MaxConnCountTCP: newu64(5),
}).Flatten()
want := EdgeMetadata{
EgressPacketCount: newu64(1 + 3),
MaxConnCountTCP: newu64(2 + 5),
}
if !reflect.DeepEqual(want, have) {
t.Error(test.Diff(want, have))
}
}
{
// Should not panic on nil
have := EdgeMetadatas{}.Flatten()
want := EdgeMetadata{}
if !reflect.DeepEqual(want, have) {
t.Error(test.Diff(want, have))
}
}
}
开发者ID:pauloheck,项目名称:scope,代码行数:51,代码来源:edge_metadatas_internal_test.go
示例10: TestMakeRenderableNodes
func TestMakeRenderableNodes(t *testing.T) {
var (
newu64 = func(value uint64) *uint64 { return &value }
srcNodeID = "srcNode"
dstNode1ID = "dstNode1"
dstNode2ID = "dstNode2"
srcNode = report.MakeNode().
WithEdge(dstNode1ID, report.EdgeMetadata{EgressPacketCount: newu64(100), EgressByteCount: newu64(1000)}).
WithEdge(dstNode2ID, report.EdgeMetadata{EgressPacketCount: newu64(200), EgressByteCount: newu64(2000)})
dstNode1 = report.MakeNode()
dstNode2 = report.MakeNode()
topology = report.MakeTopology().
AddNode(srcNodeID, srcNode).
AddNode(dstNode1ID, dstNode1).
AddNode(dstNode2ID, dstNode2)
)
result := render.MakeRenderableNodes(topology)
mustLookup := func(id string) render.RenderableNode {
node, ok := result[id]
if !ok {
t.Fatalf("Expected result to contain node: %q, got: %v", id, result)
}
return node
}
// Source nodes should have the flattened edge metadata
{
have := mustLookup(srcNodeID).EdgeMetadata
want := report.EdgeMetadata{EgressPacketCount: newu64(300), EgressByteCount: newu64(3000)}
if !reflect.DeepEqual(want, have) {
t.Errorf(test.Diff(want, have))
}
}
// Result destination nodes should have the reverse of the source nodes
{
have := mustLookup(dstNode1ID).EdgeMetadata
want := report.EdgeMetadata{IngressPacketCount: newu64(100), IngressByteCount: newu64(1000)}
if !reflect.DeepEqual(want, have) {
t.Errorf(test.Diff(want, have))
}
have = mustLookup(dstNode2ID).EdgeMetadata
want = report.EdgeMetadata{IngressPacketCount: newu64(200), IngressByteCount: newu64(2000)}
if !reflect.DeepEqual(want, have) {
t.Errorf(test.Diff(want, have))
}
}
}
开发者ID:pauloheck,项目名称:scope,代码行数:51,代码来源:selectors_test.go
示例11: TestCountersDeepEquals
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))
}
notequal := EmptyCounters.
Add("foo", 4)
if reflect.DeepEqual(want, notequal) {
t.Errorf(test.Diff(want, have))
}
}
开发者ID:pauloheck,项目名称:scope,代码行数:14,代码来源:counters_internal_test.go
示例12: TestLatestMapDeepEquals
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))
}
notequal := EmptyLatestMap.
Set("foo", now, "Baz")
if reflect.DeepEqual(want, notequal) {
t.Errorf(test.Diff(want, have))
}
}
开发者ID:pauloheck,项目名称:scope,代码行数:15,代码来源:latest_map_internal_test.go
示例13: TestLatestMapDeleteNil
func TestLatestMapDeleteNil(t *testing.T) {
want := LatestMap{}
have := LatestMap{}.Delete("foo")
if !reflect.DeepEqual(want, have) {
t.Errorf(test.Diff(want, have))
}
}
开发者ID:pauloheck,项目名称:scope,代码行数:7,代码来源:latest_map_internal_test.go
示例14: TestEdgeMetadatasEncodingNil
func TestEdgeMetadatasEncodingNil(t *testing.T) {
want := EdgeMetadatas{}
{
gobs, err := want.GobEncode()
if err != nil {
t.Fatal(err)
}
have := EmptyEdgeMetadatas
have.GobDecode(gobs)
if have.psMap == nil {
t.Error("needed to get back a non-nil psMap for EdgeMetadata")
}
}
{
for _, h := range []codec.Handle{
codec.Handle(&codec.MsgpackHandle{}),
codec.Handle(&codec.JsonHandle{}),
} {
buf := &bytes.Buffer{}
encoder := codec.NewEncoder(buf, h)
want.CodecEncodeSelf(encoder)
decoder := codec.NewDecoder(buf, h)
have := EmptyEdgeMetadatas
have.CodecDecodeSelf(decoder)
if !reflect.DeepEqual(want, have) {
t.Error(test.Diff(want, have))
}
}
}
}
开发者ID:CNDonny,项目名称:scope,代码行数:33,代码来源:edge_metadatas_internal_test.go
示例15: TestSetsMerge
func TestSetsMerge(t *testing.T) {
for _, testcase := range []struct {
a, b report.Sets
want map[string][]string
}{
{report.EmptySets, report.EmptySets, map[string][]string{}},
{
report.EmptySets,
report.EmptySets.Add("a", report.MakeStringSet("b")),
map[string][]string{"a": {"b"}},
},
{
report.EmptySets,
report.EmptySets.Add("a", report.MakeStringSet("b", "c")),
map[string][]string{"a": {"b", "c"}},
},
{
report.EmptySets.Add("a", report.MakeStringSet("1")).Add("b", report.MakeStringSet("2")),
report.EmptySets.Add("c", report.MakeStringSet("3")).Add("b", report.MakeStringSet("3")),
map[string][]string{"a": {"1"}, "b": {"2", "3"}, "c": {"3"}},
},
} {
haveSets := testcase.a.Merge(testcase.b)
have := map[string][]string{}
keys := haveSets.Keys()
for _, k := range keys {
have[k], _ = haveSets.Lookup(k)
}
if !reflect.DeepEqual(testcase.want, have) {
t.Errorf("%+v.Merge(%+v): want %+v, have %+v", testcase.a, testcase.b, testcase.want, have)
}
}
}
开发者ID:CNDonny,项目名称:scope,代码行数:34,代码来源:sets_test.go
示例16: TestEdgeMetadataDeepEquals
func TestEdgeMetadataDeepEquals(t *testing.T) {
for _, c := range []struct {
name string
a, b interface{}
want bool
}{
{
name: "zero values",
a: EdgeMetadata{},
b: EdgeMetadata{},
want: true,
},
{
name: "matching, but different pointers",
a: EdgeMetadata{EgressPacketCount: newu64(3)},
b: EdgeMetadata{EgressPacketCount: newu64(3)},
want: true,
},
{
name: "mismatching",
a: EdgeMetadata{EgressPacketCount: newu64(3)},
b: EdgeMetadata{EgressPacketCount: newu64(4)},
want: false,
},
} {
if have := reflect.DeepEqual(c.a, c.b); have != c.want {
t.Errorf("reflect.DeepEqual(%v, %v) != %v", c.a, c.b, c.want)
}
}
}
开发者ID:pauloheck,项目名称:scope,代码行数:30,代码来源:edge_metadatas_internal_test.go
示例17: TestHostRenderer
func TestHostRenderer(t *testing.T) {
have := Prune(render.HostRenderer.Render(fixture.Report, FilterNoop))
want := Prune(expected.RenderedHosts)
if !reflect.DeepEqual(want, have) {
t.Error(test.Diff(want, have))
}
}
开发者ID:CNDonny,项目名称:scope,代码行数:7,代码来源:host_test.go
示例18: TestLatestMapEncodingNil
func TestLatestMapEncodingNil(t *testing.T) {
want := LatestMap{}
{
gobs, err := want.GobEncode()
if err != nil {
t.Fatal(err)
}
have := EmptyLatestMap
have.GobDecode(gobs)
if have.Map == nil {
t.Error("Decoded LatestMap.psMap should not be nil")
}
}
{
for _, h := range []codec.Handle{
codec.Handle(&codec.MsgpackHandle{}),
codec.Handle(&codec.JsonHandle{}),
} {
buf := &bytes.Buffer{}
encoder := codec.NewEncoder(buf, h)
want.CodecEncodeSelf(encoder)
decoder := codec.NewDecoder(buf, h)
have := EmptyLatestMap
have.CodecDecodeSelf(decoder)
if !reflect.DeepEqual(want, have) {
t.Error(test.Diff(want, have))
}
}
}
}
开发者ID:CNDonny,项目名称:scope,代码行数:33,代码来源:latest_map_internal_test.go
示例19: TestApply
func TestApply(t *testing.T) {
var (
endpointNodeID = "c"
addressNodeID = "d"
endpointNode = report.MakeNodeWith(map[string]string{"5": "6"})
addressNode = report.MakeNodeWith(map[string]string{"7": "8"})
)
p := New(0, 0, nil)
p.AddTagger(NewTopologyTagger())
r := report.MakeReport()
r.Endpoint.AddNode(endpointNodeID, endpointNode)
r.Address.AddNode(addressNodeID, addressNode)
r = p.tag(r)
for _, tuple := range []struct {
want report.Node
from report.Topology
via string
}{
{endpointNode.Merge(report.MakeNode().WithID("c").WithTopology(report.Endpoint)), r.Endpoint, endpointNodeID},
{addressNode.Merge(report.MakeNode().WithID("d").WithTopology(report.Address)), r.Address, addressNodeID},
} {
if want, have := tuple.want, tuple.from.Nodes[tuple.via]; !reflect.DeepEqual(want, have) {
t.Errorf("want %+v, have %+v", want, have)
}
}
}
开发者ID:pauloheck,项目名称:scope,代码行数:29,代码来源:probe_internal_test.go
示例20: TestMakeNodeSet
func TestMakeNodeSet(t *testing.T) {
for _, testcase := range []struct {
inputs []string
wants []string
}{
{inputs: nil, wants: nil},
{
inputs: []string{"a"},
wants: []string{"a"},
},
{
inputs: []string{"b", "c", "a"},
wants: []string{"a", "b", "c"},
},
{
inputs: []string{"a", "a", "a"},
wants: []string{"a"},
},
} {
var inputs []report.Node
for _, id := range testcase.inputs {
inputs = append(inputs, report.MakeNode(id))
}
set := report.MakeNodeSet(inputs...)
var have []string
set.ForEach(func(node report.Node) { have = append(have, node.ID) })
if !reflect.DeepEqual(testcase.wants, have) {
t.Errorf("%#v: want %#v, have %#v", testcase.inputs, testcase.wants, have)
}
}
}
开发者ID:CNDonny,项目名称:scope,代码行数:31,代码来源:node_set_test.go
注:本文中的github.com/weaveworks/scope/test/reflect.DeepEqual函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论