48 lines
1.1 KiB
Go
48 lines
1.1 KiB
Go
package config
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestLoadDefaults(t *testing.T) {
|
|
t.Setenv("STORAGE_ROOT", "")
|
|
t.Setenv("RABBITMQ_URL", "")
|
|
t.Setenv("STATUS_QUEUE", "")
|
|
|
|
cfg := Load()
|
|
if cfg.StorageRoot != "/data/storage" {
|
|
t.Fatalf("StorageRoot: got %q", cfg.StorageRoot)
|
|
}
|
|
if cfg.StatusQueue != "pipeline.status" {
|
|
t.Fatalf("StatusQueue: got %q", cfg.StatusQueue)
|
|
}
|
|
if cfg.PollInterval != 5*time.Second {
|
|
t.Fatalf("PollInterval: got %v", cfg.PollInterval)
|
|
}
|
|
if cfg.StableChecks != 3 {
|
|
t.Fatalf("StableChecks: got %d", cfg.StableChecks)
|
|
}
|
|
}
|
|
|
|
func TestLoadFromEnv(t *testing.T) {
|
|
t.Setenv("STORAGE_ROOT", "/tmp/storage")
|
|
t.Setenv("POLL_INTERVAL", "10s")
|
|
t.Setenv("STABLE_CHECKS", "5")
|
|
t.Setenv("STATUS_QUEUE", "custom.status")
|
|
|
|
cfg := Load()
|
|
if cfg.StorageRoot != "/tmp/storage" {
|
|
t.Fatalf("StorageRoot: got %q", cfg.StorageRoot)
|
|
}
|
|
if cfg.PollInterval != 10*time.Second {
|
|
t.Fatalf("PollInterval: got %v", cfg.PollInterval)
|
|
}
|
|
if cfg.StableChecks != 5 {
|
|
t.Fatalf("StableChecks: got %d", cfg.StableChecks)
|
|
}
|
|
if cfg.StatusQueue != "custom.status" {
|
|
t.Fatalf("StatusQueue: got %q", cfg.StatusQueue)
|
|
}
|
|
}
|