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

Function TestHandleEventRemovesAuthFile

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

Source from the content-addressed store, hash-verified

799}
800
801func TestHandleEventRemovesAuthFile(t *testing.T) {
802 tmpDir := t.TempDir()
803 authFile := filepath.Join(tmpDir, "remove.json")
804 if err := os.WriteFile(authFile, []byte(`{"type":"demo"}`), 0o644); err != nil {
805 t.Fatalf("failed to write auth file: %v", err)
806 }
807 if err := os.Remove(authFile); err != nil {
808 t.Fatalf("failed to remove auth file pre-check: %v", err)
809 }
810
811 var reloads int32
812 w := &Watcher{
813 authDir: tmpDir,
814 config: &config.Config{AuthDir: tmpDir},
815 lastAuthHashes: make(map[string]string),
816 reloadCallback: func(*config.Config) {
817 atomic.AddInt32(&reloads, 1)
818 },
819 }
820 // Use normalizeAuthPath to set up the hash with the correct key format
821 w.lastAuthHashes[w.normalizeAuthPath(authFile)] = "hash"
822
823 w.handleEvent(fsnotify.Event{Name: authFile, Op: fsnotify.Remove})
824
825 if atomic.LoadInt32(&reloads) != 0 {
826 t.Fatalf("expected no reload callback for auth removal, got %d", reloads)
827 }
828 if _, ok := w.lastAuthHashes[w.normalizeAuthPath(authFile)]; ok {
829 t.Fatal("expected hash entry to be removed")
830 }
831}
832
833func TestDispatchAuthUpdatesFlushesQueue(t *testing.T) {
834 queue := make(chan AuthUpdate, 4)

Callers

nothing calls this directly

Calls 3

normalizeAuthPathMethod · 0.95
handleEventMethod · 0.95
RemoveMethod · 0.80

Tested by

no test coverage detected