-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconnection_internal_test.go
More file actions
37 lines (34 loc) · 1.27 KB
/
connection_internal_test.go
File metadata and controls
37 lines (34 loc) · 1.27 KB
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
package sqlitecloud
import (
"reflect"
"strings"
"testing"
)
func TestConnectionCommandsAuthPreference(t *testing.T) {
tests := []struct {
name string
config SQCloudConfig
wantCmd string
wantArgs []interface{}
}{
{"api key wins", SQCloudConfig{ApiKey: "k", Token: "t", Username: "u", Password: "p"}, "AUTH APIKEY ?;", []interface{}{"k"}},
{"token next", SQCloudConfig{Token: "t", Username: "u", Password: "p"}, "AUTH TOKEN ?;", []interface{}{"t"}},
{"user/pass fallback", SQCloudConfig{Username: "u", Password: "p"}, "AUTH USER ? PASSWORD ?;", []interface{}{"u", "p"}},
{"hashed password", SQCloudConfig{Username: "u", Password: "hash", PasswordHashed: true}, "AUTH USER ? HASH ?;", []interface{}{"u", "hash"}},
{"no credentials", SQCloudConfig{}, "", []interface{}{}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotBuf, gotArgs := connectionCommands(tt.config)
if tt.wantCmd == "" && gotBuf != "" {
t.Fatalf("expected no auth command, got %q", gotBuf)
}
if tt.wantCmd != "" && !strings.Contains(gotBuf, tt.wantCmd) {
t.Fatalf("expected %q in buffer, got %q", tt.wantCmd, gotBuf)
}
if !reflect.DeepEqual(gotArgs, tt.wantArgs) {
t.Fatalf("args mismatch: want %v got %v", tt.wantArgs, gotArgs)
}
})
}
}