X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/f4ca9ad94a6bb006d1f3c7ba207837f1736d1247..f935965259f9c0476a9c5ffa79e5c27ce9da4800:/services/keepstore/keepstore_test.go?ds=sidebyside diff --git a/services/keepstore/keepstore_test.go b/services/keepstore/keepstore_test.go index 2a1c3d243a..dc6af0fa0d 100644 --- a/services/keepstore/keepstore_test.go +++ b/services/keepstore/keepstore_test.go @@ -66,12 +66,13 @@ func TestGetBlock(t *testing.T) { } // Check that GetBlock returns success. - result, err := GetBlock(TestHash) + buf := make([]byte, BlockSize) + size, err := GetBlock(TestHash, buf, nil) if err != nil { t.Errorf("GetBlock error: %s", err) } - if fmt.Sprint(result) != fmt.Sprint(TestBlock) { - t.Errorf("expected %s, got %s", TestBlock, result) + if bytes.Compare(buf[:size], TestBlock) != 0 { + t.Errorf("got %v, expected %v", buf[:size], TestBlock) } } @@ -86,9 +87,10 @@ func TestGetBlockMissing(t *testing.T) { defer KeepVM.Close() // Check that GetBlock returns failure. - result, err := GetBlock(TestHash) + buf := make([]byte, BlockSize) + size, err := GetBlock(TestHash, buf, nil) if err != NotFoundError { - t.Errorf("Expected NotFoundError, got %v", result) + t.Errorf("Expected NotFoundError, got %v, err %v", buf[:size], err) } } @@ -107,9 +109,10 @@ func TestGetBlockCorrupt(t *testing.T) { vols[0].Put(TestHash, BadBlock) // Check that GetBlock returns failure. - result, err := GetBlock(TestHash) + buf := make([]byte, BlockSize) + size, err := GetBlock(TestHash, buf, nil) if err != DiskHashError { - t.Errorf("Expected DiskHashError, got %v (buf: %v)", err, result) + t.Errorf("Expected DiskHashError, got %v (buf: %v)", err, buf[:size]) } } @@ -133,13 +136,14 @@ func TestPutBlockOK(t *testing.T) { } vols := KeepVM.AllReadable() - result, err := vols[1].Get(TestHash) + buf := make([]byte, BlockSize) + n, err := vols[1].Get(TestHash, buf) if err != nil { t.Fatalf("Volume #0 Get returned error: %v", err) } - if string(result) != string(TestBlock) { + if string(buf[:n]) != string(TestBlock) { t.Fatalf("PutBlock stored '%s', Get retrieved '%s'", - string(TestBlock), string(result)) + string(TestBlock), string(buf[:n])) } } @@ -162,14 +166,14 @@ func TestPutBlockOneVol(t *testing.T) { t.Fatalf("PutBlock: n %d err %v", n, err) } - result, err := GetBlock(TestHash) + buf := make([]byte, BlockSize) + size, err := GetBlock(TestHash, buf, nil) if err != nil { t.Fatalf("GetBlock: %v", err) } - if string(result) != string(TestBlock) { - t.Error("PutBlock/GetBlock mismatch") - t.Fatalf("PutBlock stored '%s', GetBlock retrieved '%s'", - string(TestBlock), string(result)) + if bytes.Compare(buf[:size], TestBlock) != 0 { + t.Fatalf("PutBlock stored %+q, GetBlock retrieved %+q", + TestBlock, buf[:size]) } } @@ -191,7 +195,7 @@ func TestPutBlockMD5Fail(t *testing.T) { } // Confirm that GetBlock fails to return anything. - if result, err := GetBlock(TestHash); err != NotFoundError { + if result, err := GetBlock(TestHash, make([]byte, BlockSize), nil); err != NotFoundError { t.Errorf("GetBlock succeeded after a corrupt block store (result = %s, err = %v)", string(result), err) } @@ -216,10 +220,11 @@ func TestPutBlockCorrupt(t *testing.T) { } // The block on disk should now match TestBlock. - if block, err := GetBlock(TestHash); err != nil { + buf := make([]byte, BlockSize) + if size, err := GetBlock(TestHash, buf, nil); err != nil { t.Errorf("GetBlock: %v", err) - } else if bytes.Compare(block, TestBlock) != 0 { - t.Errorf("GetBlock returned: '%s'", string(block)) + } else if bytes.Compare(buf[:size], TestBlock) != 0 { + t.Errorf("Got %+q, expected %+q", buf[:size], TestBlock) } } @@ -290,12 +295,13 @@ func TestPutBlockTouchFails(t *testing.T) { t.Errorf("mtime was changed on vols[0]:\noldMtime = %v\nnewMtime = %v\n", oldMtime, newMtime) } - result, err := vols[1].Get(TestHash) + buf := make([]byte, BlockSize) + n, err := vols[1].Get(TestHash, buf) if err != nil { t.Fatalf("vols[1]: %v", err) } - if bytes.Compare(result, TestBlock) != 0 { - t.Errorf("new block does not match test block\nnew block = %v\n", result) + if bytes.Compare(buf[:n], TestBlock) != 0 { + t.Errorf("new block does not match test block\nnew block = %v\n", buf[:n]) } } @@ -335,23 +341,23 @@ func TestDiscoverTmpfs(t *testing.T) { f.Close() ProcMounts = f.Name() - resultVols := volumeSet{} - added := (&unixVolumeAdder{&resultVols}).Discover() + cfg := &Config{} + added := (&unixVolumeAdder{cfg}).Discover() - if added != len(resultVols) { + if added != len(cfg.Volumes) { t.Errorf("Discover returned %d, but added %d volumes", - added, len(resultVols)) + added, len(cfg.Volumes)) } if added != len(tempVols) { t.Errorf("Discover returned %d but we set up %d volumes", added, len(tempVols)) } for i, tmpdir := range tempVols { - if tmpdir != resultVols[i].(*UnixVolume).root { + if tmpdir != cfg.Volumes[i].(*UnixVolume).Root { t.Errorf("Discover returned %s, expected %s\n", - resultVols[i].(*UnixVolume).root, tmpdir) + cfg.Volumes[i].(*UnixVolume).Root, tmpdir) } - if expectReadonly := i%2 == 1; expectReadonly != resultVols[i].(*UnixVolume).readonly { + if expectReadonly := i%2 == 1; expectReadonly != cfg.Volumes[i].(*UnixVolume).ReadOnly { t.Errorf("Discover added %s with readonly=%v, should be %v", tmpdir, !expectReadonly, expectReadonly) } @@ -375,10 +381,10 @@ func TestDiscoverNone(t *testing.T) { f.Close() ProcMounts = f.Name() - resultVols := volumeSet{} - added := (&unixVolumeAdder{&resultVols}).Discover() - if added != 0 || len(resultVols) != 0 { - t.Fatalf("got %d, %v; expected 0, []", added, resultVols) + cfg := &Config{} + added := (&unixVolumeAdder{cfg}).Discover() + if added != 0 || len(cfg.Volumes) != 0 { + t.Fatalf("got %d, %v; expected 0, []", added, cfg.Volumes) } } @@ -436,8 +442,8 @@ func MakeTestVolumeManager(numVolumes int) VolumeManager { // teardown cleans up after each test. func teardown() { - dataManagerToken = "" - enforcePermissions = false - PermissionSecret = nil + theConfig.systemAuthToken = "" + theConfig.RequireSignatures = false + theConfig.blobSigningKey = nil KeepVM = nil }