96 lines
2.5 KiB
Go
96 lines
2.5 KiB
Go
package config_test
|
|
|
|
import (
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"superwork-tui/internal/config"
|
|
)
|
|
|
|
func TestDefaultSettings(t *testing.T) {
|
|
s := config.DefaultSettings()
|
|
if s.WebhookPort != 17421 {
|
|
t.Errorf("WebhookPort: got %d, want 17421", s.WebhookPort)
|
|
}
|
|
if !s.AutoReview {
|
|
t.Error("AutoReview: want true")
|
|
}
|
|
if s.DevBranch != "main" {
|
|
t.Errorf("DevBranch: got %q, want main", s.DevBranch)
|
|
}
|
|
if s.ProfilesDir != "" {
|
|
t.Errorf("ProfilesDir: want empty, got %q", s.ProfilesDir)
|
|
}
|
|
}
|
|
|
|
func TestSaveLoadRoundtrip(t *testing.T) {
|
|
dir := t.TempDir()
|
|
path := filepath.Join(dir, "config.toml")
|
|
|
|
original := &config.Settings{
|
|
WebhookPort: 12345,
|
|
AutoReview: false,
|
|
DevBranch: "develop",
|
|
AutoBuildBranch: "ci",
|
|
ProfilesDir: "/some/path",
|
|
}
|
|
if err := config.SaveTo(path, original); err != nil {
|
|
t.Fatalf("SaveTo: %v", err)
|
|
}
|
|
loaded, err := config.LoadFrom(path)
|
|
if err != nil {
|
|
t.Fatalf("LoadFrom: %v", err)
|
|
}
|
|
if loaded.WebhookPort != original.WebhookPort {
|
|
t.Errorf("WebhookPort: got %d, want %d", loaded.WebhookPort, original.WebhookPort)
|
|
}
|
|
if loaded.AutoReview != original.AutoReview {
|
|
t.Errorf("AutoReview: got %v, want %v", loaded.AutoReview, original.AutoReview)
|
|
}
|
|
if loaded.DevBranch != original.DevBranch {
|
|
t.Errorf("DevBranch: got %q, want %q", loaded.DevBranch, original.DevBranch)
|
|
}
|
|
if loaded.ProfilesDir != original.ProfilesDir {
|
|
t.Errorf("ProfilesDir: got %q, want %q", loaded.ProfilesDir, original.ProfilesDir)
|
|
}
|
|
}
|
|
|
|
func TestSystemPromptCommandDefault(t *testing.T) {
|
|
s := config.DefaultSettings()
|
|
if s.SystemPromptCommand != "" {
|
|
t.Errorf("SystemPromptCommand: want empty, got %q", s.SystemPromptCommand)
|
|
}
|
|
}
|
|
|
|
func TestSystemPromptCommandRoundtrip(t *testing.T) {
|
|
dir := t.TempDir()
|
|
path := filepath.Join(dir, "config.toml")
|
|
|
|
original := &config.Settings{
|
|
WebhookPort: 12345,
|
|
SystemPromptCommand: "echo hello",
|
|
}
|
|
if err := config.SaveTo(path, original); err != nil {
|
|
t.Fatalf("SaveTo: %v", err)
|
|
}
|
|
loaded, err := config.LoadFrom(path)
|
|
if err != nil {
|
|
t.Fatalf("LoadFrom: %v", err)
|
|
}
|
|
if loaded.SystemPromptCommand != original.SystemPromptCommand {
|
|
t.Errorf("SystemPromptCommand: got %q, want %q", loaded.SystemPromptCommand, original.SystemPromptCommand)
|
|
}
|
|
}
|
|
|
|
func TestLoadMissingFile_ReturnsDefaults(t *testing.T) {
|
|
dir := t.TempDir()
|
|
path := filepath.Join(dir, "nonexistent.toml")
|
|
s, err := config.LoadFrom(path)
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
if s.WebhookPort != 17421 {
|
|
t.Errorf("WebhookPort: got %d, want 17421", s.WebhookPort)
|
|
}
|
|
}
|