-
Notifications
You must be signed in to change notification settings - Fork 141
Expand file tree
/
Copy pathutils_test.go
More file actions
114 lines (107 loc) · 2.78 KB
/
Copy pathutils_test.go
File metadata and controls
114 lines (107 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package commands
import (
"errors"
"fmt"
"testing"
)
func TestStripDefaultsFromModelName(t *testing.T) {
tests := []struct {
name string
input string
expected string
}{
{
name: "ai prefix and latest tag",
input: "ai/gemma3:latest",
expected: "gemma3",
},
{
name: "ai prefix with custom tag",
input: "ai/gemma3:v1",
expected: "gemma3:v1",
},
{
name: "custom org with latest tag",
input: "myorg/gemma3:latest",
expected: "myorg/gemma3",
},
{
name: "simple model name with latest",
input: "gemma3:latest",
expected: "gemma3",
},
{
name: "simple model name without tag",
input: "gemma3",
expected: "gemma3",
},
{
name: "ai prefix without tag",
input: "ai/gemma3",
expected: "gemma3",
},
{
name: "huggingface model with latest",
input: "hf.co/bartowski/model:latest",
expected: "hf.co/bartowski/model",
},
{
name: "huggingface model with custom tag",
input: "hf.co/bartowski/model:Q4_K_S",
expected: "hf.co/bartowski/model:Q4_K_S",
},
{
name: "empty string",
input: "",
expected: "",
},
{
name: "docker.io registry with ai prefix and latest tag",
input: "docker.io/ai/gemma3:latest",
expected: "gemma3",
},
{
name: "index.docker.io registry with ai prefix and latest tag",
input: "index.docker.io/ai/gemma3:latest",
expected: "gemma3",
},
{
name: "docker.io registry with ai prefix and custom tag",
input: "docker.io/ai/gemma3:v1",
expected: "gemma3:v1",
},
{
name: "docker.io registry with custom org and latest tag",
input: "docker.io/myorg/gemma3:latest",
expected: "myorg/gemma3",
},
{
name: "index.docker.io registry with custom org and latest tag",
input: "index.docker.io/myorg/gemma3:latest",
expected: "myorg/gemma3",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := stripDefaultsFromModelName(tt.input)
if result != tt.expected {
t.Errorf("stripDefaultsFromModelName(%q) = %q, want %q", tt.input, result, tt.expected)
}
})
}
}
// TestHandleClientErrorFormat verifies that the error format follows the expected pattern.
func TestHandleClientErrorFormat(t *testing.T) {
t.Run("error format is message: original error", func(t *testing.T) {
originalErr := fmt.Errorf("network timeout")
message := "Failed to fetch data"
result := handleClientError(originalErr, message)
expected := fmt.Errorf("%s: %w", message, originalErr).Error()
if result.Error() != expected {
t.Errorf("Error format mismatch.\nExpected: %q\nGot: %q", expected, result.Error())
}
if !errors.Is(result, originalErr) {
t.Error("Error wrapping is not preserved - errors.Is() check failed")
}
})
}