Пример #1
0
func ExampleMapDiff() {
	expected := map[string]string{"a": "a", "b": "b"}
	actual := map[string]string{"a": "aaaa", "c": "c"}

	diff, onlyExpected, onlyActual := util.MapDiff(expected, actual)
	fmt.Println(diff)         // ["a"]
	fmt.Println(onlyExpected) // ["b"]
	fmt.Println(onlyActual)   // ["c"]

	diff, onlyExpected, onlyActual = util.MapDiff(expected, expected)
	fmt.Println(diff)         // []
	fmt.Println(onlyExpected) // []
	fmt.Println(onlyActual)   // []
}
Пример #2
0
func TestMapDiff(t *testing.T) {
	for _, md := range mdTest {
		expDiff, expOnlyE, expOnlyA := util.MapDiff(md.expected, md.actual)

		if !sliceEquals(expDiff, md.diff) {
			t.Errorf("expected diff %v, got %v", md.diff, expDiff)
		}

		if !sliceEquals(expOnlyE, md.onlyExpected) {
			t.Errorf("expected onlyExpected %v, got %v", md.onlyExpected, expOnlyE)
		}

		if !sliceEquals(expOnlyA, md.onlyActual) {
			t.Errorf("expected onlyActual %v, got %v", md.onlyActual, expOnlyA)
		}
	}
}
Пример #3
0
func TestByChecksumSetsTheProperFields(t *testing.T) {
	actual := search.ByChecksum("sha1").Parameters()
	expected := map[string]string{"sha1": "sha1"}

	diff, onlyExpected, onlyActual := util.MapDiff(expected, actual)

	for _, key := range diff {
		t.Errorf("Mismatch on key %q: expected value %q, got %q", key, expected[key], actual[key])
	}

	for _, key := range onlyExpected {
		t.Errorf("Missing key %q", key)
	}

	for _, key := range onlyActual {
		t.Errorf("Unexpected key %q", key)
	}
}
Пример #4
0
func TestByCoordinatesSetsTheProperFields(t *testing.T) {
	actual := search.ByCoordinates{GroupID: "g", ArtifactID: "a", Version: "v", Packaging: "p", Classifier: "c"}.Parameters()
	expected := map[string]string{"g": "g", "a": "a", "v": "v", "p": "p", "c": "c"}

	diff, onlyExpected, onlyActual := util.MapDiff(expected, actual)

	for _, key := range diff {
		t.Errorf("Mismatch on key %q: expected value %q, got %q", key, expected[key], actual[key])
	}

	for _, key := range onlyExpected {
		t.Errorf("Missing key %q", key)
	}

	for _, key := range onlyActual {
		t.Errorf("Unexpected key %q", key)
	}
}
Пример #5
0
func TestInRepositoryWithSearchAllIsTheSameAsByRepository(t *testing.T) {
	actual := search.InRepository{RepositoryID: "repositoryId", Criteria: search.All}.Parameters()
	expected := search.ByRepository("repositoryId").Parameters()

	diff, onlyExpected, onlyActual := util.MapDiff(expected, actual)

	for _, key := range diff {
		t.Errorf("Mismatch on key %q: expected value %q, got %q", key, expected[key], actual[key])
	}

	for _, key := range onlyExpected {
		t.Errorf("Missing key %q", key)
	}

	for _, key := range onlyActual {
		t.Errorf("Unexpected key %q", key)
	}
}