55 lines
2.1 KiB
Go
55 lines
2.1 KiB
Go
package config
|
|
|
|
import "testing"
|
|
|
|
func TestLoadUsesDefaults(t *testing.T) {
|
|
t.Setenv("RUN_MODE", "")
|
|
t.Setenv("RUN_PLATFORM_URL", "")
|
|
|
|
cfg := Load()
|
|
if cfg.Mode != DefaultMode {
|
|
t.Fatalf("expected mode %q, got %q", DefaultMode, cfg.Mode)
|
|
}
|
|
if cfg.PlatformURL != DefaultPlatformURL {
|
|
t.Fatalf("expected platform URL %q, got %q", DefaultPlatformURL, cfg.PlatformURL)
|
|
}
|
|
if cfg.RunEndpointID != DefaultEndpointID || cfg.DisplayName != DefaultDisplayName || cfg.Version != DefaultVersion {
|
|
t.Fatalf("expected worker defaults, got %+v", cfg)
|
|
}
|
|
if cfg.MaxJobs != 1 || cfg.HeartbeatInterval <= 0 || cfg.PollInterval <= 0 || cfg.RetryBackoff <= 0 {
|
|
t.Fatalf("expected positive worker scheduling defaults, got %+v", cfg)
|
|
}
|
|
}
|
|
|
|
func TestLoadUsesEnvironment(t *testing.T) {
|
|
t.Setenv("RUN_MODE", "worker")
|
|
t.Setenv("RUN_PLATFORM_URL", "http://platform.test")
|
|
t.Setenv("RUN_ENDPOINT_ID", "run-edge")
|
|
t.Setenv("RUN_DISPLAY_NAME", "Edge Run")
|
|
t.Setenv("RUN_VERSION", "1.2.3")
|
|
t.Setenv("RUN_REGISTRATION_TOKEN", "registration-token")
|
|
t.Setenv("RUN_WORKSPACE_ROOT", "/tmp/run-workspace")
|
|
t.Setenv("RUN_SPOOL_ROOT", "/tmp/run-spool")
|
|
t.Setenv("RUN_MAX_JOBS", "3")
|
|
t.Setenv("RUN_HEARTBEAT_INTERVAL_MS", "250")
|
|
t.Setenv("RUN_POLL_INTERVAL_MS", "125")
|
|
t.Setenv("RUN_RETRY_BACKOFF_MS", "75")
|
|
|
|
cfg := Load()
|
|
if cfg.Mode != "worker" {
|
|
t.Fatalf("expected configured mode, got %q", cfg.Mode)
|
|
}
|
|
if cfg.PlatformURL != "http://platform.test" {
|
|
t.Fatalf("expected configured platform URL, got %q", cfg.PlatformURL)
|
|
}
|
|
if cfg.RunEndpointID != "run-edge" || cfg.DisplayName != "Edge Run" || cfg.Version != "1.2.3" || cfg.RegistrationToken != "registration-token" {
|
|
t.Fatalf("expected configured worker identity, got %+v", cfg)
|
|
}
|
|
if cfg.WorkspaceRoot != "/tmp/run-workspace" || cfg.SpoolRoot != "/tmp/run-spool" || cfg.MaxJobs != 3 {
|
|
t.Fatalf("expected configured worker paths/capacity, got %+v", cfg)
|
|
}
|
|
if cfg.HeartbeatInterval.Milliseconds() != 250 || cfg.PollInterval.Milliseconds() != 125 || cfg.RetryBackoff.Milliseconds() != 75 {
|
|
t.Fatalf("expected configured durations, got %+v", cfg)
|
|
}
|
|
}
|