storj.io/minio@v0.0.0-20230509071714-0cbc90f649b1/cmd/fs-v1-rwpool_test.go (about) 1 /* 2 * MinIO Cloud Storage, (C) 2016, 2017 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 "runtime" 22 "testing" 23 24 "storj.io/minio/pkg/lock" 25 ) 26 27 // Tests long path calls. 28 func TestRWPoolLongPath(t *testing.T) { 29 rwPool := &fsIOPool{ 30 readersMap: make(map[string]*lock.RLockedFile), 31 } 32 33 longPath := "my-obj-del-0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001" 34 if _, err := rwPool.Create(longPath); err != errFileNameTooLong { 35 t.Fatal(err) 36 } 37 38 if _, err := rwPool.Write(longPath); err != errFileNameTooLong { 39 t.Fatal(err) 40 } 41 42 if _, err := rwPool.Open(longPath); err != errFileNameTooLong { 43 t.Fatal(err) 44 } 45 } 46 47 // Tests all RWPool methods. 48 func TestRWPool(t *testing.T) { 49 // create xlStorage test setup 50 _, path, err := newXLStorageTestSetup() 51 if err != nil { 52 t.Fatalf("Unable to create xlStorage test setup, %s", err) 53 } 54 defer os.RemoveAll(path) 55 56 rwPool := &fsIOPool{ 57 readersMap: make(map[string]*lock.RLockedFile), 58 } 59 wlk, err := rwPool.Create(pathJoin(path, "success-vol", "file/path/1.txt")) 60 if err != nil { 61 t.Fatal(err) 62 } 63 wlk.Close() 64 65 // Fails to create a parent directory if there is a file. 66 _, err = rwPool.Create(pathJoin(path, "success-vol", "file/path/1.txt/test")) 67 if err != errFileAccessDenied { 68 t.Fatal("Unexpected error", err) 69 } 70 71 // Fails to create a file if there is a directory. 72 _, err = rwPool.Create(pathJoin(path, "success-vol", "file")) 73 if runtime.GOOS == globalWindowsOSName { 74 if err != errFileAccessDenied { 75 t.Fatal("Unexpected error", err) 76 } 77 } else { 78 if err != errIsNotRegular { 79 t.Fatal("Unexpected error", err) 80 } 81 } 82 83 rlk, err := rwPool.Open(pathJoin(path, "success-vol", "file/path/1.txt")) 84 if err != nil { 85 t.Fatal("Unexpected error", err) 86 } 87 rlk.Close() 88 89 // Fails to read a directory. 90 _, err = rwPool.Open(pathJoin(path, "success-vol", "file")) 91 if runtime.GOOS == globalWindowsOSName { 92 if err != errFileAccessDenied { 93 t.Fatal("Unexpected error", err) 94 } 95 } else { 96 if err != errIsNotRegular { 97 t.Fatal("Unexpected error", err) 98 } 99 } 100 101 // Fails to open a file which has a parent as file. 102 _, err = rwPool.Open(pathJoin(path, "success-vol", "file/path/1.txt/test")) 103 if runtime.GOOS != globalWindowsOSName { 104 if err != errFileAccessDenied { 105 t.Fatal("Unexpected error", err) 106 } 107 } else { 108 if err != errFileNotFound { 109 t.Fatal("Unexpected error", err) 110 } 111 } 112 113 }