From 226a69fe15ac2be982b75f57b56fca9aa12bc460 Mon Sep 17 00:00:00 2001 From: Aditya Manthramurthy Date: Tue, 1 Nov 2016 20:04:32 -0700 Subject: [PATCH] Add test for updateUploadJSON (Fixes #3060) (#3155) --- cmd/xl-v1-multipart-common.go | 2 +- cmd/xl-v1-multipart-common_test.go | 73 ++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 cmd/xl-v1-multipart-common_test.go diff --git a/cmd/xl-v1-multipart-common.go b/cmd/xl-v1-multipart-common.go index ee73768d0..1278d617a 100644 --- a/cmd/xl-v1-multipart-common.go +++ b/cmd/xl-v1-multipart-common.go @@ -54,7 +54,7 @@ func (xl xlObjects) updateUploadJSON(bucket, object string, uCh uploadIDChange) // If we have a read error, we store error and // exit. if err != nil { - errs[index] = traceError(err) + errs[index] = err return } diff --git a/cmd/xl-v1-multipart-common_test.go b/cmd/xl-v1-multipart-common_test.go new file mode 100644 index 000000000..9c1019b58 --- /dev/null +++ b/cmd/xl-v1-multipart-common_test.go @@ -0,0 +1,73 @@ +/* + * Minio Cloud Storage, (C) 2014-2016 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package cmd + +import ( + "testing" + "time" +) + +func TestUpdateUploadJSON(t *testing.T) { + // Initialize configuration + root, err := newTestConfig("us-east-1") + if err != nil { + t.Fatalf("%s", err) + } + defer removeAll(root) + + // Create an instance of xl backend + obj, fsDirs, err := prepareXL() + if err != nil { + t.Fatal(err) + } + // Defer cleanup of backend directories + defer removeRoots(fsDirs) + + bucket, object := "bucket", "object" + err = obj.MakeBucket(bucket) + if err != nil { + t.Fatal(err) + } + + testCases := []struct { + uCh uploadIDChange + errVal error + }{ + {uploadIDChange{"111abc", time.Now().UTC(), false}, nil}, + {uploadIDChange{"222abc", time.Now().UTC(), false}, nil}, + {uploadIDChange{uploadID: "111abc", isRemove: true}, nil}, + } + + xl := obj.(xlObjects) + for i, test := range testCases { + testErrVal := xl.updateUploadJSON(bucket, object, test.uCh) + if testErrVal != test.errVal { + t.Errorf("Test %d: Expected error value %v, but got %v", + i+1, test.errVal, testErrVal) + } + } + + // make some disks faulty to simulate a failure. + for i := range xl.storageDisks[:9] { + xl.storageDisks[i] = newNaughtyDisk(xl.storageDisks[i].(*posix), nil, errFaultyDisk) + } + + testErrVal := xl.updateUploadJSON(bucket, object, uploadIDChange{"222abc", time.Now().UTC(), false}) + if testErrVal == nil || testErrVal.Error() != errXLWriteQuorum.Error() { + t.Errorf("Expected write quorum error, but got: %v", testErrVal) + } +}