Ejemplo n.º 1
0
func TestMerger(t *testing.T) {
	// Use 3 reports to check the pair-wise merging in SmartMerger
	report1 := report.MakeReport()
	report1.Endpoint.AddNode(report.MakeNode("foo"))
	report2 := report.MakeReport()
	report2.Endpoint.AddNode(report.MakeNode("bar"))
	report3 := report.MakeReport()
	report3.Endpoint.AddNode(report.MakeNode("baz"))
	reports := []report.Report{
		report1, report2, report3,
	}
	want := report.MakeReport()
	want.Endpoint.
		AddNode(report.MakeNode("foo")).
		AddNode(report.MakeNode("bar")).
		AddNode(report.MakeNode("baz"))

	for _, merger := range []app.Merger{app.MakeDumbMerger(), app.NewSmartMerger()} {
		// Test the empty list case
		if have := merger.Merge([]report.Report{}); !reflect.DeepEqual(have, report.MakeReport()) {
			t.Errorf("Bad merge: %s", test.Diff(have, want))
		}

		if have := merger.Merge(reports); !reflect.DeepEqual(have, want) {
			t.Errorf("Bad merge: %s", test.Diff(have, want))
		}

		// Repeat the above test to ensure caching works
		if have := merger.Merge(reports); !reflect.DeepEqual(have, want) {
			t.Errorf("Bad merge: %s", test.Diff(have, want))
		}
	}
}
Ejemplo n.º 2
0
func TestSmartMerger(t *testing.T) {
	// Use 3 reports _WITH SAME ID_
	report1 := report.MakeReport()
	report1.Endpoint.AddNode(report.MakeNode("foo"))
	report1.ID = "foo"
	report2 := report.MakeReport()
	report2.Endpoint.AddNode(report.MakeNode("bar"))
	report2.ID = "foo"
	report3 := report.MakeReport()
	report3.Endpoint.AddNode(report.MakeNode("baz"))
	report3.ID = "foo"
	reports := []report.Report{
		report1, report2, report3,
	}
	want := report.MakeReport()
	want.Endpoint.AddNode(report.MakeNode("foo"))

	merger := app.NewSmartMerger()
	if have := merger.Merge(reports); !reflect.DeepEqual(have, want) {
		t.Errorf("Bad merge: %s", test.Diff(have, want))
	}
}
Ejemplo n.º 3
0
func BenchmarkSmartMerger(b *testing.B) {
	benchmarkMerger(b, app.NewSmartMerger())
}