github.com/minio/minio@v0.0.0-20240328213742-3f72439b8a27/cmd/server-main_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 "context" 22 "reflect" 23 "testing" 24 ) 25 26 func TestServerConfigFile(t *testing.T) { 27 for _, testcase := range []struct { 28 config string 29 expectedErr bool 30 hash string 31 }{ 32 { 33 config: "testdata/config/1.yaml", 34 expectedErr: false, 35 hash: "hash:02bf70285dc71f76", 36 }, 37 { 38 config: "testdata/config/2.yaml", 39 expectedErr: false, 40 hash: "hash:676d2da00f71f205", 41 }, 42 { 43 config: "testdata/config/invalid.yaml", 44 expectedErr: true, 45 }, 46 { 47 config: "testdata/config/invalid-types.yaml", 48 expectedErr: true, 49 }, 50 { 51 config: "testdata/config/invalid-disks.yaml", 52 expectedErr: true, 53 }, 54 } { 55 testcase := testcase 56 t.Run(testcase.config, func(t *testing.T) { 57 sctx := &serverCtxt{} 58 err := mergeServerCtxtFromConfigFile(testcase.config, sctx) 59 if testcase.expectedErr && err == nil { 60 t.Error("expected failure, got success") 61 } 62 if !testcase.expectedErr && err != nil { 63 t.Error("expected success, got failure", err) 64 } 65 if err == nil { 66 if len(sctx.Layout.pools) != 2 { 67 t.Error("expected parsed pools to be 2, not", len(sctx.Layout.pools)) 68 } 69 if sctx.Layout.pools[0].cmdline != testcase.hash { 70 t.Error("expected hash", testcase.hash, "got", sctx.Layout.pools[0].cmdline) 71 } 72 } 73 }) 74 } 75 } 76 77 // Tests initializing new object layer. 78 func TestNewObjectLayer(t *testing.T) { 79 ctx, cancel := context.WithCancel(context.Background()) 80 defer cancel() 81 // Tests for ErasureSD object layer. 82 nDisks := 1 83 disks, err := getRandomDisks(nDisks) 84 if err != nil { 85 t.Fatal("Failed to create drives for the backend") 86 } 87 defer removeRoots(disks) 88 89 obj, err := newObjectLayer(ctx, mustGetPoolEndpoints(0, disks...)) 90 if err != nil { 91 t.Fatal("Unexpected object layer initialization error", err) 92 } 93 94 _, ok := obj.(*erasureServerPools) 95 if !ok { 96 t.Fatal("Unexpected object layer detected", reflect.TypeOf(obj)) 97 } 98 99 // Tests for Erasure object layer initialization. 100 101 // Create temporary backend for the test server. 102 nDisks = 16 103 disks, err = getRandomDisks(nDisks) 104 if err != nil { 105 t.Fatal("Failed to create drives for the backend") 106 } 107 defer removeRoots(disks) 108 109 obj, err = newObjectLayer(ctx, mustGetPoolEndpoints(0, disks...)) 110 if err != nil { 111 t.Fatal("Unexpected object layer initialization error", err) 112 } 113 114 _, ok = obj.(*erasureServerPools) 115 if !ok { 116 t.Fatal("Unexpected object layer detected", reflect.TypeOf(obj)) 117 } 118 }