github.com/minio/minio@v0.0.0-20240328213742-3f72439b8a27/internal/config/etcd/etcd_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 etcd 19 20 import ( 21 "reflect" 22 "testing" 23 ) 24 25 // TestParseEndpoints - tests parseEndpoints function with valid and invalid inputs. 26 func TestParseEndpoints(t *testing.T) { 27 testCases := []struct { 28 s string 29 endpoints []string 30 secure bool 31 success bool 32 }{ 33 // Invalid inputs 34 {"https://localhost:2379,http://localhost:2380", nil, false, false}, 35 {",,,", nil, false, false}, 36 {"", nil, false, false}, 37 {"ftp://localhost:2379", nil, false, false}, 38 {"http://localhost:2379000", nil, false, false}, 39 40 // Valid inputs 41 { 42 "https://localhost:2379,https://localhost:2380", 43 []string{ 44 "https://localhost:2379", "https://localhost:2380", 45 }, 46 true, true, 47 }, 48 {"http://localhost:2379", []string{"http://localhost:2379"}, false, true}, 49 } 50 51 for _, testCase := range testCases { 52 testCase := testCase 53 t.Run(testCase.s, func(t *testing.T) { 54 endpoints, secure, err := parseEndpoints(testCase.s) 55 if err != nil && testCase.success { 56 t.Errorf("expected to succeed but failed with %s", err) 57 } 58 if !testCase.success && err == nil { 59 t.Error("expected failure but succeeded instead") 60 } 61 if testCase.success { 62 if !reflect.DeepEqual(endpoints, testCase.endpoints) { 63 t.Errorf("expected %s, got %s", testCase.endpoints, endpoints) 64 } 65 if secure != testCase.secure { 66 t.Errorf("expected %t, got %t", testCase.secure, secure) 67 } 68 } 69 }) 70 } 71 }