MCPcopy Create free account
hub / github.com/JordanCoin/codemap / TestGitIgnoreCacheEnsureDir

Function TestGitIgnoreCacheEnsureDir

scanner/walker_test.go:708–758  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

706}
707
708func TestGitIgnoreCacheEnsureDir(t *testing.T) {
709 tests := []struct {
710 name string
711 run func(t *testing.T)
712 }{
713 {
714 name: "nil cache no panic",
715 run: func(t *testing.T) {
716 var cache *GitIgnoreCache
717 cache.EnsureDir("any/path")
718 },
719 },
720 {
721 name: "empty dir no panic",
722 run: func(t *testing.T) {
723 cache := NewGitIgnoreCache(t.TempDir())
724 cache.EnsureDir("")
725 },
726 },
727 {
728 name: "loads gitignore in provided dir",
729 run: func(t *testing.T) {
730 root := t.TempDir()
731 sub := filepath.Join(root, "sub")
732 if err := os.MkdirAll(sub, 0o755); err != nil {
733 t.Fatal(err)
734 }
735 if err := os.WriteFile(filepath.Join(sub, ".gitignore"), []byte("*.tmp\n"), 0o644); err != nil {
736 t.Fatal(err)
737 }
738 cache := NewGitIgnoreCache(root)
739 cache.EnsureDir(sub)
740 if _, ok := cache.cache[sub]; !ok {
741 t.Fatalf("expected gitignore cache for %q", sub)
742 }
743 if _, ok := cache.patterns[sub]; !ok {
744 t.Fatalf("expected gitignore patterns for %q", sub)
745 }
746 if !cache.ShouldIgnore(filepath.Join(sub, "file.tmp")) {
747 t.Fatal("expected nested .gitignore pattern to apply")
748 }
749 },
750 },
751 }
752
753 for _, tt := range tests {
754 t.Run(tt.name, func(t *testing.T) {
755 tt.run(t)
756 })
757 }
758}
759
760func TestScanFilesWithOnlyAndExcludeFilters(t *testing.T) {
761 tmpDir := t.TempDir()

Callers

nothing calls this directly

Calls 3

EnsureDirMethod · 0.95
ShouldIgnoreMethod · 0.95
NewGitIgnoreCacheFunction · 0.85

Tested by

no test coverage detected