本文整理汇总了Golang中github.com/weaveworks/scope/render.Map.EdgeMetadata方法的典型用法代码示例。如果您正苦于以下问题:Golang Map.EdgeMetadata方法的具体用法?Golang Map.EdgeMetadata怎么用?Golang Map.EdgeMetadata使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/weaveworks/scope/render.Map
的用法示例。
在下文中一共展示了Map.EdgeMetadata方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestMapEdge
func TestMapEdge(t *testing.T) {
selector := func(_ report.Report) report.Topology {
return report.Topology{
NodeMetadatas: report.NodeMetadatas{
"foo": report.MakeNodeMetadataWith(map[string]string{"id": "foo"}),
"bar": report.MakeNodeMetadataWith(map[string]string{"id": "bar"}),
},
Adjacency: report.Adjacency{
">foo": report.MakeIDList("bar"),
">bar": report.MakeIDList("foo"),
},
EdgeMetadatas: report.EdgeMetadatas{
"foo|bar": report.EdgeMetadata{EgressPacketCount: newu64(1), EgressByteCount: newu64(2)},
"bar|foo": report.EdgeMetadata{EgressPacketCount: newu64(3), EgressByteCount: newu64(4)},
},
}
}
identity := func(nmd report.NodeMetadata) render.RenderableNodes {
return render.RenderableNodes{nmd.Metadata["id"]: render.NewRenderableNode(nmd.Metadata["id"], "", "", "", nmd)}
}
mapper := render.Map{
MapFunc: func(nodes render.RenderableNode) render.RenderableNodes {
id := "_" + nodes.ID
return render.RenderableNodes{id: render.RenderableNode{ID: id}}
},
Renderer: render.LeafMap{
Selector: selector,
Mapper: identity,
Pseudo: nil,
},
}
if want, have := (report.EdgeMetadata{
EgressPacketCount: newu64(1),
EgressByteCount: newu64(2),
}), mapper.EdgeMetadata(report.MakeReport(), "_foo", "_bar"); !reflect.DeepEqual(want, have) {
t.Error(test.Diff(want, have))
}
}
示例2: TestMapEdge
func TestMapEdge(t *testing.T) {
selector := render.TopologySelector(func(_ report.Report) render.RenderableNodes {
return render.MakeRenderableNodes(report.Topology{
Nodes: report.Nodes{
"foo": report.MakeNode().WithMetadata(map[string]string{
"id": "foo",
}).WithEdge("bar", report.EdgeMetadata{
EgressPacketCount: newu64(1),
EgressByteCount: newu64(2),
}),
"bar": report.MakeNode().WithMetadata(map[string]string{
"id": "bar",
}).WithEdge("foo", report.EdgeMetadata{
EgressPacketCount: newu64(3),
EgressByteCount: newu64(4),
}),
},
})
})
mapper := render.Map{
MapFunc: func(node render.RenderableNode, _ report.Networks) render.RenderableNodes {
id := "_" + node.ID
return render.RenderableNodes{id: render.NewDerivedNode(id, node)}
},
Renderer: selector,
}
have := mapper.Render(report.MakeReport()).Prune()
want := (render.RenderableNodes{
"_foo": {
ID: "_foo",
Origins: report.MakeIDList("foo"),
Node: report.MakeNode().WithAdjacent("_bar"),
EdgeMetadata: report.EdgeMetadata{
EgressPacketCount: newu64(1),
EgressByteCount: newu64(2),
IngressPacketCount: newu64(3),
IngressByteCount: newu64(4),
},
},
"_bar": {
ID: "_bar",
Origins: report.MakeIDList("bar"),
Node: report.MakeNode().WithAdjacent("_foo"),
EdgeMetadata: report.EdgeMetadata{
EgressPacketCount: newu64(3),
EgressByteCount: newu64(4),
IngressPacketCount: newu64(1),
IngressByteCount: newu64(2),
},
},
}).Prune()
if !reflect.DeepEqual(want, have) {
t.Error(test.Diff(want, have))
}
if want, have := (report.EdgeMetadata{
EgressPacketCount: newu64(1),
EgressByteCount: newu64(2),
}), mapper.EdgeMetadata(report.MakeReport(), "_foo", "_bar"); !reflect.DeepEqual(want, have) {
t.Error(test.Diff(want, have))
}
}