MCPcopy Create free account
hub / github.com/chainreactors/EvilProxy / TestAddOrUpdateClientEdgeCases

Function TestAddOrUpdateClientEdgeCases

internal/watcher/watcher_test.go:1239–1268  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1237}
1238
1239func 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
1270func TestLoadFileClientsWalkError(t *testing.T) {
1271 tmpDir := t.TempDir()

Callers

nothing calls this directly

Calls 1

addOrUpdateClientMethod · 0.95

Tested by

no test coverage detected