-
Notifications
You must be signed in to change notification settings - Fork 51
/
config_test.go
38 lines (32 loc) · 1.54 KB
/
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
package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestCreateDefaultConfig(t *testing.T) {
// serverConfig should be initialized by testsSetup function
if assert.NotNil(t, serverConfig, "server configuration is expected") {
assert.Equal(t, defaultDatabaseType, serverConfig.DbType, "wrong db type")
assert.Equal(t, defaultServicePort, serverConfig.ServerPort, "wrong server port")
assert.Equal(t, initBasketCapacity, serverConfig.InitCapacity, "wrong initial capacity")
assert.Equal(t, maxBasketCapacity, serverConfig.MaxCapacity, "wrong max capacity")
assert.Equal(t, defaultPageSize, serverConfig.PageSize, "wrong page size")
assert.Equal(t, "./baskets.db", serverConfig.DbFile, "wrong DB file location")
assert.NotEmpty(t, serverConfig.MasterToken, "expected randomly generated master token")
}
}
func TestArrayFlags(t *testing.T) {
var flags arrayFlags
flags.Set("123")
flags.Set("abc")
flags.Set("xyz")
flags.Set("abc")
assert.Equal(t, "123,abc,xyz,abc", flags.String(), "unexpected list of flags")
}
func TestNormalizePrefix(t *testing.T) {
assert.Empty(t, normalizePrefix(""), "expected empty prefix after normalization")
assert.Equal(t, "/xyz", normalizePrefix("/xyz"), "unexpected result of normalization")
assert.Equal(t, "/abc", normalizePrefix("abc"), "unexpected result of normalization")
assert.Equal(t, "/services/baskets", normalizePrefix("services/baskets"), "unexpected result of normalization")
assert.Equal(t, "/abc/def/ghi", normalizePrefix("/abc/def/ghi"), "unexpected result of normalization")
}