-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgitignore_test.go
More file actions
65 lines (59 loc) · 1.73 KB
/
Copy pathgitignore_test.go
File metadata and controls
65 lines (59 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package contexting
import (
"os"
"path/filepath"
"testing"
)
func TestEnsureAndLoadGitignoreCreatesStarter(t *testing.T) {
tmpDir := t.TempDir()
patterns, err := EnsureAndLoadGitignore(tmpDir)
if err != nil {
t.Fatalf("EnsureAndLoadGitignore failed: %v", err)
}
if len(patterns) == 0 {
t.Fatalf("expected starter patterns")
}
foundVenv := false
foundSitePackages := false
for _, pattern := range patterns {
if pattern == ".venv" {
foundVenv = true
}
if pattern == "site-packages" {
foundSitePackages = true
}
}
if !foundVenv {
t.Fatalf("expected starter patterns to include .venv, got %v", patterns)
}
if !foundSitePackages {
t.Fatalf("expected starter patterns to include site-packages, got %v", patterns)
}
if _, err := os.Stat(filepath.Join(tmpDir, ".gitignore")); err != nil {
t.Fatalf("expected .gitignore created: %v", err)
}
}
func TestLoadGitignorePatternsIgnoresCommentsAndNegation(t *testing.T) {
tmpDir := t.TempDir()
path := filepath.Join(tmpDir, ".gitignore")
content := "# comment\nnode_modules/\n.env\n!important.env\n*.log\n"
if err := os.WriteFile(path, []byte(content), 0o644); err != nil {
t.Fatalf("write .gitignore: %v", err)
}
patterns, err := LoadGitignorePatterns(path)
if err != nil {
t.Fatalf("LoadGitignorePatterns failed: %v", err)
}
if len(patterns) < 3 {
t.Fatalf("expected parsed patterns, got %v", patterns)
}
}
func TestShouldIgnorePathWithWildcard(t *testing.T) {
ignored := BuildIgnoreMap([]string{"*.log", ".env.*.local"})
if !shouldIgnorePath("logs/app.log", "app.log", ignored) {
t.Fatalf("expected wildcard log pattern to match")
}
if !shouldIgnorePath(".env.dev.local", ".env.dev.local", ignored) {
t.Fatalf("expected wildcard env pattern to match")
}
}