-
Notifications
You must be signed in to change notification settings - Fork 1
/
driver_test.go
34 lines (31 loc) · 961 Bytes
/
driver_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
package openmldb
import (
"errors"
"testing"
"github.com/stretchr/testify/assert"
)
func Test_parseDsn(t *testing.T) {
for _, tc := range []struct {
dsn string
host string
db string
mode queryMode
err error
}{
{"openmldb://127.0.0.1:8080/test_db", "127.0.0.1:8080", "test_db", ModeOnline, nil},
{"openmldb://127.0.0.1:8080/test_db?mode=online", "127.0.0.1:8080", "test_db", ModeOnline, nil},
{"openmldb://127.0.0.1:8080/test_db?mode=offasync", "127.0.0.1:8080", "test_db", ModeOffasync, nil},
{"openmldb://127.0.0.1:8080/test_db?mode=offsync", "127.0.0.1:8080", "test_db", ModeOffsync, nil},
{"openmldb://127.0.0.1:8080/test_db?mode=unknown", "127.0.0.1:8080", "test_db", "", errors.New("")},
} {
host, db, mode, err := parseDsn(tc.dsn)
if tc.err == nil {
assert.NoError(t, err)
assert.Equal(t, host, tc.host)
assert.Equal(t, db, tc.db)
assert.Equal(t, mode, tc.mode)
} else {
assert.Error(t, err)
}
}
}