diff --git a/config/default_test.go b/config/default_test.go new file mode 100644 index 0000000..35b4d4b --- /dev/null +++ b/config/default_test.go @@ -0,0 +1,40 @@ +package config + +import ( + "os" + "testing" + + envconfig "github.com/unistack-org/micro-config-env" + "github.com/unistack-org/micro/v3" + "github.com/unistack-org/micro/v3/config" +) + +type Config struct { + String string `env:"MICRO_TEST" default:"default"` +} + +func TestMultiple(t *testing.T) { + cfg := &Config{} + svc := micro.NewService(micro.Configs( + config.NewConfig(config.Struct(cfg)), + envconfig.NewConfig(config.Struct(cfg)), + ), + ) + if err := svc.Init(); err != nil { + t.Fatal(err) + } + if cfg.String != "default" { + t.Fatalf("config not parsed by default source: %#+v\n", cfg) + } + os.Setenv("MICRO_TEST", "non_default") + if err := svc.Init(); err != nil { + t.Fatal(err) + } + if cfg.String == "default" { + t.Fatalf("config not parsed by default source: %#+v\n", cfg) + } + if cfg.String != "non_default" { + t.Fatalf("config not parsed by default source: %#+v\n", cfg) + } + t.Logf("config: %#+v\n", cfg) +}