fork/gdu

git clone https://git.julia.blue/fork/gdu

Daniel Mildetest: cover internal packages (#535)fb46b4f

ignore
974 B41 linesraw
1package common_test
2
3import (
4	"os"
5	"path/filepath"
6	"testing"
7
8	"github.com/dundee/gdu/v5/internal/common"
9	"github.com/stretchr/testify/assert"
10)
11
12func TestSetIgnoreFromEmptyFile(t *testing.T) {
13	dir := t.TempDir()
14	path := filepath.Join(dir, "ignore")
15	err := os.WriteFile(path, []byte(""), 0o600)
16	assert.Nil(t, err)
17
18	ui := &common.UI{}
19	err = ui.SetIgnoreFromFile(path)
20	assert.Nil(t, err)
21
22	shouldIgnore := ui.CreateIgnoreFunc()
23	assert.False(t, shouldIgnore("anything", "/anything"))
24}
25
26func TestSetIgnoreFromFileWithBlankLines(t *testing.T) {
27	dir := t.TempDir()
28	path := filepath.Join(dir, "ignore")
29	content := "/valid\n/other\n"
30	err := os.WriteFile(path, []byte(content), 0o600)
31	assert.Nil(t, err)
32
33	ui := &common.UI{}
34	err = ui.SetIgnoreFromFile(path)
35	assert.Nil(t, err)
36
37	shouldIgnore := ui.CreateIgnoreFunc()
38	assert.True(t, shouldIgnore("valid", "/valid"))
39	assert.True(t, shouldIgnore("other", "/other"))
40	assert.False(t, shouldIgnore("xxx", "/xxx"))
41}