config.go: rename parseConfig to configParse

This commit is contained in:
Adhityaa Chandrasekar 2018-07-24 12:11:01 +05:30
parent 6ca442f9cc
commit b7b224983c
3 changed files with 15 additions and 15 deletions

View File

@ -6,7 +6,7 @@ import (
"strings" "strings"
) )
func parseConfig() error { func configParse() error {
binPath, err := filepath.Abs(filepath.Dir(os.Args[0])) binPath, err := filepath.Abs(filepath.Dir(os.Args[0]))
if err != nil { if err != nil {
logger.Errorf("cannot load binary path: %v", err) logger.Errorf("cannot load binary path: %v", err)

View File

@ -6,10 +6,10 @@ import (
"testing" "testing"
) )
func TestParseConfigBasics(t *testing.T) { func TestConfigParseBasics(t *testing.T) {
os.Setenv("COMMENTO_ORIGIN", "https://commento.io") os.Setenv("COMMENTO_ORIGIN", "https://commento.io")
if err := parseConfig(); err != nil { if err := configParse(); err != nil {
t.Errorf("unexpected error when parsing config: %v", err) t.Errorf("unexpected error when parsing config: %v", err)
return return
} }
@ -21,7 +21,7 @@ func TestParseConfigBasics(t *testing.T) {
os.Setenv("COMMENTO_BIND_ADDRESS", "192.168.1.100") os.Setenv("COMMENTO_BIND_ADDRESS", "192.168.1.100")
if err := parseConfig(); err != nil { if err := configParse(); err != nil {
t.Errorf("unexpected error when parsing config: %v", err) t.Errorf("unexpected error when parsing config: %v", err)
return return
} }
@ -39,7 +39,7 @@ func TestParseConfigBasics(t *testing.T) {
os.Setenv("COMMENTO_PORT", "1886") os.Setenv("COMMENTO_PORT", "1886")
if err := parseConfig(); err != nil { if err := configParse(); err != nil {
t.Errorf("unexpected error when parsing config: %v", err) t.Errorf("unexpected error when parsing config: %v", err)
return return
} }
@ -50,19 +50,19 @@ func TestParseConfigBasics(t *testing.T) {
} }
} }
func TestParseConfigNoOrigin(t *testing.T) { func TestConfigParseNoOrigin(t *testing.T) {
os.Setenv("COMMENTO_ORIGIN", "") os.Setenv("COMMENTO_ORIGIN", "")
if err := parseConfig(); err == nil { if err := configParse(); err == nil {
t.Errorf("expected error not found parsing config without ORIGIN") t.Errorf("expected error not found parsing config without ORIGIN")
return return
} }
} }
func TestParseConfigStatic(t *testing.T) { func TestConfigParseStatic(t *testing.T) {
os.Setenv("COMMENTO_ORIGIN", "https://commento.io") os.Setenv("COMMENTO_ORIGIN", "https://commento.io")
if err := parseConfig(); err != nil { if err := configParse(); err != nil {
t.Errorf("unexpected error when parsing config: %v", err) t.Errorf("unexpected error when parsing config: %v", err)
return return
} }
@ -80,7 +80,7 @@ func TestParseConfigStatic(t *testing.T) {
os.Setenv("COMMENTO_STATIC", "/usr/") os.Setenv("COMMENTO_STATIC", "/usr/")
if err := parseConfig(); err != nil { if err := configParse(); err != nil {
t.Errorf("unexpected error when parsing config: %v", err) t.Errorf("unexpected error when parsing config: %v", err)
return return
} }
@ -91,21 +91,21 @@ func TestParseConfigStatic(t *testing.T) {
} }
} }
func TestParseConfigStaticDNE(t *testing.T) { func TestConfigParseStaticDNE(t *testing.T) {
os.Setenv("COMMENTO_ORIGIN", "https://commento.io") os.Setenv("COMMENTO_ORIGIN", "https://commento.io")
os.Setenv("COMMENTO_STATIC", "/does/not/exist/surely/") os.Setenv("COMMENTO_STATIC", "/does/not/exist/surely/")
if err := parseConfig(); err == nil { if err := configParse(); err == nil {
t.Errorf("expected error not found when a non-existant directory is used") t.Errorf("expected error not found when a non-existant directory is used")
return return
} }
} }
func TestParseConfigStaticNotADirectory(t *testing.T) { func TestConfigParseStaticNotADirectory(t *testing.T) {
os.Setenv("COMMENTO_ORIGIN", "https://commento.io") os.Setenv("COMMENTO_ORIGIN", "https://commento.io")
os.Setenv("COMMENTO_STATIC", os.Args[0]) os.Setenv("COMMENTO_STATIC", os.Args[0])
if err := parseConfig(); err != errorNotADirectory { if err := configParse(); err != errorNotADirectory {
t.Errorf("expected error not found when a file is used") t.Errorf("expected error not found when a file is used")
return return
} }

View File

@ -2,7 +2,7 @@ package main
func main() { func main() {
exitIfError(createLogger()) exitIfError(createLogger())
exitIfError(parseConfig()) exitIfError(configParse())
exitIfError(connectDB(5)) exitIfError(connectDB(5))
exitIfError(performMigrations()) exitIfError(performMigrations())
exitIfError(smtpConfigure()) exitIfError(smtpConfigure())