1package fsext
2
3import (
4 "os"
5 "testing"
6
7 "github.com/stretchr/testify/require"
8)
9
10func TestCrushIgnore(t *testing.T) {
11 // Create a temporary directory for testing
12 tempDir := t.TempDir()
13
14 // Change to temp directory
15 oldWd, _ := os.Getwd()
16 err := os.Chdir(tempDir)
17 require.NoError(t, err)
18 defer os.Chdir(oldWd)
19
20 // Create test files
21 require.NoError(t, os.WriteFile("test1.txt", []byte("test"), 0o644))
22 require.NoError(t, os.WriteFile("test2.log", []byte("test"), 0o644))
23 require.NoError(t, os.WriteFile("test3.tmp", []byte("test"), 0o644))
24
25 // Create a .crushignore file that ignores .log files
26 require.NoError(t, os.WriteFile(".crushignore", []byte("*.log\n"), 0o644))
27
28 dl := NewDirectoryLister(tempDir)
29 require.True(t, dl.shouldIgnore("test2.log", nil), ".log files should be ignored")
30 require.False(t, dl.shouldIgnore("test1.txt", nil), ".txt files should not be ignored")
31 require.True(t, dl.shouldIgnore("test3.tmp", nil), ".tmp files should be ignored by common patterns")
32}