mirror of
https://github.com/pgsty/minio.git
synced 2026-07-21 13:10:22 +03:00
move to go1.24 (#21114)
This commit is contained in:
+82
-83
@@ -19,7 +19,6 @@ package cmd
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/rand"
|
||||
"io"
|
||||
"net/url"
|
||||
@@ -142,7 +141,7 @@ func newXLStorageTestSetup(tb testing.TB) (*xlStorageDiskIDCheck, string, error)
|
||||
}
|
||||
|
||||
// Create a sample format.json file
|
||||
if err = storage.WriteAll(context.Background(), minioMetaBucket, formatConfigFile, []byte(`{"version":"1","format":"xl","id":"592a41c2-b7cc-4130-b883-c4b5cb15965b","xl":{"version":"3","this":"da017d62-70e3-45f1-8a1a-587707e69ad1","sets":[["e07285a6-8c73-4962-89c6-047fb939f803","33b8d431-482d-4376-b63c-626d229f0a29","cff6513a-4439-4dc1-bcaa-56c9e880c352","da017d62-70e3-45f1-8a1a-587707e69ad1","9c9f21d5-1f15-4737-bce6-835faa0d9626","0a59b346-1424-4fc2-9fa2-a2e80541d0c1","7924a3dc-b69a-4971-9a2e-014966d6aebb","4d2b8dd9-4e48-444b-bdca-c89194b26042"]],"distributionAlgo":"CRCMOD"}}`)); err != nil {
|
||||
if err = storage.WriteAll(tb.Context(), minioMetaBucket, formatConfigFile, []byte(`{"version":"1","format":"xl","id":"592a41c2-b7cc-4130-b883-c4b5cb15965b","xl":{"version":"3","this":"da017d62-70e3-45f1-8a1a-587707e69ad1","sets":[["e07285a6-8c73-4962-89c6-047fb939f803","33b8d431-482d-4376-b63c-626d229f0a29","cff6513a-4439-4dc1-bcaa-56c9e880c352","da017d62-70e3-45f1-8a1a-587707e69ad1","9c9f21d5-1f15-4737-bce6-835faa0d9626","0a59b346-1424-4fc2-9fa2-a2e80541d0c1","7924a3dc-b69a-4971-9a2e-014966d6aebb","4d2b8dd9-4e48-444b-bdca-c89194b26042"]],"distributionAlgo":"CRCMOD"}}`)); err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
|
||||
@@ -243,15 +242,15 @@ func TestXLStorageReadVersionLegacy(t *testing.T) {
|
||||
}
|
||||
|
||||
// Create files for the test cases.
|
||||
if err = xlStorage.MakeVol(context.Background(), "exists-legacy"); err != nil {
|
||||
if err = xlStorage.MakeVol(t.Context(), "exists-legacy"); err != nil {
|
||||
t.Fatalf("Unable to create a volume \"exists-legacy\", %s", err)
|
||||
}
|
||||
|
||||
if err = xlStorage.AppendFile(context.Background(), "exists-legacy", "as-file/xl.json", []byte(legacyJSON)); err != nil {
|
||||
if err = xlStorage.AppendFile(t.Context(), "exists-legacy", "as-file/xl.json", []byte(legacyJSON)); err != nil {
|
||||
t.Fatalf("Unable to create a file \"as-file\", %s", err)
|
||||
}
|
||||
|
||||
fi, err := xlStorage.ReadVersion(context.Background(), "", "exists-legacy", "as-file", "", ReadOptions{})
|
||||
fi, err := xlStorage.ReadVersion(t.Context(), "", "exists-legacy", "as-file", "", ReadOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to read older 'xl.json' content: %s", err)
|
||||
}
|
||||
@@ -273,19 +272,19 @@ func TestXLStorageReadVersion(t *testing.T) {
|
||||
fi, _ := getFileInfo(xlMeta, "exists", "as-file", "", fileInfoOpts{Data: false})
|
||||
|
||||
// Create files for the test cases.
|
||||
if err = xlStorage.MakeVol(context.Background(), "exists"); err != nil {
|
||||
if err = xlStorage.MakeVol(t.Context(), "exists"); err != nil {
|
||||
t.Fatalf("Unable to create a volume \"exists\", %s", err)
|
||||
}
|
||||
if err = xlStorage.AppendFile(context.Background(), "exists", "as-directory/as-file/xl.meta", xlMeta); err != nil {
|
||||
if err = xlStorage.AppendFile(t.Context(), "exists", "as-directory/as-file/xl.meta", xlMeta); err != nil {
|
||||
t.Fatalf("Unable to create a file \"as-directory/as-file\", %s", err)
|
||||
}
|
||||
if err = xlStorage.AppendFile(context.Background(), "exists", "as-file/xl.meta", xlMeta); err != nil {
|
||||
if err = xlStorage.AppendFile(t.Context(), "exists", "as-file/xl.meta", xlMeta); err != nil {
|
||||
t.Fatalf("Unable to create a file \"as-file\", %s", err)
|
||||
}
|
||||
if err = xlStorage.AppendFile(context.Background(), "exists", "as-file-parent/xl.meta", xlMeta); err != nil {
|
||||
if err = xlStorage.AppendFile(t.Context(), "exists", "as-file-parent/xl.meta", xlMeta); err != nil {
|
||||
t.Fatalf("Unable to create a file \"as-file-parent\", %s", err)
|
||||
}
|
||||
if err = xlStorage.MakeVol(context.Background(), "exists/as-file/"+fi.DataDir); err != nil {
|
||||
if err = xlStorage.MakeVol(t.Context(), "exists/as-file/"+fi.DataDir); err != nil {
|
||||
t.Fatalf("Unable to create a dataDir %s, %s", fi.DataDir, err)
|
||||
}
|
||||
|
||||
@@ -341,7 +340,7 @@ func TestXLStorageReadVersion(t *testing.T) {
|
||||
|
||||
// Run through all the test cases and validate for ReadVersion.
|
||||
for i, testCase := range testCases {
|
||||
_, err = xlStorage.ReadVersion(context.Background(), "", testCase.volume, testCase.path, "", ReadOptions{})
|
||||
_, err = xlStorage.ReadVersion(t.Context(), "", testCase.volume, testCase.path, "", ReadOptions{})
|
||||
if err != testCase.err {
|
||||
t.Fatalf("TestXLStorage %d: Expected err \"%s\", got err \"%s\"", i+1, testCase.err, err)
|
||||
}
|
||||
@@ -357,16 +356,16 @@ func TestXLStorageReadAll(t *testing.T) {
|
||||
}
|
||||
|
||||
// Create files for the test cases.
|
||||
if err = xlStorage.MakeVol(context.Background(), "exists"); err != nil {
|
||||
if err = xlStorage.MakeVol(t.Context(), "exists"); err != nil {
|
||||
t.Fatalf("Unable to create a volume \"exists\", %s", err)
|
||||
}
|
||||
if err = xlStorage.AppendFile(context.Background(), "exists", "as-directory/as-file", []byte("Hello, World")); err != nil {
|
||||
if err = xlStorage.AppendFile(t.Context(), "exists", "as-directory/as-file", []byte("Hello, World")); err != nil {
|
||||
t.Fatalf("Unable to create a file \"as-directory/as-file\", %s", err)
|
||||
}
|
||||
if err = xlStorage.AppendFile(context.Background(), "exists", "as-file", []byte("Hello, World")); err != nil {
|
||||
if err = xlStorage.AppendFile(t.Context(), "exists", "as-file", []byte("Hello, World")); err != nil {
|
||||
t.Fatalf("Unable to create a file \"as-file\", %s", err)
|
||||
}
|
||||
if err = xlStorage.AppendFile(context.Background(), "exists", "as-file-parent", []byte("Hello, World")); err != nil {
|
||||
if err = xlStorage.AppendFile(t.Context(), "exists", "as-file-parent", []byte("Hello, World")); err != nil {
|
||||
t.Fatalf("Unable to create a file \"as-file-parent\", %s", err)
|
||||
}
|
||||
|
||||
@@ -423,7 +422,7 @@ func TestXLStorageReadAll(t *testing.T) {
|
||||
var dataRead []byte
|
||||
// Run through all the test cases and validate for ReadAll.
|
||||
for i, testCase := range testCases {
|
||||
dataRead, err = xlStorage.ReadAll(context.Background(), testCase.volume, testCase.path)
|
||||
dataRead, err = xlStorage.ReadAll(t.Context(), testCase.volume, testCase.path)
|
||||
if err != testCase.err {
|
||||
t.Errorf("TestXLStorage %d: Expected err \"%v\", got err \"%v\"", i+1, testCase.err, err)
|
||||
continue
|
||||
@@ -529,7 +528,7 @@ func TestXLStorageMakeVol(t *testing.T) {
|
||||
}
|
||||
|
||||
for i, testCase := range testCases {
|
||||
if err := xlStorage.MakeVol(context.Background(), testCase.volName); err != testCase.expectedErr {
|
||||
if err := xlStorage.MakeVol(t.Context(), testCase.volName); err != testCase.expectedErr {
|
||||
t.Fatalf("TestXLStorage %d: Expected: \"%s\", got: \"%s\"", i+1, testCase.expectedErr, err)
|
||||
}
|
||||
}
|
||||
@@ -561,7 +560,7 @@ func TestXLStorageMakeVol(t *testing.T) {
|
||||
t.Fatalf("Unable to change permission to temporary directory %v. %v", permDeniedDir, err)
|
||||
}
|
||||
|
||||
if err := xlStorageNew.MakeVol(context.Background(), "test-vol"); err != errDiskAccessDenied {
|
||||
if err := xlStorageNew.MakeVol(t.Context(), "test-vol"); err != errDiskAccessDenied {
|
||||
t.Fatalf("expected: %s, got: %s", errDiskAccessDenied, err)
|
||||
}
|
||||
}
|
||||
@@ -576,7 +575,7 @@ func TestXLStorageDeleteVol(t *testing.T) {
|
||||
}
|
||||
|
||||
// Setup test environment.
|
||||
if err = xlStorage.MakeVol(context.Background(), "success-vol"); err != nil {
|
||||
if err = xlStorage.MakeVol(t.Context(), "success-vol"); err != nil {
|
||||
t.Fatalf("Unable to create volume, %s", err)
|
||||
}
|
||||
|
||||
@@ -620,7 +619,7 @@ func TestXLStorageDeleteVol(t *testing.T) {
|
||||
}
|
||||
|
||||
for i, testCase := range testCases {
|
||||
if err = xlStorage.DeleteVol(context.Background(), testCase.volName, false); err != testCase.expectedErr {
|
||||
if err = xlStorage.DeleteVol(t.Context(), testCase.volName, false); err != testCase.expectedErr {
|
||||
t.Fatalf("TestXLStorage: %d, expected: %s, got: %s", i+1, testCase.expectedErr, err)
|
||||
}
|
||||
}
|
||||
@@ -662,7 +661,7 @@ func TestXLStorageDeleteVol(t *testing.T) {
|
||||
t.Fatalf("Unable to change permission to temporary directory %v. %v", permDeniedDir, err)
|
||||
}
|
||||
|
||||
if err = xlStorageNew.DeleteVol(context.Background(), "mybucket", false); err != errDiskAccessDenied {
|
||||
if err = xlStorageNew.DeleteVol(t.Context(), "mybucket", false); err != errDiskAccessDenied {
|
||||
t.Fatalf("expected: Permission error, got: %s", err)
|
||||
}
|
||||
}
|
||||
@@ -676,7 +675,7 @@ func TestXLStorageDeleteVol(t *testing.T) {
|
||||
|
||||
// TestXLStorage for delete on an removed disk.
|
||||
// should fail with disk not found.
|
||||
err = xlStorageDeletedStorage.DeleteVol(context.Background(), "Del-Vol", false)
|
||||
err = xlStorageDeletedStorage.DeleteVol(t.Context(), "Del-Vol", false)
|
||||
if err != errDiskNotFound {
|
||||
t.Errorf("Expected: \"Drive not found\", got \"%s\"", err)
|
||||
}
|
||||
@@ -691,7 +690,7 @@ func TestXLStorageStatVol(t *testing.T) {
|
||||
}
|
||||
|
||||
// Setup test environment.
|
||||
if err = xlStorage.MakeVol(context.Background(), "success-vol"); err != nil {
|
||||
if err = xlStorage.MakeVol(t.Context(), "success-vol"); err != nil {
|
||||
t.Fatalf("Unable to create volume, %s", err)
|
||||
}
|
||||
|
||||
@@ -718,7 +717,7 @@ func TestXLStorageStatVol(t *testing.T) {
|
||||
|
||||
for i, testCase := range testCases {
|
||||
var volInfo VolInfo
|
||||
volInfo, err = xlStorage.StatVol(context.Background(), testCase.volName)
|
||||
volInfo, err = xlStorage.StatVol(t.Context(), testCase.volName)
|
||||
if err != testCase.expectedErr {
|
||||
t.Fatalf("TestXLStorage case : %d, Expected: \"%s\", got: \"%s\"", i+1, testCase.expectedErr, err)
|
||||
}
|
||||
@@ -740,7 +739,7 @@ func TestXLStorageStatVol(t *testing.T) {
|
||||
|
||||
// TestXLStorage for delete on an removed disk.
|
||||
// should fail with disk not found.
|
||||
_, err = xlStorageDeletedStorage.StatVol(context.Background(), "Stat vol")
|
||||
_, err = xlStorageDeletedStorage.StatVol(t.Context(), "Stat vol")
|
||||
if err != errDiskNotFound {
|
||||
t.Errorf("Expected: \"Drive not found\", got \"%s\"", err)
|
||||
}
|
||||
@@ -756,18 +755,18 @@ func TestXLStorageListVols(t *testing.T) {
|
||||
|
||||
var volInfos []VolInfo
|
||||
// TestXLStorage empty list vols.
|
||||
if volInfos, err = xlStorage.ListVols(context.Background()); err != nil {
|
||||
if volInfos, err = xlStorage.ListVols(t.Context()); err != nil {
|
||||
t.Fatalf("expected: <nil>, got: %s", err)
|
||||
} else if len(volInfos) != 1 {
|
||||
t.Fatalf("expected: one entry, got: %v", volInfos)
|
||||
}
|
||||
|
||||
// TestXLStorage non-empty list vols.
|
||||
if err = xlStorage.MakeVol(context.Background(), "success-vol"); err != nil {
|
||||
if err = xlStorage.MakeVol(t.Context(), "success-vol"); err != nil {
|
||||
t.Fatalf("Unable to create volume, %s", err)
|
||||
}
|
||||
|
||||
volInfos, err = xlStorage.ListVols(context.Background())
|
||||
volInfos, err = xlStorage.ListVols(t.Context())
|
||||
if err != nil {
|
||||
t.Fatalf("expected: <nil>, got: %s", err)
|
||||
}
|
||||
@@ -788,7 +787,7 @@ func TestXLStorageListVols(t *testing.T) {
|
||||
// removing the path and simulating disk failure
|
||||
os.RemoveAll(path)
|
||||
// should fail with errDiskNotFound.
|
||||
if _, err = xlStorage.ListVols(context.Background()); err != errDiskNotFound {
|
||||
if _, err = xlStorage.ListVols(t.Context()); err != errDiskNotFound {
|
||||
t.Errorf("Expected to fail with \"%s\", but instead failed with \"%s\"", errDiskNotFound, err)
|
||||
}
|
||||
}
|
||||
@@ -809,13 +808,13 @@ func TestXLStorageListDir(t *testing.T) {
|
||||
// removing the disk, used to recreate disk not found error.
|
||||
os.RemoveAll(diskPath)
|
||||
// Setup test environment.
|
||||
if err = xlStorage.MakeVol(context.Background(), "success-vol"); err != nil {
|
||||
if err = xlStorage.MakeVol(t.Context(), "success-vol"); err != nil {
|
||||
t.Fatalf("Unable to create volume, %s", err)
|
||||
}
|
||||
if err = xlStorage.AppendFile(context.Background(), "success-vol", "abc/def/ghi/success-file", []byte("Hello, world")); err != nil {
|
||||
if err = xlStorage.AppendFile(t.Context(), "success-vol", "abc/def/ghi/success-file", []byte("Hello, world")); err != nil {
|
||||
t.Fatalf("Unable to create file, %s", err)
|
||||
}
|
||||
if err = xlStorage.AppendFile(context.Background(), "success-vol", "abc/xyz/ghi/success-file", []byte("Hello, world")); err != nil {
|
||||
if err = xlStorage.AppendFile(t.Context(), "success-vol", "abc/xyz/ghi/success-file", []byte("Hello, world")); err != nil {
|
||||
t.Fatalf("Unable to create file, %s", err)
|
||||
}
|
||||
|
||||
@@ -874,7 +873,7 @@ func TestXLStorageListDir(t *testing.T) {
|
||||
|
||||
for i, testCase := range testCases {
|
||||
var dirList []string
|
||||
dirList, err = xlStorage.ListDir(context.Background(), "", testCase.srcVol, testCase.srcPath, -1)
|
||||
dirList, err = xlStorage.ListDir(t.Context(), "", testCase.srcVol, testCase.srcPath, -1)
|
||||
if err != testCase.expectedErr {
|
||||
t.Errorf("TestXLStorage case %d: Expected: \"%s\", got: \"%s\"", i+1, testCase.expectedErr, err)
|
||||
}
|
||||
@@ -906,7 +905,7 @@ func TestXLStorageListDir(t *testing.T) {
|
||||
t.Fatalf("Unable to initialize xlStorage, %s", err)
|
||||
}
|
||||
|
||||
if err = xlStorageNew.Delete(context.Background(), "mybucket", "myobject", DeleteOptions{
|
||||
if err = xlStorageNew.Delete(t.Context(), "mybucket", "myobject", DeleteOptions{
|
||||
Recursive: false,
|
||||
Immediate: false,
|
||||
}); err != errFileAccessDenied {
|
||||
@@ -916,7 +915,7 @@ func TestXLStorageListDir(t *testing.T) {
|
||||
|
||||
// TestXLStorage for delete on an removed disk.
|
||||
// should fail with disk not found.
|
||||
err = xlStorageDeletedStorage.Delete(context.Background(), "del-vol", "my-file", DeleteOptions{
|
||||
err = xlStorageDeletedStorage.Delete(t.Context(), "del-vol", "my-file", DeleteOptions{
|
||||
Recursive: false,
|
||||
Immediate: false,
|
||||
})
|
||||
@@ -938,17 +937,17 @@ func TestXLStorageDeleteFile(t *testing.T) {
|
||||
}
|
||||
|
||||
// Setup test environment.
|
||||
if err = xlStorage.MakeVol(context.Background(), "success-vol"); err != nil {
|
||||
if err = xlStorage.MakeVol(t.Context(), "success-vol"); err != nil {
|
||||
t.Fatalf("Unable to create volume, %s", err)
|
||||
}
|
||||
if err = xlStorage.AppendFile(context.Background(), "success-vol", "success-file", []byte("Hello, world")); err != nil {
|
||||
if err = xlStorage.AppendFile(t.Context(), "success-vol", "success-file", []byte("Hello, world")); err != nil {
|
||||
t.Fatalf("Unable to create file, %s", err)
|
||||
}
|
||||
|
||||
if err = xlStorage.MakeVol(context.Background(), "no-permissions"); err != nil {
|
||||
if err = xlStorage.MakeVol(t.Context(), "no-permissions"); err != nil {
|
||||
t.Fatalf("Unable to create volume, %s", err.Error())
|
||||
}
|
||||
if err = xlStorage.AppendFile(context.Background(), "no-permissions", "dir/file", []byte("Hello, world")); err != nil {
|
||||
if err = xlStorage.AppendFile(t.Context(), "no-permissions", "dir/file", []byte("Hello, world")); err != nil {
|
||||
t.Fatalf("Unable to create file, %s", err.Error())
|
||||
}
|
||||
// Parent directory must have write permissions, this is read + execute.
|
||||
@@ -1002,7 +1001,7 @@ func TestXLStorageDeleteFile(t *testing.T) {
|
||||
}
|
||||
|
||||
for i, testCase := range testCases {
|
||||
if err = xlStorage.Delete(context.Background(), testCase.srcVol, testCase.srcPath, DeleteOptions{
|
||||
if err = xlStorage.Delete(t.Context(), testCase.srcVol, testCase.srcPath, DeleteOptions{
|
||||
Recursive: false,
|
||||
Immediate: false,
|
||||
}); err != testCase.expectedErr {
|
||||
@@ -1029,7 +1028,7 @@ func TestXLStorageDeleteFile(t *testing.T) {
|
||||
t.Fatalf("Unable to initialize xlStorage, %s", err)
|
||||
}
|
||||
|
||||
if err = xlStorageNew.Delete(context.Background(), "mybucket", "myobject", DeleteOptions{
|
||||
if err = xlStorageNew.Delete(t.Context(), "mybucket", "myobject", DeleteOptions{
|
||||
Recursive: false,
|
||||
Immediate: false,
|
||||
}); err != errFileAccessDenied {
|
||||
@@ -1050,7 +1049,7 @@ func TestXLStorageDeleteFile(t *testing.T) {
|
||||
|
||||
// TestXLStorage for delete on an removed disk.
|
||||
// should fail with disk not found.
|
||||
err = xlStorageDeletedStorage.Delete(context.Background(), "del-vol", "my-file", DeleteOptions{
|
||||
err = xlStorageDeletedStorage.Delete(t.Context(), "del-vol", "my-file", DeleteOptions{
|
||||
Recursive: false,
|
||||
Immediate: false,
|
||||
})
|
||||
@@ -1069,7 +1068,7 @@ func TestXLStorageReadFile(t *testing.T) {
|
||||
|
||||
volume := "success-vol"
|
||||
// Setup test environment.
|
||||
if err = xlStorage.MakeVol(context.Background(), volume); err != nil {
|
||||
if err = xlStorage.MakeVol(t.Context(), volume); err != nil {
|
||||
t.Fatalf("Unable to create volume, %s", err)
|
||||
}
|
||||
|
||||
@@ -1156,7 +1155,7 @@ func TestXLStorageReadFile(t *testing.T) {
|
||||
v := NewBitrotVerifier(SHA256, getSHA256Sum([]byte("hello, world")))
|
||||
// Create test files for further reading.
|
||||
for i, appendFile := range appendFiles {
|
||||
err = xlStorage.AppendFile(context.Background(), volume, appendFile.fileName, []byte("hello, world"))
|
||||
err = xlStorage.AppendFile(t.Context(), volume, appendFile.fileName, []byte("hello, world"))
|
||||
if err != appendFile.expectedErr {
|
||||
t.Fatalf("Creating file failed: %d %#v, expected: %s, got: %s", i+1, appendFile, appendFile.expectedErr, err)
|
||||
}
|
||||
@@ -1165,7 +1164,7 @@ func TestXLStorageReadFile(t *testing.T) {
|
||||
{
|
||||
buf := make([]byte, 5)
|
||||
// Test for negative offset.
|
||||
if _, err = xlStorage.ReadFile(context.Background(), volume, "myobject", -1, buf, v); err == nil {
|
||||
if _, err = xlStorage.ReadFile(t.Context(), volume, "myobject", -1, buf, v); err == nil {
|
||||
t.Fatalf("expected: error, got: <nil>")
|
||||
}
|
||||
}
|
||||
@@ -1176,7 +1175,7 @@ func TestXLStorageReadFile(t *testing.T) {
|
||||
var n int64
|
||||
// Common read buffer.
|
||||
buf := make([]byte, testCase.bufSize)
|
||||
n, err = xlStorage.ReadFile(context.Background(), testCase.volume, testCase.fileName, testCase.offset, buf, v)
|
||||
n, err = xlStorage.ReadFile(t.Context(), testCase.volume, testCase.fileName, testCase.offset, buf, v)
|
||||
if err != nil && testCase.expectedErr != nil {
|
||||
// Validate if the type string of the errors are an exact match.
|
||||
if err.Error() != testCase.expectedErr.Error() {
|
||||
@@ -1252,7 +1251,7 @@ func TestXLStorageReadFile(t *testing.T) {
|
||||
|
||||
// Common read buffer.
|
||||
buf := make([]byte, 10)
|
||||
if _, err = xlStoragePermStorage.ReadFile(context.Background(), "mybucket", "myobject", 0, buf, v); err != errFileAccessDenied {
|
||||
if _, err = xlStoragePermStorage.ReadFile(t.Context(), "mybucket", "myobject", 0, buf, v); err != errFileAccessDenied {
|
||||
t.Errorf("expected: %s, got: %s", errFileAccessDenied, err)
|
||||
}
|
||||
}
|
||||
@@ -1293,14 +1292,14 @@ func TestXLStorageReadFileWithVerify(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to create xlStorage test setup, %s", err)
|
||||
}
|
||||
if err = xlStorage.MakeVol(context.Background(), volume); err != nil {
|
||||
if err = xlStorage.MakeVol(t.Context(), volume); err != nil {
|
||||
t.Fatalf("Unable to create volume %s: %v", volume, err)
|
||||
}
|
||||
data := make([]byte, 8*1024)
|
||||
if _, err = io.ReadFull(rand.Reader, data); err != nil {
|
||||
t.Fatalf("Unable to create generate random data: %v", err)
|
||||
}
|
||||
if err = xlStorage.AppendFile(context.Background(), volume, object, data); err != nil {
|
||||
if err = xlStorage.AppendFile(t.Context(), volume, object, data); err != nil {
|
||||
t.Fatalf("Unable to create object: %v", err)
|
||||
}
|
||||
|
||||
@@ -1312,7 +1311,7 @@ func TestXLStorageReadFileWithVerify(t *testing.T) {
|
||||
}
|
||||
|
||||
buffer := make([]byte, test.length)
|
||||
n, err := xlStorage.ReadFile(context.Background(), volume, test.file, int64(test.offset), buffer, NewBitrotVerifier(test.algorithm, h.Sum(nil)))
|
||||
n, err := xlStorage.ReadFile(t.Context(), volume, test.file, int64(test.offset), buffer, NewBitrotVerifier(test.algorithm, h.Sum(nil)))
|
||||
|
||||
switch {
|
||||
case err == nil && test.expError != nil:
|
||||
@@ -1335,7 +1334,7 @@ func TestXLStorageFormatFileChange(t *testing.T) {
|
||||
t.Fatalf("Unable to create xlStorage test setup, %s", err)
|
||||
}
|
||||
|
||||
if err = xlStorage.MakeVol(context.Background(), volume); err != nil {
|
||||
if err = xlStorage.MakeVol(t.Context(), volume); err != nil {
|
||||
t.Fatalf("MakeVol failed with %s", err)
|
||||
}
|
||||
|
||||
@@ -1344,7 +1343,7 @@ func TestXLStorageFormatFileChange(t *testing.T) {
|
||||
t.Fatalf("ioutil.WriteFile failed with %s", err)
|
||||
}
|
||||
|
||||
err = xlStorage.MakeVol(context.Background(), volume)
|
||||
err = xlStorage.MakeVol(t.Context(), volume)
|
||||
if err != errVolumeExists {
|
||||
t.Fatalf("MakeVol expected to fail with errDiskNotFound but failed with %s", err)
|
||||
}
|
||||
@@ -1359,7 +1358,7 @@ func TestXLStorageAppendFile(t *testing.T) {
|
||||
}
|
||||
|
||||
// Setup test environment.
|
||||
if err = xlStorage.MakeVol(context.Background(), "success-vol"); err != nil {
|
||||
if err = xlStorage.MakeVol(t.Context(), "success-vol"); err != nil {
|
||||
t.Fatalf("Unable to create volume, %s", err)
|
||||
}
|
||||
|
||||
@@ -1389,7 +1388,7 @@ func TestXLStorageAppendFile(t *testing.T) {
|
||||
}
|
||||
|
||||
for i, testCase := range testCases {
|
||||
if err = xlStorage.AppendFile(context.Background(), "success-vol", testCase.fileName, []byte("hello, world")); err != testCase.expectedErr {
|
||||
if err = xlStorage.AppendFile(t.Context(), "success-vol", testCase.fileName, []byte("hello, world")); err != testCase.expectedErr {
|
||||
t.Errorf("Case: %d, expected: %s, got: %s", i+1, testCase.expectedErr, err)
|
||||
}
|
||||
}
|
||||
@@ -1414,14 +1413,14 @@ func TestXLStorageAppendFile(t *testing.T) {
|
||||
t.Fatalf("Unable to initialize xlStorage, %s", err)
|
||||
}
|
||||
|
||||
if err = xlStoragePermStorage.AppendFile(context.Background(), "mybucket", "myobject", []byte("hello, world")); err != errFileAccessDenied {
|
||||
if err = xlStoragePermStorage.AppendFile(t.Context(), "mybucket", "myobject", []byte("hello, world")); err != errFileAccessDenied {
|
||||
t.Fatalf("expected: errFileAccessDenied error, got: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
// TestXLStorage case with invalid volume name.
|
||||
// A valid volume name should be at least of size 3.
|
||||
err = xlStorage.AppendFile(context.Background(), "bn", "yes", []byte("hello, world"))
|
||||
err = xlStorage.AppendFile(t.Context(), "bn", "yes", []byte("hello, world"))
|
||||
if err != errVolumeNotFound {
|
||||
t.Fatalf("expected: \"Invalid argument error\", got: \"%s\"", err)
|
||||
}
|
||||
@@ -1436,32 +1435,32 @@ func TestXLStorageRenameFile(t *testing.T) {
|
||||
}
|
||||
|
||||
// Setup test environment.
|
||||
if err := xlStorage.MakeVol(context.Background(), "src-vol"); err != nil {
|
||||
if err := xlStorage.MakeVol(t.Context(), "src-vol"); err != nil {
|
||||
t.Fatalf("Unable to create volume, %s", err)
|
||||
}
|
||||
|
||||
if err := xlStorage.MakeVol(context.Background(), "dest-vol"); err != nil {
|
||||
if err := xlStorage.MakeVol(t.Context(), "dest-vol"); err != nil {
|
||||
t.Fatalf("Unable to create volume, %s", err)
|
||||
}
|
||||
|
||||
if err := xlStorage.AppendFile(context.Background(), "src-vol", "file1", []byte("Hello, world")); err != nil {
|
||||
if err := xlStorage.AppendFile(t.Context(), "src-vol", "file1", []byte("Hello, world")); err != nil {
|
||||
t.Fatalf("Unable to create file, %s", err)
|
||||
}
|
||||
|
||||
if err := xlStorage.AppendFile(context.Background(), "src-vol", "file2", []byte("Hello, world")); err != nil {
|
||||
if err := xlStorage.AppendFile(t.Context(), "src-vol", "file2", []byte("Hello, world")); err != nil {
|
||||
t.Fatalf("Unable to create file, %s", err)
|
||||
}
|
||||
if err := xlStorage.AppendFile(context.Background(), "src-vol", "file3", []byte("Hello, world")); err != nil {
|
||||
if err := xlStorage.AppendFile(t.Context(), "src-vol", "file3", []byte("Hello, world")); err != nil {
|
||||
t.Fatalf("Unable to create file, %s", err)
|
||||
}
|
||||
if err := xlStorage.AppendFile(context.Background(), "src-vol", "file4", []byte("Hello, world")); err != nil {
|
||||
if err := xlStorage.AppendFile(t.Context(), "src-vol", "file4", []byte("Hello, world")); err != nil {
|
||||
t.Fatalf("Unable to create file, %s", err)
|
||||
}
|
||||
|
||||
if err := xlStorage.AppendFile(context.Background(), "src-vol", "file5", []byte("Hello, world")); err != nil {
|
||||
if err := xlStorage.AppendFile(t.Context(), "src-vol", "file5", []byte("Hello, world")); err != nil {
|
||||
t.Fatalf("Unable to create file, %s", err)
|
||||
}
|
||||
if err := xlStorage.AppendFile(context.Background(), "src-vol", "path/to/file1", []byte("Hello, world")); err != nil {
|
||||
if err := xlStorage.AppendFile(t.Context(), "src-vol", "path/to/file1", []byte("Hello, world")); err != nil {
|
||||
t.Fatalf("Unable to create file, %s", err)
|
||||
}
|
||||
|
||||
@@ -1638,7 +1637,7 @@ func TestXLStorageRenameFile(t *testing.T) {
|
||||
}
|
||||
|
||||
for i, testCase := range testCases {
|
||||
if err := xlStorage.RenameFile(context.Background(), testCase.srcVol, testCase.srcPath, testCase.destVol, testCase.destPath); err != testCase.expectedErr {
|
||||
if err := xlStorage.RenameFile(t.Context(), testCase.srcVol, testCase.srcPath, testCase.destVol, testCase.destPath); err != testCase.expectedErr {
|
||||
t.Fatalf("TestXLStorage %d: Expected the error to be : \"%v\", got: \"%v\".", i+1, testCase.expectedErr, err)
|
||||
}
|
||||
}
|
||||
@@ -1651,7 +1650,7 @@ func TestXLStorageDeleteVersion(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to create xlStorage test setup, %s", err)
|
||||
}
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
|
||||
volume := "myvol-vol"
|
||||
object := "my-object"
|
||||
@@ -1744,19 +1743,19 @@ func TestXLStorageStatInfoFile(t *testing.T) {
|
||||
}
|
||||
|
||||
// Setup test environment.
|
||||
if err := xlStorage.MakeVol(context.Background(), "success-vol"); err != nil {
|
||||
if err := xlStorage.MakeVol(t.Context(), "success-vol"); err != nil {
|
||||
t.Fatalf("Unable to create volume, %s", err)
|
||||
}
|
||||
|
||||
if err := xlStorage.AppendFile(context.Background(), "success-vol", pathJoin("success-file", xlStorageFormatFile), []byte("Hello, world")); err != nil {
|
||||
if err := xlStorage.AppendFile(t.Context(), "success-vol", pathJoin("success-file", xlStorageFormatFile), []byte("Hello, world")); err != nil {
|
||||
t.Fatalf("Unable to create file, %s", err)
|
||||
}
|
||||
|
||||
if err := xlStorage.AppendFile(context.Background(), "success-vol", pathJoin("path/to/success-file", xlStorageFormatFile), []byte("Hello, world")); err != nil {
|
||||
if err := xlStorage.AppendFile(t.Context(), "success-vol", pathJoin("path/to/success-file", xlStorageFormatFile), []byte("Hello, world")); err != nil {
|
||||
t.Fatalf("Unable to create file, %s", err)
|
||||
}
|
||||
|
||||
if err := xlStorage.MakeVol(context.Background(), "success-vol/path/to/"+xlStorageFormatFile); err != nil {
|
||||
if err := xlStorage.MakeVol(t.Context(), "success-vol/path/to/"+xlStorageFormatFile); err != nil {
|
||||
t.Fatalf("Unable to create path, %s", err)
|
||||
}
|
||||
|
||||
@@ -1817,7 +1816,7 @@ func TestXLStorageStatInfoFile(t *testing.T) {
|
||||
}
|
||||
|
||||
for i, testCase := range testCases {
|
||||
_, err := xlStorage.StatInfoFile(context.Background(), testCase.srcVol, testCase.srcPath+"/"+xlStorageFormatFile, false)
|
||||
_, err := xlStorage.StatInfoFile(t.Context(), testCase.srcVol, testCase.srcPath+"/"+xlStorageFormatFile, false)
|
||||
if err != testCase.expectedErr {
|
||||
t.Errorf("TestXLStorage case %d: Expected: \"%s\", got: \"%s\"", i+1, testCase.expectedErr, err)
|
||||
}
|
||||
@@ -1840,7 +1839,7 @@ func TestXLStorageVerifyFile(t *testing.T) {
|
||||
|
||||
volName := "testvol"
|
||||
fileName := "testfile"
|
||||
if err := storage.MakeVol(context.Background(), volName); err != nil {
|
||||
if err := storage.MakeVol(t.Context(), volName); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -1854,29 +1853,29 @@ func TestXLStorageVerifyFile(t *testing.T) {
|
||||
h := algo.New()
|
||||
h.Write(data)
|
||||
hashBytes := h.Sum(nil)
|
||||
if err := storage.WriteAll(context.Background(), volName, fileName, data); err != nil {
|
||||
if err := storage.WriteAll(t.Context(), volName, fileName, data); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := storage.storage.bitrotVerify(context.Background(), pathJoin(path, volName, fileName), size, algo, hashBytes, 0); err != nil {
|
||||
if err := storage.storage.bitrotVerify(t.Context(), pathJoin(path, volName, fileName), size, algo, hashBytes, 0); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// 2) Whole-file bitrot check on corrupted file
|
||||
if err := storage.AppendFile(context.Background(), volName, fileName, []byte("a")); err != nil {
|
||||
if err := storage.AppendFile(t.Context(), volName, fileName, []byte("a")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Check if VerifyFile reports the incorrect file length (the correct length is `size+1`)
|
||||
if err := storage.storage.bitrotVerify(context.Background(), pathJoin(path, volName, fileName), size, algo, hashBytes, 0); err == nil {
|
||||
if err := storage.storage.bitrotVerify(t.Context(), pathJoin(path, volName, fileName), size, algo, hashBytes, 0); err == nil {
|
||||
t.Fatal("expected to fail bitrot check")
|
||||
}
|
||||
|
||||
// Check if bitrot fails
|
||||
if err := storage.storage.bitrotVerify(context.Background(), pathJoin(path, volName, fileName), size+1, algo, hashBytes, 0); err == nil {
|
||||
if err := storage.storage.bitrotVerify(t.Context(), pathJoin(path, volName, fileName), size+1, algo, hashBytes, 0); err == nil {
|
||||
t.Fatal("expected to fail bitrot check")
|
||||
}
|
||||
|
||||
if err := storage.Delete(context.Background(), volName, fileName, DeleteOptions{
|
||||
if err := storage.Delete(t.Context(), volName, fileName, DeleteOptions{
|
||||
Recursive: false,
|
||||
Immediate: false,
|
||||
}); err != nil {
|
||||
@@ -1904,7 +1903,7 @@ func TestXLStorageVerifyFile(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
w.(io.Closer).Close()
|
||||
if err := storage.storage.bitrotVerify(context.Background(), pathJoin(path, volName, fileName), size, algo, nil, shardSize); err != nil {
|
||||
if err := storage.storage.bitrotVerify(t.Context(), pathJoin(path, volName, fileName), size, algo, nil, shardSize); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -1919,10 +1918,10 @@ func TestXLStorageVerifyFile(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
f.Close()
|
||||
if err := storage.storage.bitrotVerify(context.Background(), pathJoin(path, volName, fileName), size, algo, nil, shardSize); err == nil {
|
||||
if err := storage.storage.bitrotVerify(t.Context(), pathJoin(path, volName, fileName), size, algo, nil, shardSize); err == nil {
|
||||
t.Fatal("expected to fail bitrot check")
|
||||
}
|
||||
if err := storage.storage.bitrotVerify(context.Background(), pathJoin(path, volName, fileName), size+1, algo, nil, shardSize); err == nil {
|
||||
if err := storage.storage.bitrotVerify(t.Context(), pathJoin(path, volName, fileName), size+1, algo, nil, shardSize); err == nil {
|
||||
t.Fatal("expected to fail bitrot check")
|
||||
}
|
||||
}
|
||||
@@ -1937,8 +1936,8 @@ func TestXLStorageReadMetadata(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
disk.MakeVol(context.Background(), volume)
|
||||
if _, err := disk.readMetadata(context.Background(), pathJoin(tmpDir, volume, object)); err != errFileNameTooLong {
|
||||
disk.MakeVol(t.Context(), volume)
|
||||
if _, err := disk.readMetadata(t.Context(), pathJoin(tmpDir, volume, object)); err != errFileNameTooLong {
|
||||
t.Fatalf("Unexpected error from readMetadata - expect %v: got %v", errFileNameTooLong, err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user