本文整理汇总了Golang中github.com/weaveworks/scope/render.Map类的典型用法代码示例。如果您正苦于以下问题:Golang Map类的具体用法?Golang Map怎么用?Golang Map使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Map类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestMapRender1
func TestMapRender1(t *testing.T) {
// 1. Check when we return false, the node gets filtered out
mapper := render.Map{
MapFunc: func(nodes render.RenderableNode, _ report.Networks) render.RenderableNodes {
return render.RenderableNodes{}
},
Renderer: mockRenderer{RenderableNodes: render.RenderableNodes{
"foo": render.NewRenderableNode("foo"),
}},
}
want := render.RenderableNodes{}
have := mapper.Render(report.MakeReport())
if !reflect.DeepEqual(want, have) {
t.Errorf("want %+v, have %+v", want, have)
}
}
开发者ID:hrhelena,项目名称:scope,代码行数:16,代码来源:render_test.go
示例2: TestMapRender2
func TestMapRender2(t *testing.T) {
// 2. Check we can remap two nodes into one
mapper := render.Map{
MapFunc: func(nodes render.RenderableNode) (render.RenderableNode, bool) {
return render.RenderableNode{ID: "bar"}, true
},
Renderer: mockRenderer{RenderableNodes: render.RenderableNodes{
"foo": {ID: "foo"},
"baz": {ID: "baz"},
}},
}
want := render.RenderableNodes{
"bar": render.RenderableNode{ID: "bar"},
}
have := mapper.Render(report.MakeReport())
if !reflect.DeepEqual(want, have) {
t.Errorf("want %+v, have %+v", want, have)
}
}
开发者ID:neviim,项目名称:scope,代码行数:19,代码来源:render_test.go
示例3: TestMapRender2
func TestMapRender2(t *testing.T) {
// 2. Check we can remap two nodes into one
mapper := render.Map{
MapFunc: func(nodes render.RenderableNode) render.RenderableNodes {
return render.RenderableNodes{"bar": render.RenderableNode{ID: "bar"}}
},
Renderer: mockRenderer{RenderableNodes: render.RenderableNodes{
"foo": {ID: "foo"},
"baz": {ID: "baz"},
}},
}
want := sterilize(render.RenderableNodes{
"bar": render.RenderableNode{ID: "bar"},
}, false)
have := mapper.Render(report.MakeReport())
if !reflect.DeepEqual(want, have) {
t.Error(test.Diff(want, have))
}
}
开发者ID:cgvarela,项目名称:scope,代码行数:19,代码来源:render_test.go
示例4: TestMapEdge
func TestMapEdge(t *testing.T) {
selector := func(_ report.Report) report.Topology {
return report.Topology{
NodeMetadatas: report.NodeMetadatas{
"foo": report.NewNodeMetadata(map[string]string{"id": "foo"}),
"bar": report.NewNodeMetadata(map[string]string{"id": "bar"}),
},
Adjacency: report.Adjacency{
">foo": report.MakeIDList("bar"),
">bar": report.MakeIDList("foo"),
},
EdgeMetadatas: report.EdgeMetadatas{
"foo|bar": report.EdgeMetadata{WithBytes: true, BytesIngress: 1, BytesEgress: 2},
"bar|foo": report.EdgeMetadata{WithBytes: true, BytesIngress: 3, BytesEgress: 4},
},
}
}
identity := func(nmd report.NodeMetadata) (render.RenderableNode, bool) {
return render.NewRenderableNode(nmd.Metadata["id"], "", "", "", nmd), true
}
mapper := render.Map{
MapFunc: func(nodes render.RenderableNode) (render.RenderableNode, bool) {
return render.RenderableNode{ID: "_" + nodes.ID}, true
},
Renderer: render.LeafMap{
Selector: selector,
Mapper: identity,
Pseudo: nil,
},
}
want := render.AggregateMetadata{
render.KeyBytesIngress: 1,
render.KeyBytesEgress: 2,
}
have := mapper.AggregateMetadata(report.MakeReport(), "_foo", "_bar")
if !reflect.DeepEqual(want, have) {
t.Errorf("want %+v, have %+v", want, have)
}
}
开发者ID:neviim,项目名称:scope,代码行数:42,代码来源:render_test.go
示例5: TestMapRender3
func TestMapRender3(t *testing.T) {
// 3. Check we can remap adjacencies
mapper := render.Map{
MapFunc: func(nodes render.RenderableNode) (render.RenderableNode, bool) {
return render.RenderableNode{ID: "_" + nodes.ID}, true
},
Renderer: mockRenderer{RenderableNodes: render.RenderableNodes{
"foo": {ID: "foo", Adjacency: report.MakeIDList("baz")},
"baz": {ID: "baz", Adjacency: report.MakeIDList("foo")},
}},
}
want := render.RenderableNodes{
"_foo": {ID: "_foo", Adjacency: report.MakeIDList("_baz")},
"_baz": {ID: "_baz", Adjacency: report.MakeIDList("_foo")},
}
have := mapper.Render(report.MakeReport())
if !reflect.DeepEqual(want, have) {
t.Errorf("want %+v, have %+v", want, have)
}
}
开发者ID:neviim,项目名称:scope,代码行数:20,代码来源:render_test.go
示例6: 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))
}
}
开发者ID:cgvarela,项目名称:scope,代码行数:41,代码来源:render_test.go
示例7: TestMapRender3
func TestMapRender3(t *testing.T) {
// 3. Check we can remap adjacencies
mapper := render.Map{
MapFunc: func(nodes render.RenderableNode, _ report.Networks) render.RenderableNodes {
id := "_" + nodes.ID
return render.RenderableNodes{id: render.NewRenderableNode(id)}
},
Renderer: mockRenderer{RenderableNodes: render.RenderableNodes{
"foo": render.NewRenderableNode("foo").WithNode(report.MakeNode().WithAdjacent("baz")),
"baz": render.NewRenderableNode("baz").WithNode(report.MakeNode().WithAdjacent("foo")),
}},
}
want := render.RenderableNodes{
"_foo": render.NewRenderableNode("_foo").WithNode(report.MakeNode().WithAdjacent("_baz")),
"_baz": render.NewRenderableNode("_baz").WithNode(report.MakeNode().WithAdjacent("_foo")),
}
have := mapper.Render(report.MakeReport())
if !reflect.DeepEqual(want, have) {
t.Error(test.Diff(want, have))
}
}
开发者ID:hrhelena,项目名称:scope,代码行数:21,代码来源:render_test.go
示例8: TestMapRender2
func TestMapRender2(t *testing.T) {
// 2. Check we can remap two nodes into one
mapper := render.Map{
MapFunc: func(nodes render.RenderableNode, _ report.Networks) render.RenderableNodes {
return render.RenderableNodes{
"bar": render.NewRenderableNode("bar"),
}
},
Renderer: mockRenderer{RenderableNodes: render.RenderableNodes{
"foo": render.NewRenderableNode("foo"),
"baz": render.NewRenderableNode("baz"),
}},
}
want := render.RenderableNodes{
"bar": render.NewRenderableNode("bar"),
}
have := mapper.Render(report.MakeReport())
if !reflect.DeepEqual(want, have) {
t.Error(test.Diff(want, have))
}
}
开发者ID:hrhelena,项目名称:scope,代码行数:21,代码来源:render_test.go
示例9: 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))
}
}
开发者ID:hrhelena,项目名称:scope,代码行数:65,代码来源:render_test.go
注:本文中的github.com/weaveworks/scope/render.Map类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论