MCPcopy Index your code
hub / github.com/docker/docker-agent / TestFetchDisallowedServesFromCache

Function TestFetchDisallowedServesFromCache

pkg/modelsdev/store_test.go:100–134  ·  view source on GitHub ↗

TestFetchDisallowedServesFromCache checks the cache-only path: a provider the predicate rejects but that IS present in the on-disk cache resolves from the cache without any network call, and an absent one is a clean "not found".

(t *testing.T)

Source from the content-addressed store, hash-verified

98// predicate rejects but that IS present in the on-disk cache resolves from the
99// cache without any network call, and an absent one is a clean "not found".
100func TestFetchDisallowedServesFromCache(t *testing.T) {
101 t.Parallel()
102
103 cacheFile := filepath.Join(t.TempDir(), "models_dev.json")
104 writeCache(t, cacheFile, Database{Providers: map[string]Provider{
105 // Present in the catalog but not in the known-provider set below.
106 "deepseek": {Models: map[string]Model{
107 "deepseek-chat": {Name: "DeepSeek Chat", Limit: Limit{Context: 64000}},
108 }},
109 }})
110
111 store, err := NewStore(
112 WithCache(cacheFile),
113 WithKnownProvider(func(p string) bool { return p == "openai" }),
114 )
115 require.NoError(t, err)
116
117 // Expired context: proves resolution is cache-only (no network) for a
118 // fetch-disallowed provider.
119 ctx := expiredContext(t)
120
121 m, err := store.GetModel(ctx, NewID("deepseek", "deepseek-chat"))
122 require.NoError(t, err)
123 assert.Equal(t, 64000, m.Limit.Context)
124
125 // Repeated lookups stay consistent (served from the memoized snapshot).
126 again, err := store.GetModel(ctx, NewID("deepseek", "deepseek-chat"))
127 require.NoError(t, err)
128 assert.Equal(t, m.Limit.Context, again.Limit.Context)
129
130 // A provider absent from the cache is still a clean not-found, no fetch.
131 _, err = store.GetModel(ctx, NewID("mistral_gateway", "x"))
132 require.Error(t, err)
133 assert.NotContains(t, err.Error(), "fetch from API")
134}
135
136// BenchmarkGetModelFetchDisallowed guards the hot path: repeatedly resolving a
137// fetch-disallowed provider against a warm, sizable cache must not re-read and

Callers

nothing calls this directly

Calls 8

GetModelMethod · 0.95
writeCacheFunction · 0.85
WithKnownProviderFunction · 0.85
expiredContextFunction · 0.85
NewIDFunction · 0.85
NewStoreFunction · 0.70
WithCacheFunction · 0.70
ErrorMethod · 0.45

Tested by

no test coverage detected