|
|
|
@ -24,6 +24,7 @@ func TestConfig_ReadConfig(t *testing.T){
|
|
|
|
|
"--title=title",
|
|
|
|
|
"--apikey=apikey",
|
|
|
|
|
"--domain=domain",
|
|
|
|
|
"--root=root"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
expected := &Config{
|
|
|
|
@ -33,6 +34,7 @@ func TestConfig_ReadConfig(t *testing.T){
|
|
|
|
|
Title: "title",
|
|
|
|
|
APIkey: "apikey",
|
|
|
|
|
Domain: "domain",
|
|
|
|
|
RootPath: "root",
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cfg, err := readConfig(flag.NewFlagSet("", flag.ContinueOnError), input)
|
|
|
|
@ -41,18 +43,20 @@ func TestConfig_ReadConfig(t *testing.T){
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestConfig_ReadConfigFromEnv(t *testing.T) {
|
|
|
|
|
assert.NoError(t, os.Setenv("SHRT_DB_FILE", "db"))
|
|
|
|
|
defer os.Unsetenv("SHRT_DB_FILE")
|
|
|
|
|
assert.NoError(t, os.Setenv("SHRT_API_KEY", "apikey"))
|
|
|
|
|
defer os.Unsetenv("SHRT_API_KEY")
|
|
|
|
|
assert.NoError(t, os.Setenv("SHRT_HOST", "host"))
|
|
|
|
|
defer os.Unsetenv("SHRT_HOST")
|
|
|
|
|
assert.NoError(t, os.Setenv("SHRT_PORT", "port"))
|
|
|
|
|
defer os.Unsetenv("SHRT_PORT")
|
|
|
|
|
assert.NoError(t, os.Setenv("SHRT_DOMAIN", "domain"))
|
|
|
|
|
defer os.Unsetenv("SHRT_DOMAIN")
|
|
|
|
|
assert.NoError(t, os.Setenv("SHRT_TITLE", "title"))
|
|
|
|
|
defer os.Unsetenv("SHRT_TITLE")
|
|
|
|
|
assert.NoError(t, os.Setenv("SHRTY_DB_FILE", "db"))
|
|
|
|
|
defer os.Unsetenv("SHRTY_DB_FILE")
|
|
|
|
|
assert.NoError(t, os.Setenv("SHRTY_API_KEY", "apikey"))
|
|
|
|
|
defer os.Unsetenv("SHRTY_API_KEY")
|
|
|
|
|
assert.NoError(t, os.Setenv("SHRTY_HOST", "host"))
|
|
|
|
|
defer os.Unsetenv("SHRTY_HOST")
|
|
|
|
|
assert.NoError(t, os.Setenv("SHRTY_PORT", "port"))
|
|
|
|
|
defer os.Unsetenv("SHRTY_PORT")
|
|
|
|
|
assert.NoError(t, os.Setenv("SHRTY_DOMAIN", "domain"))
|
|
|
|
|
defer os.Unsetenv("SHRTY_DOMAIN")
|
|
|
|
|
assert.NoError(t, os.Setenv("SHRTY_TITLE", "title"))
|
|
|
|
|
defer os.Unsetenv("SHRTY_TITLE")
|
|
|
|
|
assert.NoError(t, os.Setenv("SHRTY_ROOT_PATH", "root"))
|
|
|
|
|
defer os.Unsetenv("SHRTY_ROOT_PATH")
|
|
|
|
|
|
|
|
|
|
expected := &Config{
|
|
|
|
|
Host: "host",
|
|
|
|
@ -61,6 +65,7 @@ func TestConfig_ReadConfigFromEnv(t *testing.T) {
|
|
|
|
|
Title: "title",
|
|
|
|
|
APIkey: "apikey",
|
|
|
|
|
Domain: "domain",
|
|
|
|
|
RootPath: "root",
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cfg, err := readConfig(flag.NewFlagSet("", flag.ContinueOnError), []string{})
|
|
|
|
|