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