hugin/cli/internal/tools/tools_test.go
2026-10-27 08:33:21 +01:00

44 lines
1,010 B
Go

package tools
import (
"os"
"path/filepath"
"slices"
"testing"
)
func TestLess(t *testing.T) {
tests := []struct {
a, b string
ok bool
}{
{"2.1.104", "2.1.105", true},
{"2.1.105", "2.1.105", false},
{"2.10.0", "2.9.9", false},
{"1.2.9", "1.2.11", true},
}
for _, tt := range tests {
if Less(tt.a, tt.b) != tt.ok {
t.Errorf("Kleiner(%s, %s) != %v", tt.a, tt.b, tt.ok)
}
}
}
func TestTarget(t *testing.T) {
for version, target := range map[string]string{"1.19.3": "opencode@1", "2.0.1": "opencode@2", "": "opencode@1"} {
if got := Target("opencode", version); got != target {
t.Errorf("Ziel(opencode, %q) = %s", version, got)
}
}
}
func TestInRepo(t *testing.T) {
repo := t.TempDir()
if got := InRepo(repo); !slices.Equal(got, []string{"claude", "opencode"}) {
t.Errorf("leeres Repo: %v", got)
}
os.WriteFile(filepath.Join(repo, "CLAUDE.md"), nil, 0o644)
if got := InRepo(repo); !slices.Equal(got, []string{"claude"}) {
t.Errorf("nur CLAUDE.md: %v", got)
}
}