• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang render.NewRenderableNode函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/weaveworks/scope/render.NewRenderableNode函数的典型用法代码示例。如果您正苦于以下问题:Golang NewRenderableNode函数的具体用法?Golang NewRenderableNode怎么用?Golang NewRenderableNode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了NewRenderableNode函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: TestReduceRender

func TestReduceRender(t *testing.T) {
	renderer := render.Reduce([]render.Renderer{
		mockRenderer{RenderableNodes: render.RenderableNodes{"foo": render.NewRenderableNode("foo")}},
		mockRenderer{RenderableNodes: render.RenderableNodes{"bar": render.NewRenderableNode("bar")}},
	})

	want := render.RenderableNodes{
		"foo": render.NewRenderableNode("foo"),
		"bar": render.NewRenderableNode("bar"),
	}
	have := renderer.Render(report.MakeReport())
	if !reflect.DeepEqual(want, have) {
		t.Errorf("want %+v, have %+v", want, have)
	}
}
开发者ID:hrhelena,项目名称:scope,代码行数:15,代码来源:render_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: 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


示例4: 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


示例5: 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


示例6: 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


示例7: 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


示例8: TestMergeRenderableNodes

func TestMergeRenderableNodes(t *testing.T) {
	nodes1 := render.RenderableNodes{
		"foo": render.NewRenderableNode("foo"),
		"bar": render.NewRenderableNode("bar"),
	}
	nodes2 := render.RenderableNodes{
		"bar": render.NewRenderableNode("bar"),
		"baz": render.NewRenderableNode("baz"),
	}
	want := expected.Sterilize(render.RenderableNodes{
		"foo": render.NewRenderableNode("foo"),
		"bar": render.NewRenderableNode("bar"),
		"baz": render.NewRenderableNode("baz"),
	})
	have := nodes1.Merge(nodes2)
	if !reflect.DeepEqual(want, have) {
		t.Error(test.Diff(want, have))
	}
}
开发者ID:philipz,项目名称:scope,代码行数:19,代码来源:renderable_node_test.go


示例9: nrn

func nrn(nmd report.Node) render.RenderableNode {
	return render.NewRenderableNode("").WithNode(nmd)
}
开发者ID:philipz,项目名称:scope,代码行数:3,代码来源:mapping_test.go



注:本文中的github.com/weaveworks/scope/render.NewRenderableNode函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang render.Filter类代码示例发布时间:2022-05-28
下一篇:
Golang process.Tree类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap