Files

31 lines
793 B
Go

package crossos
import (
"path/filepath"
"testing"
)
func TestConfigPath(t *testing.T) {
base := filepath.Join("home", "ops")
got := ConfigPath(base, "monitor")
want := filepath.Join(base, "monitor", "config.yaml")
if got != want {
t.Fatalf("got %q, want %q", got, want)
}
}
func TestEnvOrDefault(t *testing.T) {
env := map[string]string{"LOG_LEVEL": "debug", "EMPTY": " "}
lookup := func(k string) (string, bool) { v, ok := env[k]; return v, ok }
if got := EnvOrDefault(lookup, "LOG_LEVEL", "info"); got != "debug" {
t.Fatalf("got %q, want debug", got)
}
if got := EnvOrDefault(lookup, "EMPTY", "info"); got != "info" {
t.Fatalf("got %q, want info", got)
}
if got := EnvOrDefault(lookup, "MISSING", "info"); got != "info" {
t.Fatalf("got %q, want info", got)
}
}