(t *testing.T)
| 799 | } |
| 800 | |
| 801 | func 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 | |
| 833 | func TestDispatchAuthUpdatesFlushesQueue(t *testing.T) { |
| 834 | queue := make(chan AuthUpdate, 4) |
nothing calls this directly
no test coverage detected