aboutsummaryrefslogtreecommitdiff
path: root/server/store/config_test.go
blob: 9a77027d45df10e935e9fb2808233bef0abde75d (plain)
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
package store

import (
	"reflect"
	"testing"
	"time"

	mgo "gopkg.in/mgo.v2"
)

func TestMySQLConfig(t *testing.T) {
	t.Parallel()
	var tests = []struct {
		in  string
		out []string
	}{
		{"mysql:user:passwd:localhost", []string{"mysql", "user:passwd@tcp(localhost:3306)/certs?parseTime=true"}},
		{"mysql:user:passwd:localhost:13306", []string{"mysql", "user:passwd@tcp(localhost:13306)/certs?parseTime=true"}},
		{"mysql:root::localhost", []string{"mysql", "root@tcp(localhost:3306)/certs?parseTime=true"}},
	}
	for _, tt := range tests {
		result := parse(tt.in)
		if !reflect.DeepEqual(result, tt.out) {
			t.Errorf("want %s, got %s", tt.out, result)
		}
	}
}

func TestMongoConfig(t *testing.T) {
	t.Parallel()
	var tests = []struct {
		in  string
		out *mgo.DialInfo
	}{
		{"mongo:user:passwd:host", &mgo.DialInfo{
			Username: "user",
			Password: "passwd",
			Addrs:    []string{"host"},
			Database: "certs",
			Timeout:  5 * time.Second,
		}},
		{"mongo:user:passwd:host1,host2", &mgo.DialInfo{
			Username: "user",
			Password: "passwd",
			Addrs:    []string{"host1", "host2"},
			Database: "certs",
			Timeout:  5 * time.Second,
		}},
		{"mongo:user:passwd:host1:27017,host2:27017", &mgo.DialInfo{
			Username: "user",
			Password: "passwd",
			Addrs:    []string{"host1:27017", "host2:27017"},
			Database: "certs",
			Timeout:  5 * time.Second,
		}},
		{"mongo:user:passwd:host1,host2:27017", &mgo.DialInfo{
			Username: "user",
			Password: "passwd",
			Addrs:    []string{"host1", "host2:27017"},
			Database: "certs",
			Timeout:  5 * time.Second,
		}},
	}
	for _, tt := range tests {
		result := parseMongoConfig(tt.in)
		if !reflect.DeepEqual(result, tt.out) {
			t.Errorf("want:\n%+v\ngot:\n%+v", tt.out, result)
		}
	}
}