(t *testing.T)
| 160 | } |
| 161 | |
| 162 | func 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 | |
| 199 | func TestNetworkError_SilentDegradation(t *testing.T) { |
| 200 | resetInit() |
nothing calls this directly
no test coverage detected