handle Loader.Load return value error

This commit is contained in:
Allenxuxu
2020-01-19 16:31:02 +08:00
parent 1983d607f3
commit a82fd19209
3 changed files with 25 additions and 11 deletions

View File

@@ -55,7 +55,10 @@ func TestConfigLoadWithGoodFile(t *testing.T) {
}()
// Create new config
conf := NewConfig()
conf, err := NewConfig()
if err != nil {
t.Fatalf("Expected no error but got %v", err)
}
// Load file source
if err := conf.Load(file.NewSource(
file.WithPath(path),
@@ -73,9 +76,12 @@ func TestConfigLoadWithInvalidFile(t *testing.T) {
}()
// Create new config
conf := NewConfig()
conf, err := NewConfig()
if err != nil {
t.Fatalf("Expected no error but got %v", err)
}
// Load file source
err := conf.Load(file.NewSource(
err = conf.Load(file.NewSource(
file.WithPath(path),
file.WithPath("/i/do/not/exists.json"),
))
@@ -105,13 +111,18 @@ func TestConfigMerge(t *testing.T) {
}()
os.Setenv("AMQP_HOST", "rabbit.testing.com")
conf := NewConfig()
conf.Load(
conf, err := NewConfig()
if err != nil {
t.Fatalf("Expected no error but got %v", err)
}
if err := conf.Load(
file.NewSource(
file.WithPath(path),
),
env.NewSource(),
)
); err != nil {
t.Fatalf("Expected no error but got %v", err)
}
actualHost := conf.Get("amqp", "host").String("backup")
if actualHost != "rabbit.testing.com" {