github.com/minio/minio@v0.0.0-20240328213742-3f72439b8a27/cmd/server-startup-msg_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 "os" 23 "reflect" 24 "strings" 25 "testing" 26 27 "github.com/minio/madmin-go/v3" 28 ) 29 30 // Tests if we generate storage info. 31 func TestStorageInfoMsg(t *testing.T) { 32 infoStorage := StorageInfo{} 33 infoStorage.Disks = []madmin.Disk{ 34 {Endpoint: "http://127.0.0.1:9000/data/1/", State: madmin.DriveStateOk}, 35 {Endpoint: "http://127.0.0.1:9000/data/2/", State: madmin.DriveStateOk}, 36 {Endpoint: "http://127.0.0.1:9000/data/3/", State: madmin.DriveStateOk}, 37 {Endpoint: "http://127.0.0.1:9000/data/4/", State: madmin.DriveStateOk}, 38 {Endpoint: "http://127.0.0.1:9001/data/1/", State: madmin.DriveStateOk}, 39 {Endpoint: "http://127.0.0.1:9001/data/2/", State: madmin.DriveStateOk}, 40 {Endpoint: "http://127.0.0.1:9001/data/3/", State: madmin.DriveStateOk}, 41 {Endpoint: "http://127.0.0.1:9001/data/4/", State: madmin.DriveStateOffline}, 42 } 43 infoStorage.Backend.Type = madmin.Erasure 44 45 if msg := getStorageInfoMsg(infoStorage); !strings.Contains(msg, "7 Online, 1 Offline") { 46 t.Fatal("Unexpected storage info message, found:", msg) 47 } 48 } 49 50 // Tests stripping standard ports from apiEndpoints. 51 func TestStripStandardPorts(t *testing.T) { 52 apiEndpoints := []string{"http://127.0.0.1:9000", "http://127.0.0.2:80", "https://127.0.0.3:443"} 53 expectedAPIEndpoints := []string{"http://127.0.0.1:9000", "http://127.0.0.2", "https://127.0.0.3"} 54 newAPIEndpoints := stripStandardPorts(apiEndpoints, "") 55 56 if !reflect.DeepEqual(expectedAPIEndpoints, newAPIEndpoints) { 57 t.Fatalf("Expected %#v, got %#v", expectedAPIEndpoints, newAPIEndpoints) 58 } 59 60 apiEndpoints = []string{"http://%%%%%:9000"} 61 newAPIEndpoints = stripStandardPorts(apiEndpoints, "") 62 if !reflect.DeepEqual(apiEndpoints, newAPIEndpoints) { 63 t.Fatalf("Expected %#v, got %#v", apiEndpoints, newAPIEndpoints) 64 } 65 66 apiEndpoints = []string{"http://127.0.0.1:443", "https://127.0.0.1:80"} 67 newAPIEndpoints = stripStandardPorts(apiEndpoints, "") 68 if !reflect.DeepEqual(apiEndpoints, newAPIEndpoints) { 69 t.Fatalf("Expected %#v, got %#v", apiEndpoints, newAPIEndpoints) 70 } 71 } 72 73 // Test printing server common message. 74 func TestPrintServerCommonMessage(t *testing.T) { 75 ctx, cancel := context.WithCancel(context.Background()) 76 defer cancel() 77 78 obj, fsDir, err := prepareFS(ctx) 79 if err != nil { 80 t.Fatal(err) 81 } 82 defer os.RemoveAll(fsDir) 83 if err = newTestConfig(globalMinioDefaultRegion, obj); err != nil { 84 t.Fatal(err) 85 } 86 87 apiEndpoints := []string{"http://127.0.0.1:9000"} 88 printServerCommonMsg(apiEndpoints) 89 } 90 91 // Tests print cli access message. 92 func TestPrintCLIAccessMsg(t *testing.T) { 93 ctx, cancel := context.WithCancel(context.Background()) 94 defer cancel() 95 96 obj, fsDir, err := prepareFS(ctx) 97 if err != nil { 98 t.Fatal(err) 99 } 100 defer os.RemoveAll(fsDir) 101 if err = newTestConfig(globalMinioDefaultRegion, obj); err != nil { 102 t.Fatal(err) 103 } 104 105 apiEndpoints := []string{"http://127.0.0.1:9000"} 106 printCLIAccessMsg(apiEndpoints[0], "myminio") 107 } 108 109 // Test print startup message. 110 func TestPrintStartupMessage(t *testing.T) { 111 ctx, cancel := context.WithCancel(context.Background()) 112 defer cancel() 113 114 obj, fsDir, err := prepareFS(ctx) 115 if err != nil { 116 t.Fatal(err) 117 } 118 defer os.RemoveAll(fsDir) 119 if err = newTestConfig(globalMinioDefaultRegion, obj); err != nil { 120 t.Fatal(err) 121 } 122 123 apiEndpoints := []string{"http://127.0.0.1:9000"} 124 printStartupMessage(apiEndpoints, nil) 125 }