github.com/minio/minio@v0.0.0-20240328213742-3f72439b8a27/cmd/os-reliable_test.go (about)

     1  // Copyright (c) 2015-2021 MinIO, Inc.
     2  //
     3  // This file is part of MinIO Object Storage stack
     4  //
     5  // This program is free software: you can redistribute it and/or modify
     6  // it under the terms of the GNU Affero General Public License as published by
     7  // the Free Software Foundation, either version 3 of the License, or
     8  // (at your option) any later version.
     9  //
    10  // This program is distributed in the hope that it will be useful
    11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13  // GNU Affero General Public License for more details.
    14  //
    15  // You should have received a copy of the GNU Affero General Public License
    16  // along with this program.  If not, see <http://www.gnu.org/licenses/>.
    17  
    18  package cmd
    19  
    20  import (
    21  	"testing"
    22  )
    23  
    24  // Tests - mkdirAll()
    25  func TestOSMkdirAll(t *testing.T) {
    26  	// create xlStorage test setup
    27  	_, path, err := newXLStorageTestSetup(t)
    28  	if err != nil {
    29  		t.Fatalf("Unable to create xlStorage test setup, %s", err)
    30  	}
    31  
    32  	if err = mkdirAll("", 0o777, ""); err != errInvalidArgument {
    33  		t.Fatal("Unexpected error", err)
    34  	}
    35  
    36  	if err = mkdirAll(pathJoin(path, "my-obj-del-0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001"), 0o777, ""); err != errFileNameTooLong {
    37  		t.Fatal("Unexpected error", err)
    38  	}
    39  
    40  	if err = mkdirAll(pathJoin(path, "success-vol", "success-object"), 0o777, ""); err != nil {
    41  		t.Fatal("Unexpected error", err)
    42  	}
    43  }
    44  
    45  // Tests - renameAll()
    46  func TestOSRenameAll(t *testing.T) {
    47  	// create xlStorage test setup
    48  	_, path, err := newXLStorageTestSetup(t)
    49  	if err != nil {
    50  		t.Fatalf("Unable to create xlStorage test setup, %s", err)
    51  	}
    52  
    53  	if err = mkdirAll(pathJoin(path, "testvolume1"), 0o777, ""); err != nil {
    54  		t.Fatal(err)
    55  	}
    56  	if err = renameAll("", "foo", ""); err != errInvalidArgument {
    57  		t.Fatal(err)
    58  	}
    59  	if err = renameAll("foo", "", ""); err != errInvalidArgument {
    60  		t.Fatal(err)
    61  	}
    62  	if err = renameAll(pathJoin(path, "testvolume1"), pathJoin(path, "testvolume2"), ""); err != nil {
    63  		t.Fatal(err)
    64  	}
    65  	if err = renameAll(pathJoin(path, "testvolume1"), pathJoin(path, "testvolume2"), ""); err != errFileNotFound {
    66  		t.Fatal(err)
    67  	}
    68  	if err = renameAll(pathJoin(path, "my-obj-del-0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001"), pathJoin(path, "testvolume2"), ""); err != errFileNameTooLong {
    69  		t.Fatal("Unexpected error", err)
    70  	}
    71  	if err = renameAll(pathJoin(path, "testvolume1"), pathJoin(path, "my-obj-del-0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001"), ""); err != errFileNameTooLong {
    72  		t.Fatal("Unexpected error", err)
    73  	}
    74  }