mirror of
https://github.com/ollama/ollama.git
synced 2026-04-18 03:54:12 +02:00
106 lines
2.5 KiB
Go
106 lines
2.5 KiB
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"runtime"
|
|
"slices"
|
|
"testing"
|
|
)
|
|
|
|
func TestClaudeIntegration(t *testing.T) {
|
|
c := &Claude{}
|
|
|
|
t.Run("String", func(t *testing.T) {
|
|
if got := c.String(); got != "Claude Code" {
|
|
t.Errorf("String() = %q, want %q", got, "Claude Code")
|
|
}
|
|
})
|
|
|
|
t.Run("implements Runner", func(t *testing.T) {
|
|
var _ Runner = c
|
|
})
|
|
}
|
|
|
|
func TestClaudeFindPath(t *testing.T) {
|
|
c := &Claude{}
|
|
|
|
t.Run("finds claude in PATH", func(t *testing.T) {
|
|
tmpDir := t.TempDir()
|
|
name := "claude"
|
|
if runtime.GOOS == "windows" {
|
|
name = "claude.exe"
|
|
}
|
|
fakeBin := filepath.Join(tmpDir, name)
|
|
os.WriteFile(fakeBin, []byte("#!/bin/sh\n"), 0o755)
|
|
t.Setenv("PATH", tmpDir)
|
|
|
|
got, err := c.findPath()
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
if got != fakeBin {
|
|
t.Errorf("findPath() = %q, want %q", got, fakeBin)
|
|
}
|
|
})
|
|
|
|
t.Run("falls back to ~/.claude/local/claude", func(t *testing.T) {
|
|
tmpDir := t.TempDir()
|
|
setTestHome(t, tmpDir)
|
|
t.Setenv("PATH", t.TempDir()) // empty dir, no claude binary
|
|
|
|
name := "claude"
|
|
if runtime.GOOS == "windows" {
|
|
name = "claude.exe"
|
|
}
|
|
fallback := filepath.Join(tmpDir, ".claude", "local", name)
|
|
os.MkdirAll(filepath.Dir(fallback), 0o755)
|
|
os.WriteFile(fallback, []byte("#!/bin/sh\n"), 0o755)
|
|
|
|
got, err := c.findPath()
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
if got != fallback {
|
|
t.Errorf("findPath() = %q, want %q", got, fallback)
|
|
}
|
|
})
|
|
|
|
t.Run("returns error when neither PATH nor fallback exists", func(t *testing.T) {
|
|
tmpDir := t.TempDir()
|
|
setTestHome(t, tmpDir)
|
|
t.Setenv("PATH", t.TempDir()) // empty dir, no claude binary
|
|
|
|
_, err := c.findPath()
|
|
if err == nil {
|
|
t.Fatal("expected error, got nil")
|
|
}
|
|
})
|
|
}
|
|
|
|
func TestClaudeArgs(t *testing.T) {
|
|
c := &Claude{}
|
|
|
|
tests := []struct {
|
|
name string
|
|
model string
|
|
args []string
|
|
want []string
|
|
}{
|
|
{"with model", "llama3.2", nil, []string{"--model", "llama3.2"}},
|
|
{"empty model", "", nil, nil},
|
|
{"with model and verbose", "llama3.2", []string{"--verbose"}, []string{"--model", "llama3.2", "--verbose"}},
|
|
{"empty model with help", "", []string{"--help"}, []string{"--help"}},
|
|
{"with allowed tools", "llama3.2", []string{"--allowedTools", "Read,Write,Bash"}, []string{"--model", "llama3.2", "--allowedTools", "Read,Write,Bash"}},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got := c.args(tt.model, tt.args)
|
|
if !slices.Equal(got, tt.want) {
|
|
t.Errorf("args(%q, %v) = %v, want %v", tt.model, tt.args, got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|