@@ -4,88 +4,8 @@ import (
44 "errors"
55 "fmt"
66 "testing"
7-
8- "github.com/docker/model-runner/pkg/inference/models"
97)
108
11- func TestNormalizeModelName (t * testing.T ) {
12- tests := []struct {
13- name string
14- input string
15- expected string
16- }{
17- {
18- name : "simple model name" ,
19- input : "gemma3" ,
20- expected : "ai/gemma3:latest" ,
21- },
22- {
23- name : "model name with tag" ,
24- input : "gemma3:v1" ,
25- expected : "ai/gemma3:v1" ,
26- },
27- {
28- name : "model name with org" ,
29- input : "myorg/gemma3" ,
30- expected : "myorg/gemma3:latest" ,
31- },
32- {
33- name : "model name with org and tag" ,
34- input : "myorg/gemma3:v1" ,
35- expected : "myorg/gemma3:v1" ,
36- },
37- {
38- name : "fully qualified model name" ,
39- input : "ai/gemma3:latest" ,
40- expected : "ai/gemma3:latest" ,
41- },
42- {
43- name : "huggingface model" ,
44- input : "hf.co/bartowski/model" ,
45- expected : "huggingface.co/bartowski/model:latest" ,
46- },
47- {
48- name : "huggingface model with tag" ,
49- input : "hf.co/bartowski/model:Q4_K_S" ,
50- expected : "huggingface.co/bartowski/model:q4_k_s" ,
51- },
52- {
53- name : "registry with model" ,
54- input : "docker.io/library/model" ,
55- expected : "docker.io/library/model:latest" ,
56- },
57- {
58- name : "registry with model and tag" ,
59- input : "docker.io/library/model:v1" ,
60- expected : "docker.io/library/model:v1" ,
61- },
62- {
63- name : "empty string" ,
64- input : "" ,
65- expected : "" ,
66- },
67- {
68- name : "ai prefix already present" ,
69- input : "ai/gemma3" ,
70- expected : "ai/gemma3:latest" ,
71- },
72- {
73- name : "model name with latest tag already" ,
74- input : "gemma3:latest" ,
75- expected : "ai/gemma3:latest" ,
76- },
77- }
78-
79- for _ , tt := range tests {
80- t .Run (tt .name , func (t * testing.T ) {
81- result := models .NormalizeModelName (tt .input )
82- if result != tt .expected {
83- t .Errorf ("NormalizeModelName(%q) = %q, want %q" , tt .input , result , tt .expected )
84- }
85- })
86- }
87- }
88-
899func TestStripDefaultsFromModelName (t * testing.T ) {
9010 tests := []struct {
9111 name string
@@ -174,54 +94,6 @@ func TestStripDefaultsFromModelName(t *testing.T) {
17494 }
17595}
17696
177- // TestNormalizeModelNameConsistency verifies that locally packaged models
178- // (without namespace) get normalized the same way as other operations.
179- // This test documents the fix for the bug where `docker model package my-model`
180- // would create a model that couldn't be run with `docker model run my-model`.
181- func TestNormalizeModelNameConsistency (t * testing.T ) {
182- tests := []struct {
183- name string
184- userProvidedName string
185- expectedNormalizedName string
186- description string
187- }{
188- {
189- name : "locally packaged model without namespace" ,
190- userProvidedName : "my-model" ,
191- expectedNormalizedName : "ai/my-model:latest" ,
192- description : "When a user packages a local model as 'my-model', it should be normalized to 'ai/my-model:latest'" ,
193- },
194- {
195- name : "locally packaged model without namespace but with tag" ,
196- userProvidedName : "my-model:v1.0" ,
197- expectedNormalizedName : "ai/my-model:v1.0" ,
198- description : "When a user packages a local model as 'my-model:v1.0', it should be normalized to 'ai/my-model:v1.0'" ,
199- },
200- {
201- name : "model with explicit namespace" ,
202- userProvidedName : "myorg/my-model" ,
203- expectedNormalizedName : "myorg/my-model:latest" ,
204- description : "When a user packages a model with explicit org 'myorg/my-model', it should keep the org" ,
205- },
206- {
207- name : "model with ai namespace explicitly set" ,
208- userProvidedName : "ai/my-model" ,
209- expectedNormalizedName : "ai/my-model:latest" ,
210- description : "When a user explicitly sets 'ai/' namespace, it should remain the same" ,
211- },
212- }
213-
214- for _ , tt := range tests {
215- t .Run (tt .name , func (t * testing.T ) {
216- result := models .NormalizeModelName (tt .userProvidedName )
217- if result != tt .expectedNormalizedName {
218- t .Errorf ("%s: NormalizeModelName(%q) = %q, want %q" ,
219- tt .description , tt .userProvidedName , result , tt .expectedNormalizedName )
220- }
221- })
222- }
223- }
224-
22597// TestHandleClientErrorFormat verifies that the error format follows the expected pattern.
22698func TestHandleClientErrorFormat (t * testing.T ) {
22799 t .Run ("error format is message: original error" , func (t * testing.T ) {
0 commit comments