package bellconfig import "testing" func TestLoadRequiresIndependentDatabaseAndSecret(t *testing.T) { for _, values := range []map[string]string{ {}, {DatabaseURLEnv: "postgres://bell@localhost/bell"}, {DatabaseURLEnv: "postgres://bell@localhost/bell", JWTSecretEnv: "go-admin"}, {DatabaseURLEnv: "postgres://bell@localhost/bell", JWTSecretEnv: "too-short"}, } { _, err := Load(func(key string) string { return values[key] }) if err == nil { t.Fatalf("Load(%v) unexpectedly succeeded", values) } } } func TestLoadAcceptsExactBellOverrides(t *testing.T) { values := map[string]string{ DatabaseURLEnv: "postgres://bell@localhost/bell", JWTSecretEnv: "bell-test-secret-with-at-least-32-characters", "BELL_HOST": "127.0.0.2", "BELL_PORT": "18091", } env, err := Load(func(key string) string { return values[key] }) if err != nil { t.Fatal(err) } if env.Host != "127.0.0.2" || env.Port != 18091 { t.Fatalf("unexpected listen override: %#v", env) } }