github.com/milvus-io/milvus-sdk-go/v2@v2.4.1/client/config_test.go (about) 1 package client 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 ) 8 9 func TestClientConfig(t *testing.T) { 10 // empty config. 11 assertConfig( 12 t, 13 &Config{}, 14 "", "", false, true, 15 ) 16 // local host 17 assertConfig( 18 t, 19 &Config{ 20 Address: "localhost:19540", 21 }, 22 "localhost:19540", "", false, false, 23 ) 24 // local secure host 25 assertConfig( 26 t, 27 &Config{ 28 Address: "localhost:19540", 29 EnableTLSAuth: true, 30 }, 31 "localhost:19540", "", true, false, 32 ) 33 // local http host 34 assertConfig( 35 t, 36 &Config{ 37 Address: "http://localhost:19540", 38 }, 39 "localhost:19540", "", false, false, 40 ) 41 // local https host 42 assertConfig( 43 t, 44 &Config{ 45 Address: "https://localhost:19540", 46 }, 47 "localhost:19540", "", true, false, 48 ) 49 // remote https host 50 assertConfig( 51 t, 52 &Config{ 53 Address: "https://xxxx-xxxx-xxxxx.com", 54 }, 55 "xxxx-xxxx-xxxxx.com:443", "", true, false, 56 ) 57 // remote https host with dbname 58 assertConfig( 59 t, 60 &Config{ 61 Address: "https://xxxx-xxxxxxxxxxxxxx-xxxxxx.aws-us-west-2.vectordb-sit.zillizcloud.com:19530/database_name", 62 APIKey: "test-token", 63 }, 64 "xxxx-xxxxxxxxxxxxxx-xxxxxx.aws-us-west-2.vectordb-sit.zillizcloud.com:19530", "database_name", true, false, 65 ) 66 67 // local secure host 68 assertConfig( 69 t, 70 &Config{ 71 Address: "https://localhost:19540", 72 }, 73 "localhost:19540", "", true, false, 74 ) 75 76 assertConfig( 77 t, 78 &Config{ 79 Address: "https://localhost:8080", 80 }, 81 "localhost:8080", "", true, false, 82 ) 83 assertConfig( 84 t, 85 &Config{ 86 Address: "https://localhost:port", 87 }, 88 "", "", false, true, 89 ) 90 assertConfig( 91 t, 92 &Config{ 93 Address: "http://localhost:8080", 94 }, 95 "localhost:8080", "", false, false, 96 ) 97 assertConfig( 98 t, 99 &Config{ 100 Address: "http://localhost:port", 101 }, 102 "", "", false, true, 103 ) 104 assertConfig( 105 t, 106 &Config{ 107 Address: "localhost:8080", 108 }, 109 "localhost:8080", "", false, false, 110 ) 111 assertConfig( 112 t, 113 &Config{ 114 Address: "localhost:8080", 115 DBName: "test_db", 116 }, 117 "localhost:8080", "test_db", false, false, 118 ) 119 } 120 121 func assertConfig(t *testing.T, c *Config, host string, db string, secure bool, isErr bool) { 122 err := c.parse() 123 if isErr { 124 assert.NotNil(t, err) 125 return 126 } 127 assert.Nil(t, err) 128 assert.Equal(t, c.EnableTLSAuth, secure) 129 assert.Equal(t, c.DBName, db) 130 assert.Equal(t, c.getParsedAddress(), host) 131 }