add config_test.go

This commit is contained in:
Jakob Schrettenbrunner
2017-06-26 21:04:11 +02:00
parent 7055f0c9b2
commit 90e81d89eb
3 changed files with 24 additions and 5 deletions

View File

@@ -77,10 +77,14 @@ type Config struct {
var config *Config
// LoadConfiguration loads the configuration from the disk.
func LoadConfiguration() error {
viper.SetConfigName("config")
viper.AddConfigPath(".")
func LoadConfiguration(path *string) error {
if path != nil {
viper.SetConfigFile(*path)
} else {
viper.AddConfigPath("./")
viper.SetConfigName("config")
}
// Find and read the config file
if err := viper.ReadInConfig(); err != nil {
return err

15
config/config_test.go Normal file
View File

@@ -0,0 +1,15 @@
package config
import (
"testing"
"github.com/stretchr/testify/assert"
)
var configFile = "../config.example.json"
func TestLoadConfiguraiton(t *testing.T) {
err := LoadConfiguration(&configFile)
assert.Nil(t, err)
assert.Equal(t, Get().Web.ListenHost, "0.0.0.0")
}