X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/0662b235357dd40b5d27efd06b60044ddcec06f6..97b8ba6c2d2023f66cab62b7062cd0dbff837c67:/services/keepstore/volume_unix_test.go diff --git a/services/keepstore/volume_unix_test.go b/services/keepstore/volume_unix_test.go index b216810f8c..fad1f12164 100644 --- a/services/keepstore/volume_unix_test.go +++ b/services/keepstore/volume_unix_test.go @@ -2,6 +2,7 @@ package main import ( "bytes" + "context" "errors" "fmt" "io" @@ -30,9 +31,9 @@ func NewTestableUnixVolume(t TB, serialize bool, readonly bool) *TestableUnixVol } return &TestableUnixVolume{ UnixVolume: UnixVolume{ - root: d, + Root: d, + ReadOnly: readonly, locker: locker, - readonly: readonly, }, t: t, } @@ -42,10 +43,10 @@ func NewTestableUnixVolume(t TB, serialize bool, readonly bool) *TestableUnixVol // the volume is readonly. func (v *TestableUnixVolume) PutRaw(locator string, data []byte) { defer func(orig bool) { - v.readonly = orig - }(v.readonly) - v.readonly = false - err := v.Put(locator, data) + v.ReadOnly = orig + }(v.ReadOnly) + v.ReadOnly = false + err := v.Put(context.TODO(), locator, data) if err != nil { v.t.Fatal(err) } @@ -59,7 +60,7 @@ func (v *TestableUnixVolume) TouchWithDate(locator string, lastPut time.Time) { } func (v *TestableUnixVolume) Teardown() { - if err := os.RemoveAll(v.root); err != nil { + if err := os.RemoveAll(v.Root); err != nil { v.t.Fatal(err) } } @@ -101,17 +102,31 @@ func TestUnixVolumeHandlersWithGenericVolumeTests(t *testing.T) { }) } +func TestReplicationDefault1(t *testing.T) { + v := &UnixVolume{ + Root: "/", + ReadOnly: true, + } + if err := v.Start(); err != nil { + t.Error(err) + } + if got := v.Replication(); got != 1 { + t.Errorf("Replication() returned %d, expected 1 if no config given", got) + } +} + func TestGetNotFound(t *testing.T) { v := NewTestableUnixVolume(t, false, false) defer v.Teardown() - v.Put(TestHash, TestBlock) + v.Put(context.TODO(), TestHash, TestBlock) - buf, err := v.Get(TestHash2) + buf := make([]byte, BlockSize) + n, err := v.Get(context.TODO(), TestHash2, buf) switch { case os.IsNotExist(err): break case err == nil: - t.Errorf("Read should have failed, returned %s", string(buf)) + t.Errorf("Read should have failed, returned %+q", buf[:n]) default: t.Errorf("Read expected ErrNotExist, got: %s", err) } @@ -121,11 +136,11 @@ func TestPut(t *testing.T) { v := NewTestableUnixVolume(t, false, false) defer v.Teardown() - err := v.Put(TestHash, TestBlock) + err := v.Put(context.TODO(), TestHash, TestBlock) if err != nil { t.Error(err) } - p := fmt.Sprintf("%s/%s/%s", v.root, TestHash[:3], TestHash) + p := fmt.Sprintf("%s/%s/%s", v.Root, TestHash[:3], TestHash) if buf, err := ioutil.ReadFile(p); err != nil { t.Error(err) } else if bytes.Compare(buf, TestBlock) != 0 { @@ -138,8 +153,8 @@ func TestPutBadVolume(t *testing.T) { v := NewTestableUnixVolume(t, false, false) defer v.Teardown() - os.Chmod(v.root, 000) - err := v.Put(TestHash, TestBlock) + os.Chmod(v.Root, 000) + err := v.Put(context.TODO(), TestHash, TestBlock) if err == nil { t.Error("Write should have failed") } @@ -151,12 +166,13 @@ func TestUnixVolumeReadonly(t *testing.T) { v.PutRaw(TestHash, TestBlock) - _, err := v.Get(TestHash) + buf := make([]byte, BlockSize) + _, err := v.Get(context.TODO(), TestHash, buf) if err != nil { t.Errorf("got err %v, expected nil", err) } - err = v.Put(TestHash, TestBlock) + err = v.Put(context.TODO(), TestHash, TestBlock) if err != MethodDisabledError { t.Errorf("got err %v, expected MethodDisabledError", err) } @@ -166,7 +182,7 @@ func TestUnixVolumeReadonly(t *testing.T) { t.Errorf("got err %v, expected MethodDisabledError", err) } - err = v.Delete(TestHash) + err = v.Trash(TestHash) if err != MethodDisabledError { t.Errorf("got err %v, expected MethodDisabledError", err) } @@ -176,7 +192,7 @@ func TestIsFull(t *testing.T) { v := NewTestableUnixVolume(t, false, false) defer v.Teardown() - fullPath := v.root + "/full" + fullPath := v.Root + "/full" now := fmt.Sprintf("%d", time.Now().Unix()) os.Symlink(now, fullPath) if !v.IsFull() { @@ -198,8 +214,8 @@ func TestNodeStatus(t *testing.T) { // Get node status and make a basic sanity check. volinfo := v.Status() - if volinfo.MountPoint != v.root { - t.Errorf("GetNodeStatus mount_point %s, expected %s", volinfo.MountPoint, v.root) + if volinfo.MountPoint != v.Root { + t.Errorf("GetNodeStatus mount_point %s, expected %s", volinfo.MountPoint, v.Root) } if volinfo.DeviceNum == 0 { t.Errorf("uninitialized device_num in %v", volinfo) @@ -216,7 +232,7 @@ func TestUnixVolumeGetFuncWorkerError(t *testing.T) { v := NewTestableUnixVolume(t, false, false) defer v.Teardown() - v.Put(TestHash, TestBlock) + v.Put(context.TODO(), TestHash, TestBlock) mockErr := errors.New("Mock error") err := v.getFunc(v.blockPath(TestHash), func(rdr io.Reader) error { return mockErr @@ -247,7 +263,7 @@ func TestUnixVolumeGetFuncWorkerWaitsOnMutex(t *testing.T) { v := NewTestableUnixVolume(t, false, false) defer v.Teardown() - v.Put(TestHash, TestBlock) + v.Put(context.TODO(), TestHash, TestBlock) mtx := NewMockMutex() v.locker = mtx @@ -282,7 +298,7 @@ func TestUnixVolumeCompare(t *testing.T) { v := NewTestableUnixVolume(t, false, false) defer v.Teardown() - v.Put(TestHash, TestBlock) + v.Put(context.TODO(), TestHash, TestBlock) err := v.Compare(TestHash, TestBlock) if err != nil { t.Errorf("Got err %q, expected nil", err) @@ -293,13 +309,13 @@ func TestUnixVolumeCompare(t *testing.T) { t.Errorf("Got err %q, expected %q", err, CollisionError) } - v.Put(TestHash, []byte("baddata")) + v.Put(context.TODO(), TestHash, []byte("baddata")) err = v.Compare(TestHash, TestBlock) if err != DiskHashError { t.Errorf("Got err %q, expected %q", err, DiskHashError) } - p := fmt.Sprintf("%s/%s/%s", v.root, TestHash[:3], TestHash) + p := fmt.Sprintf("%s/%s/%s", v.Root, TestHash[:3], TestHash) os.Chmod(p, 000) err = v.Compare(TestHash, TestBlock) if err == nil || strings.Index(err.Error(), "permission denied") < 0 {