MCPcopy
hub / github.com/larksuite/cli / TestCacheHit_WithinTTL

Function TestCacheHit_WithinTTL

internal/registry/remote_test.go:162–197  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

160}
161
162func TestCacheHit_WithinTTL(t *testing.T) {
163 resetInit()
164 tmp := t.TempDir()
165 t.Setenv("LARKSUITE_CLI_CONFIG_DIR", tmp)
166 t.Setenv("LARKSUITE_CLI_REMOTE_META", "on")
167 t.Setenv("LARKSUITE_CLI_META_TTL", "3600")
168
169 // Pre-seed cache with a custom service
170 cDir := filepath.Join(tmp, "cache")
171 os.MkdirAll(cDir, 0700)
172 os.WriteFile(filepath.Join(cDir, "remote_meta.json"), testCacheJSON("custom_svc"), 0644)
173 meta := CacheMeta{LastCheckAt: time.Now().Unix()}
174 metaData, _ := json.Marshal(meta)
175 os.WriteFile(filepath.Join(cDir, "remote_meta.meta.json"), metaData, 0644)
176
177 // Point META_URL to a server that would fail if contacted
178 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
179 t.Error("server should not be contacted when cache is within TTL")
180 w.WriteHeader(500)
181 }))
182 defer ts.Close()
183 testMetaURL = ts.URL
184
185 Init()
186
187 // custom_svc should be loaded from cache overlay
188 if _, ok := ServiceTyped("custom_svc"); !ok {
189 t.Error("expected custom_svc from cache overlay")
190 }
191 // Embedded projects should still be present (if compiled in)
192 if hasEmbeddedServices() {
193 if _, ok := ServiceTyped("calendar"); !ok {
194 t.Error("expected calendar from embedded data")
195 }
196 }
197}
198
199func TestNetworkError_SilentDegradation(t *testing.T) {
200 resetInit()

Callers

nothing calls this directly

Calls 9

resetInitFunction · 0.85
testCacheJSONFunction · 0.85
ServiceTypedFunction · 0.85
hasEmbeddedServicesFunction · 0.85
InitFunction · 0.70
MkdirAllMethod · 0.65
WriteFileMethod · 0.65
ErrorMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected