- 5 komandi: run, status, next, verify, history - Config proširen sa KAOS_TASKS_DIR - Tabelarni status sa emoji ikonama - run: scan → find → move → run → verify → report → review - 8 CLI testova, 59 ukupno — svi prolaze - T05 premešten u done/ Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
123 lines
2.9 KiB
Go
123 lines
2.9 KiB
Go
// Package config tests verify configuration loading from
|
|
// environment variables and .env files.
|
|
package config
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestLoad_WithValidEnv(t *testing.T) {
|
|
t.Setenv("KAOS_TIMEOUT", "30m")
|
|
t.Setenv("KAOS_PROJECT_PATH", "/tmp/test")
|
|
t.Setenv("KAOS_TASKS_DIR", "/tmp/tasks")
|
|
|
|
cfg, err := Load()
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
|
|
if cfg.Timeout != 30*time.Minute {
|
|
t.Errorf("expected timeout 30m, got %v", cfg.Timeout)
|
|
}
|
|
|
|
if cfg.ProjectPath != "/tmp/test" {
|
|
t.Errorf("expected project path /tmp/test, got %s", cfg.ProjectPath)
|
|
}
|
|
|
|
if cfg.TasksDir != "/tmp/tasks" {
|
|
t.Errorf("expected tasks dir /tmp/tasks, got %s", cfg.TasksDir)
|
|
}
|
|
}
|
|
|
|
func TestLoad_MissingTimeout(t *testing.T) {
|
|
t.Setenv("KAOS_TIMEOUT", "")
|
|
t.Setenv("KAOS_PROJECT_PATH", "/tmp/test")
|
|
t.Setenv("KAOS_TASKS_DIR", "/tmp/tasks")
|
|
|
|
_, err := Load()
|
|
if err == nil {
|
|
t.Fatal("expected error for missing KAOS_TIMEOUT")
|
|
}
|
|
}
|
|
|
|
func TestLoad_InvalidTimeout(t *testing.T) {
|
|
t.Setenv("KAOS_TIMEOUT", "not-a-duration")
|
|
t.Setenv("KAOS_PROJECT_PATH", "/tmp/test")
|
|
t.Setenv("KAOS_TASKS_DIR", "/tmp/tasks")
|
|
|
|
_, err := Load()
|
|
if err == nil {
|
|
t.Fatal("expected error for invalid KAOS_TIMEOUT")
|
|
}
|
|
}
|
|
|
|
func TestLoad_MissingProjectPath(t *testing.T) {
|
|
t.Setenv("KAOS_TIMEOUT", "30m")
|
|
t.Setenv("KAOS_PROJECT_PATH", "")
|
|
t.Setenv("KAOS_TASKS_DIR", "/tmp/tasks")
|
|
|
|
_, err := Load()
|
|
if err == nil {
|
|
t.Fatal("expected error for missing KAOS_PROJECT_PATH")
|
|
}
|
|
}
|
|
|
|
func TestLoad_MissingTasksDir(t *testing.T) {
|
|
t.Setenv("KAOS_TIMEOUT", "30m")
|
|
t.Setenv("KAOS_PROJECT_PATH", "/tmp/test")
|
|
t.Setenv("KAOS_TASKS_DIR", "")
|
|
|
|
_, err := Load()
|
|
if err == nil {
|
|
t.Fatal("expected error for missing KAOS_TASKS_DIR")
|
|
}
|
|
}
|
|
|
|
func TestLoadEnvFile(t *testing.T) {
|
|
dir := t.TempDir()
|
|
envPath := filepath.Join(dir, ".env")
|
|
|
|
content := "TEST_KAOS_VAR=hello\n# comment\nTEST_KAOS_OTHER=world\n"
|
|
if err := os.WriteFile(envPath, []byte(content), 0644); err != nil {
|
|
t.Fatalf("failed to write .env: %v", err)
|
|
}
|
|
|
|
// Ensure vars are not set
|
|
os.Unsetenv("TEST_KAOS_VAR")
|
|
os.Unsetenv("TEST_KAOS_OTHER")
|
|
|
|
loadEnvFile(envPath)
|
|
|
|
if v := os.Getenv("TEST_KAOS_VAR"); v != "hello" {
|
|
t.Errorf("expected TEST_KAOS_VAR=hello, got %q", v)
|
|
}
|
|
if v := os.Getenv("TEST_KAOS_OTHER"); v != "world" {
|
|
t.Errorf("expected TEST_KAOS_OTHER=world, got %q", v)
|
|
}
|
|
|
|
// Cleanup
|
|
os.Unsetenv("TEST_KAOS_VAR")
|
|
os.Unsetenv("TEST_KAOS_OTHER")
|
|
}
|
|
|
|
func TestLoadEnvFile_DoesNotOverride(t *testing.T) {
|
|
dir := t.TempDir()
|
|
envPath := filepath.Join(dir, ".env")
|
|
|
|
content := "TEST_KAOS_EXISTING=from_file\n"
|
|
if err := os.WriteFile(envPath, []byte(content), 0644); err != nil {
|
|
t.Fatalf("failed to write .env: %v", err)
|
|
}
|
|
|
|
t.Setenv("TEST_KAOS_EXISTING", "from_env")
|
|
|
|
loadEnvFile(envPath)
|
|
|
|
if v := os.Getenv("TEST_KAOS_EXISTING"); v != "from_env" {
|
|
t.Errorf("expected TEST_KAOS_EXISTING=from_env, got %q", v)
|
|
}
|
|
}
|