(t *testing.T)
| 1237 | } |
| 1238 | |
| 1239 | func TestAddOrUpdateClientEdgeCases(t *testing.T) { |
| 1240 | tmpDir := t.TempDir() |
| 1241 | authDir := tmpDir |
| 1242 | authFile := filepath.Join(tmpDir, "edge.json") |
| 1243 | if err := os.WriteFile(authFile, []byte(`{"type":"demo"}`), 0o644); err != nil { |
| 1244 | t.Fatalf("failed to write auth file: %v", err) |
| 1245 | } |
| 1246 | emptyFile := filepath.Join(tmpDir, "empty.json") |
| 1247 | if err := os.WriteFile(emptyFile, []byte(""), 0o644); err != nil { |
| 1248 | t.Fatalf("failed to write empty auth file: %v", err) |
| 1249 | } |
| 1250 | |
| 1251 | var reloads int32 |
| 1252 | w := &Watcher{ |
| 1253 | authDir: authDir, |
| 1254 | lastAuthHashes: make(map[string]string), |
| 1255 | reloadCallback: func(*config.Config) { atomic.AddInt32(&reloads, 1) }, |
| 1256 | } |
| 1257 | |
| 1258 | w.addOrUpdateClient(filepath.Join(tmpDir, "missing.json")) |
| 1259 | w.addOrUpdateClient(emptyFile) |
| 1260 | if atomic.LoadInt32(&reloads) != 0 { |
| 1261 | t.Fatalf("expected no reloads for missing/empty file, got %d", reloads) |
| 1262 | } |
| 1263 | |
| 1264 | w.addOrUpdateClient(authFile) // config nil -> should not panic or update |
| 1265 | if len(w.lastAuthHashes) != 0 { |
| 1266 | t.Fatalf("expected no hash entries without config, got %d", len(w.lastAuthHashes)) |
| 1267 | } |
| 1268 | } |
| 1269 | |
| 1270 | func TestLoadFileClientsWalkError(t *testing.T) { |
| 1271 | tmpDir := t.TempDir() |
nothing calls this directly
no test coverage detected