add config_test.go
This commit is contained in:
parent
7055f0c9b2
commit
90e81d89eb
|
@ -77,10 +77,14 @@ type Config struct {
|
||||||
|
|
||||||
var config *Config
|
var config *Config
|
||||||
|
|
||||||
// LoadConfiguration loads the configuration from the disk.
|
func LoadConfiguration(path *string) error {
|
||||||
func LoadConfiguration() error {
|
if path != nil {
|
||||||
|
viper.SetConfigFile(*path)
|
||||||
|
} else {
|
||||||
|
viper.AddConfigPath("./")
|
||||||
viper.SetConfigName("config")
|
viper.SetConfigName("config")
|
||||||
viper.AddConfigPath(".")
|
}
|
||||||
|
|
||||||
// Find and read the config file
|
// Find and read the config file
|
||||||
if err := viper.ReadInConfig(); err != nil {
|
if err := viper.ReadInConfig(); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
15
config/config_test.go
Normal file
15
config/config_test.go
Normal 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")
|
||||||
|
}
|
2
main.go
2
main.go
|
@ -16,7 +16,7 @@ const (
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
fmt.Println("Loading configuration")
|
fmt.Println("Loading configuration")
|
||||||
if err := config.LoadConfiguration(); err != nil {
|
if err := config.LoadConfiguration(nil); err != nil {
|
||||||
log.WithError(err).Fatal("Failed to find configuration file")
|
log.WithError(err).Fatal("Failed to find configuration file")
|
||||||
}
|
}
|
||||||
tools.ConfigureLogging()
|
tools.ConfigureLogging()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user