diff options
author | Niall Sheridan <nsheridan@gmail.com> | 2016-07-29 00:59:48 +0100 |
---|---|---|
committer | Niall Sheridan <nsheridan@gmail.com> | 2016-07-31 22:09:59 +0100 |
commit | 04aeda21e0ad2f7e8dd2bad3328e6ce0ba38f6a9 (patch) | |
tree | 3da48edf177826aeaae69447fd1fb001e873c43a /server/store/config_test.go | |
parent | 531f63e5a9e82d86a6ee1f5d44bebee0bc51d828 (diff) |
Support mongo datastores
Diffstat (limited to 'server/store/config_test.go')
-rw-r--r-- | server/store/config_test.go | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/server/store/config_test.go b/server/store/config_test.go new file mode 100644 index 0000000..8e283f5 --- /dev/null +++ b/server/store/config_test.go @@ -0,0 +1,68 @@ +package store + +import ( + "reflect" + "testing" + "time" + + mgo "gopkg.in/mgo.v2" +) + +func TestMySQLConfig(t *testing.T) { + var tests = []struct { + in string + out string + }{ + {"mysql:user:passwd:localhost", "user:passwd@tcp(localhost:3306)/certs?parseTime=true"}, + {"mysql:user:passwd:localhost:13306", "user:passwd@tcp(localhost:13306)/certs?parseTime=true"}, + {"mysql:root::localhost", "root@tcp(localhost:3306)/certs?parseTime=true"}, + } + for _, tt := range tests { + result := parseMySQLConfig(tt.in) + if result != tt.out { + t.Errorf("want %s, got %s", tt.out, result) + } + } +} + +func TestMongoConfig(t *testing.T) { + 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) + } + } +} |