Added /index handlers. (refs #2561)
[arvados.git] / services / keep / keep_test.go
index cb5e89cfb919d3bfdfe5f72d15f4717bcce7dfb0..2aa8aff77c09ae17ed469342e5c77ddf953fdbbf 100644 (file)
@@ -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.
 // ========================================