forked from influxdata/influxdb-iox-client-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
iox_client_config_test.go
80 lines (70 loc) · 1.86 KB
/
iox_client_config_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package influxdbiox_test
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
"github.com/influxdata/influxdb-iox-client-go/v2"
)
func ExampleClientConfig_ToJSONString() {
config := &influxdbiox.ClientConfig{
Address: "localhost:8082",
}
s, _ := config.ToJSONString()
println(s)
}
func ExampleClientConfigFromJSONString() {
// Multiline, indented JSON is accepted.
dsn := `{
"address": "localhost:8082",
"tls_ca": "..."
}`
config, _ := influxdbiox.ClientConfigFromJSONString(dsn)
println(config)
config, _ = influxdbiox.ClientConfigFromJSONString(`{"address":"localhost:8082","tls_ca":"..."}`)
println(config)
}
func ExampleClientConfigFromAddressString() {
config, _ := influxdbiox.ClientConfigFromAddressString("localhost:8082")
println(config)
config, _ = influxdbiox.ClientConfigFromAddressString("localhost:8082/mydb")
println(config)
}
func TestClientConfigFromAddressString(t *testing.T) {
tests := []struct {
s string
expectConfig *influxdbiox.ClientConfig
expectError bool
}{{
s: "",
expectConfig: nil,
expectError: true,
}, {
s: "localhost:8082",
expectConfig: &influxdbiox.ClientConfig{Address: "localhost:8082"},
expectError: false,
}, {
s: "localhost:8082/mydb",
expectConfig: &influxdbiox.ClientConfig{Address: "localhost:8082", Namespace: "mydb"},
expectError: false,
}, {
s: "localhost",
expectConfig: nil,
expectError: true,
}, {
s: "localhost/mydb",
expectConfig: nil,
expectError: true,
}}
for i, test := range tests {
t.Run(fmt.Sprint(i), func(t *testing.T) {
gotConfig, gotErr := influxdbiox.ClientConfigFromAddressString(test.s)
if test.expectError {
assert.Nil(t, gotConfig)
assert.Error(t, gotErr)
} else {
assert.Equal(t, test.expectConfig, gotConfig)
assert.NoError(t, gotErr)
}
})
}
}