コード例 #1
0
ファイル: util_test.go プロジェクト: gitter-badger/alkasir
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
ファイル: util_test.go プロジェクト: gitter-badger/alkasir
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
ファイル: search_test.go プロジェクト: gitter-badger/alkasir
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
ファイル: search_test.go プロジェクト: gitter-badger/alkasir
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
ファイル: search_test.go プロジェクト: gitter-badger/alkasir
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)
	}
}