From da030d1618d0cd4e81be91413d02211e2371c0f0 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Tue, 17 Sep 2019 15:34:31 +0000 Subject: [PATCH] test: add TestReportUnMerge() Testing the new delta-report internals --- report/report_test.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/report/report_test.go b/report/report_test.go index 6ecbc1c8d..80717e7f6 100644 --- a/report/report_test.go +++ b/report/report_test.go @@ -98,3 +98,41 @@ func TestReportUpgrade(t *testing.T) { t.Error(test.Diff(expected, got)) } } + +func TestReportUnMerge(t *testing.T) { + n1 := report.MakeNodeWith("foo", map[string]string{"foo": "bar"}) + r1 := makeTestReport() + r2 := r1.Copy() + r2.Container.AddNode(n1) + // r2 should be the same as r1 with just the foo-bar node added + r2.UnsafeUnMerge(r1) + // Now r2 should have everything removed except that one node, and its ID + expected := report.Report{ + ID: r2.ID, + Container: report.Topology{ + Nodes: report.Nodes{ + "foo": n1, + }, + }, + } + + // Now test report with two nodes unmerged on report with one + r1.Container.AddNode(n1) + r2 = r1.Copy() + n2 := report.MakeNodeWith("foo2", map[string]string{"ping": "pong"}) + r2.Container.AddNode(n2) + // r2 should be the same as r1 with one extra node + r2.UnsafeUnMerge(r1) + expected = report.Report{ + ID: r2.ID, + Container: report.Topology{ + Nodes: report.Nodes{ + "foo2": n2, + }, + }, + } + + if !s_reflect.DeepEqual(expected, r2) { + t.Error(test.Diff(expected, r2)) + } +}