Exemple #1
0
func TestHostRenderer(t *testing.T) {
	have := expected.Sterilize(render.HostRenderer.Render(test.Report))
	want := expected.RenderedHosts
	if !reflect.DeepEqual(want, have) {
		t.Error(test.Diff(want, have))
	}
}
Exemple #2
0
func TestContainerImageRenderer(t *testing.T) {
	have := expected.Sterilize(render.ContainerImageRenderer.Render(test.Report))
	want := expected.RenderedContainerImages
	if !reflect.DeepEqual(want, have) {
		t.Error(test.Diff(want, have))
	}
}
Exemple #3
0
func TestProcessNameRenderer(t *testing.T) {
	have := expected.Sterilize(render.ProcessNameRenderer.Render(test.Report))
	want := expected.RenderedProcessNames
	if !reflect.DeepEqual(want, have) {
		t.Error(test.Diff(want, have))
	}
}
Exemple #4
0
func TestAPITopologyContainers(t *testing.T) {
	ts := httptest.NewServer(Router(StaticReport{}))
	{
		body := getRawJSON(t, ts, "/api/topology/containers")
		var topo APITopology
		if err := json.Unmarshal(body, &topo); err != nil {
			t.Fatal(err)
		}

		if want, have := expected.RenderedContainers, expected.Sterilize(topo.Nodes); !reflect.DeepEqual(want, have) {
			t.Error(test.Diff(want, have))
		}
	}
}
Exemple #5
0
func TestFilterRender(t *testing.T) {
	renderer := render.FilterUnconnected(
		mockRenderer{RenderableNodes: render.RenderableNodes{
			"foo": {ID: "foo", Node: report.MakeNode().WithAdjacent("bar")},
			"bar": {ID: "bar", Node: report.MakeNode().WithAdjacent("foo")},
			"baz": {ID: "baz", Node: report.MakeNode()},
		}})
	want := render.RenderableNodes{
		"foo": {ID: "foo", Node: report.MakeNode().WithAdjacent("bar")},
		"bar": {ID: "bar", Node: report.MakeNode().WithAdjacent("foo")},
	}
	have := expected.Sterilize(renderer.Render(report.MakeReport()))
	if !reflect.DeepEqual(want, have) {
		t.Errorf("want %+v, have %+v", want, have)
	}
}
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))
	}
}
Exemple #7
0
func TestAPITopologyHosts(t *testing.T) {
	ts := httptest.NewServer(Router(StaticReport{}))
	defer ts.Close()
	is404(t, ts, "/api/topology/hosts/foobar")
	{
		body := getRawJSON(t, ts, "/api/topology/hosts")
		var topo APITopology
		if err := json.Unmarshal(body, &topo); err != nil {
			t.Fatal(err)
		}

		if want, have := expected.RenderedHosts, expected.Sterilize(topo.Nodes); !reflect.DeepEqual(want, have) {
			t.Error(test.Diff(want, have))
		}
	}
	{
		body := getRawJSON(t, ts, "/api/topology/hosts/"+expected.ServerHostRenderedID)
		var node APINode
		if err := json.Unmarshal(body, &node); err != nil {
			t.Fatal(err)
		}
		equals(t, expected.ServerHostRenderedID, node.Node.ID)
		equals(t, "server", node.Node.LabelMajor)
		equals(t, "hostname.com", node.Node.LabelMinor)
		equals(t, false, node.Node.Pseudo)
		// Let's not unit-test the specific content of the detail tables
	}
	{
		body := getRawJSON(t, ts, fmt.Sprintf("/api/topology/hosts/%s/%s", expected.ClientHostRenderedID, expected.ServerHostRenderedID))
		var edge APIEdge
		if err := json.Unmarshal(body, &edge); err != nil {
			t.Fatalf("JSON parse error: %s", err)
		}
		if want, have := (report.EdgeMetadata{
			MaxConnCountTCP: newu64(3),
		}), edge.Metadata; !reflect.DeepEqual(want, have) {
			t.Error(test.Diff(want, have))
		}
	}
}
Exemple #8
0
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 := expected.Sterilize(mapper.Render(report.MakeReport()))
	want := expected.Sterilize(render.RenderableNodes{
		"_foo": {
			ID:      "_foo",
			Origins: report.MakeIDList("foo"),
			Node:    report.MakeNode().WithAdjacent("_bar"),
			EdgeMetadata: report.EdgeMetadata{
				EgressPacketCount: newu64(4),
				EgressByteCount:   newu64(6),
			},
		},
		"_bar": {
			ID:      "_bar",
			Origins: report.MakeIDList("bar"),
			Node:    report.MakeNode().WithAdjacent("_foo"),
			EdgeMetadata: report.EdgeMetadata{
				EgressPacketCount: newu64(4),
				EgressByteCount:   newu64(6),
			},
		},
	})
	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))
	}
}