Skip to content

Commit 1c9e856

Browse files
committed
test(provider): cover resolveEffectiveProvider and isOpenAICompatibleProvider
Both helpers had partial coverage — resolveEffectiveProvider's 'explicit Provider wins' branch was implicitly exercised through the merge tests, and isOpenAICompatibleProvider's alias-table tail was completely uncovered (80%). Add focused, table-driven tests: - resolveEffectiveProvider: documents the explicit-Provider-wins contract and the openai backward-compat fallback when Provider is empty. - isOpenAICompatibleProvider: walks the actual Aliases map and asserts that every alias whose APIType is 'openai' is reported as compatible. This means new openai-flavoured aliases automatically get coverage when they're added. Both helpers now reach 100% coverage; package coverage 95.8% -> 96.4%. Assisted-By: docker-agent
1 parent 1d7328e commit 1c9e856

1 file changed

Lines changed: 74 additions & 0 deletions

File tree

pkg/model/provider/resolve_test.go

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package provider
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
8+
"github.com/docker/docker-agent/pkg/config/latest"
9+
)
10+
11+
func TestResolveEffectiveProvider(t *testing.T) {
12+
t.Parallel()
13+
14+
tests := []struct {
15+
name string
16+
cfg latest.ProviderConfig
17+
want string
18+
}{
19+
{
20+
name: "explicit Provider wins",
21+
cfg: latest.ProviderConfig{Provider: "anthropic"},
22+
want: "anthropic",
23+
},
24+
{
25+
name: "empty Provider falls back to openai (backward compat)",
26+
cfg: latest.ProviderConfig{},
27+
want: "openai",
28+
},
29+
{
30+
name: "explicit Provider wins even if APIType also set",
31+
cfg: latest.ProviderConfig{Provider: "google", APIType: "openai_chatcompletions"},
32+
want: "google",
33+
},
34+
}
35+
36+
for _, tt := range tests {
37+
t.Run(tt.name, func(t *testing.T) {
38+
t.Parallel()
39+
assert.Equal(t, tt.want, resolveEffectiveProvider(tt.cfg))
40+
})
41+
}
42+
}
43+
44+
func TestIsOpenAICompatibleProvider(t *testing.T) {
45+
t.Parallel()
46+
47+
// Direct OpenAI api types — first switch arm.
48+
openAIArm := []string{"openai", "openai_chatcompletions", "openai_responses"}
49+
for _, p := range openAIArm {
50+
t.Run("direct/"+p, func(t *testing.T) {
51+
t.Parallel()
52+
assert.True(t, isOpenAICompatibleProvider(p))
53+
})
54+
}
55+
56+
// Aliases that point to the openai api — the previously-uncovered tail.
57+
for name, alias := range Aliases {
58+
if alias.APIType == "openai" {
59+
t.Run("alias/"+name, func(t *testing.T) {
60+
t.Parallel()
61+
assert.True(t, isOpenAICompatibleProvider(name), "alias %s should map to openai", name)
62+
})
63+
}
64+
}
65+
66+
// Negative cases.
67+
negatives := []string{"anthropic", "google", "dmr", "amazon-bedrock", "unknown", ""}
68+
for _, p := range negatives {
69+
t.Run("negative/"+p, func(t *testing.T) {
70+
t.Parallel()
71+
assert.False(t, isOpenAICompatibleProvider(p))
72+
})
73+
}
74+
}

0 commit comments

Comments
 (0)