mirror of
https://github.com/tiennm99/keepalive.git
synced 2026-10-17 08:14:36 +00:00
feat(config): support multi-service yaml config
This commit is contained in:
1 parent
655db8dcbf
commit
f3a23ee91e
19 files changed
+709
-268
No files matched your search
@@ -0,0 +1,48 @@
|
||||
package adapter
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestConfigRequiredReturnsConfiguredValue(t *testing.T) {
|
||||
cfg := Config{"url": "redis://127.0.0.1:6379"}
|
||||
|
||||
got, err := cfg.Required("url")
|
||||
if err != nil {
|
||||
t.Fatalf("Required returned error: %v", err)
|
||||
}
|
||||
if got != "redis://127.0.0.1:6379" {
|
||||
t.Fatalf("Required() = %q, want configured value", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigRequiredReportsMissingName(t *testing.T) {
|
||||
cfg := Config{}
|
||||
|
||||
_, err := cfg.Required("url")
|
||||
if err == nil {
|
||||
t.Fatal("Required returned nil error")
|
||||
}
|
||||
if !strings.Contains(err.Error(), "url") {
|
||||
t.Fatalf("error %q does not include config key", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigOptionalReturnsConfiguredValue(t *testing.T) {
|
||||
cfg := Config{"counter_key": "custom"}
|
||||
|
||||
got := cfg.Optional("counter_key", "counter")
|
||||
if got != "custom" {
|
||||
t.Fatalf("Optional() = %q, want custom", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigOptionalUsesDefault(t *testing.T) {
|
||||
cfg := Config{}
|
||||
|
||||
got := cfg.Optional("counter_key", "counter")
|
||||
if got != "counter" {
|
||||
t.Fatalf("Optional() = %q, want counter", got)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user