X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/a6c0c9dccbe036132c110817d69c08b757aab5fa..c7b155c06452315396ec98f42cf5b502be38b221:/services/keep/keep_test.go diff --git a/services/keep/keep_test.go b/services/keep/keep_test.go index cb5e89cfb9..2aa8aff77c 100644 --- a/services/keep/keep_test.go +++ b/services/keep/keep_test.go @@ -5,11 +5,21 @@ import ( "io/ioutil" "os" "path" + "regexp" "testing" ) var TEST_BLOCK = []byte("The quick brown fox jumps over the lazy dog.") var TEST_HASH = "e4d909c290d0fb1ca068ffaddf22cbd0" + +var TEST_BLOCK_2 = []byte("Pack my box with five dozen liquor jugs.") +var TEST_HASH_2 = "f15ac516f788aec4f30932ffb6395c39" + +var TEST_BLOCK_3 = []byte("Now is the time for all good men to come to the aid of their country.") +var TEST_HASH_3 = "eed29bbffbc2dbe5e5ee0bb71888e61f" + +// BAD_BLOCK is used to test collisions and corruption. +// It must not match any test hashes. var BAD_BLOCK = []byte("The magic words are squeamish ossifrage.") // ======================================== @@ -244,6 +254,32 @@ func TestFindKeepVolumesFail(t *testing.T) { } } +// TestIndex +// Test an /index request. +func TestIndex(t *testing.T) { + defer teardown() + + // Set up Keep volumes and populate them. + KeepVolumes = setup(t, 2) + store(t, KeepVolumes[0], TEST_HASH, TEST_BLOCK) + store(t, KeepVolumes[1], TEST_HASH_2, TEST_BLOCK_2) + store(t, KeepVolumes[0], TEST_HASH_3, TEST_BLOCK_3) + + index := IndexLocators("") + expected := `^` + TEST_HASH + `\+\d+ \d+\n` + + TEST_HASH_3 + `\+\d+ \d+\n` + + TEST_HASH_2 + `\+\d+ \d+\n$` + + match, err := regexp.MatchString(expected, index) + if err == nil { + if !match { + t.Errorf("IndexLocators returned:\n-----\n%s-----\n", index) + } + } else { + t.Errorf("regexp.MatchString: %s", err) + } +} + // ======================================== // Helper functions for unit tests. // ========================================