|
|
|
@ -1,6 +1,7 @@ |
|
|
|
package common |
|
|
|
|
|
|
|
import ( |
|
|
|
"errors" |
|
|
|
"os" |
|
|
|
"testing" |
|
|
|
|
|
|
|
@ -15,3 +16,40 @@ func TestLoadFromEnv(t *testing.T) { |
|
|
|
loadFromEnv("T", &ms) |
|
|
|
assert.Equal(t, "d1", ms.Driver) |
|
|
|
} |
|
|
|
|
|
|
|
func TestCheckConfig(t *testing.T) { |
|
|
|
config := &Config |
|
|
|
retryIntervalErr := checkConfig() |
|
|
|
retryIntervalExpect := errors.New("RetryInterval should not be less than 10") |
|
|
|
assert.Equal(t,retryIntervalErr,retryIntervalExpect) |
|
|
|
|
|
|
|
config.RetryInterval = 10 |
|
|
|
timeoutToFailErr := checkConfig() |
|
|
|
timeoutToFailExpect := errors.New("TimeoutToFail should not be less than RetryInterval") |
|
|
|
assert.Equal(t,timeoutToFailErr,timeoutToFailExpect) |
|
|
|
|
|
|
|
config.TimeoutToFail = 20 |
|
|
|
driverErr := checkConfig() |
|
|
|
assert.Equal(t,driverErr,nil) |
|
|
|
|
|
|
|
config.Store = Store{Driver: Mysql} |
|
|
|
hostErr := checkConfig() |
|
|
|
hostExpect := errors.New("Db host not valid ") |
|
|
|
assert.Equal(t,hostErr,hostExpect) |
|
|
|
|
|
|
|
config.Store = Store{Driver: Mysql,Host: "127.0.0.1"} |
|
|
|
portErr := checkConfig() |
|
|
|
portExpect := errors.New("Db port not valid ") |
|
|
|
assert.Equal(t,portErr,portExpect) |
|
|
|
|
|
|
|
config.Store = Store{Driver: Mysql,Host: "127.0.0.1",Port: 8686} |
|
|
|
userErr := checkConfig() |
|
|
|
userExpect := errors.New("Db user not valid ") |
|
|
|
assert.Equal(t,userErr,userExpect) |
|
|
|
|
|
|
|
config.Store = Store{Driver: Mysql,Host: "127.0.0.1",Port: 8686,User: "test"} |
|
|
|
passwordErr := checkConfig() |
|
|
|
passwordExpect := errors.New("Db password not valid ") |
|
|
|
assert.Equal(t,passwordErr,passwordExpect) |
|
|
|
|
|
|
|
} |
|
|
|
|