storj.io/minio@v0.0.0-20230509071714-0cbc90f649b1/cmd/os-reliable_test.go (about) 1 /* 2 * MinIO Cloud Storage, (C) 2018 MinIO, Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package cmd 18 19 import ( 20 "os" 21 "testing" 22 ) 23 24 // Tests - mkdirAll() 25 func TestOSMkdirAll(t *testing.T) { 26 // create xlStorage test setup 27 _, path, err := newXLStorageTestSetup() 28 if err != nil { 29 t.Fatalf("Unable to create xlStorage test setup, %s", err) 30 } 31 defer os.RemoveAll(path) 32 33 if err = mkdirAll("", 0777); err != errInvalidArgument { 34 t.Fatal("Unexpected error", err) 35 } 36 37 if err = mkdirAll(pathJoin(path, "my-obj-del-0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001"), 0777); err != errFileNameTooLong { 38 t.Fatal("Unexpected error", err) 39 } 40 41 if err = mkdirAll(pathJoin(path, "success-vol", "success-object"), 0777); err != nil { 42 t.Fatal("Unexpected error", err) 43 } 44 } 45 46 // Tests - renameAll() 47 func TestOSRenameAll(t *testing.T) { 48 // create xlStorage test setup 49 _, path, err := newXLStorageTestSetup() 50 if err != nil { 51 t.Fatalf("Unable to create xlStorage test setup, %s", err) 52 } 53 defer os.RemoveAll(path) 54 55 if err = mkdirAll(pathJoin(path, "testvolume1"), 0777); err != nil { 56 t.Fatal(err) 57 } 58 if err = renameAll("", "foo"); err != errInvalidArgument { 59 t.Fatal(err) 60 } 61 if err = renameAll("foo", ""); err != errInvalidArgument { 62 t.Fatal(err) 63 } 64 if err = renameAll(pathJoin(path, "testvolume1"), pathJoin(path, "testvolume2")); err != nil { 65 t.Fatal(err) 66 } 67 if err = renameAll(pathJoin(path, "testvolume1"), pathJoin(path, "testvolume2")); err != errFileNotFound { 68 t.Fatal(err) 69 } 70 if err = renameAll(pathJoin(path, "my-obj-del-0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001"), pathJoin(path, "testvolume2")); err != errFileNameTooLong { 71 t.Fatal("Unexpected error", err) 72 } 73 if err = renameAll(pathJoin(path, "testvolume1"), pathJoin(path, "my-obj-del-0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001")); err != errFileNameTooLong { 74 t.Fatal("Unexpected error", err) 75 } 76 }