(t *testing.T)
| 594 | } |
| 595 | |
| 596 | func TestAuthFileUnchangedUsesHash(t *testing.T) { |
| 597 | tmpDir := t.TempDir() |
| 598 | authFile := filepath.Join(tmpDir, "sample.json") |
| 599 | content := []byte(`{"type":"demo"}`) |
| 600 | if err := os.WriteFile(authFile, content, 0o644); err != nil { |
| 601 | t.Fatalf("failed to write auth file: %v", err) |
| 602 | } |
| 603 | |
| 604 | w := &Watcher{lastAuthHashes: make(map[string]string)} |
| 605 | unchanged, err := w.authFileUnchanged(authFile) |
| 606 | if err != nil { |
| 607 | t.Fatalf("unexpected error: %v", err) |
| 608 | } |
| 609 | if unchanged { |
| 610 | t.Fatal("expected first check to report changed") |
| 611 | } |
| 612 | |
| 613 | sum := sha256.Sum256(content) |
| 614 | // Use normalizeAuthPath to match how authFileUnchanged looks up the key |
| 615 | w.lastAuthHashes[w.normalizeAuthPath(authFile)] = hexString(sum[:]) |
| 616 | |
| 617 | unchanged, err = w.authFileUnchanged(authFile) |
| 618 | if err != nil { |
| 619 | t.Fatalf("unexpected error: %v", err) |
| 620 | } |
| 621 | if !unchanged { |
| 622 | t.Fatal("expected hash match to report unchanged") |
| 623 | } |
| 624 | } |
| 625 | |
| 626 | func TestAuthFileUnchangedEmptyAndMissing(t *testing.T) { |
| 627 | tmpDir := t.TempDir() |
nothing calls this directly
no test coverage detected