exclude/cmd/list_test.go
onyx-and-iris 8059255d52 add del command
add tests for all commands

wrap entry point with fang

add --version flag
target to Taskfile
2026-03-29 21:15:56 +01:00

47 lines
1.1 KiB
Go

package cmd
import (
"bytes"
"testing"
)
func TestRunListCommand(t *testing.T) {
tests := []struct {
name string
input string
expected string
}{
{
name: "Empty file",
input: defaultExcludeFileContent,
expected: "No patterns found in the exclude file.\n",
},
{
name: "Exclude file with patterns",
input: defaultExcludeFileContent + "node_modules/\nbuild/\n# This is a comment\n",
expected: "node_modules/\nbuild/\n",
},
{
name: "Exclude file with only comments and empty lines",
input: defaultExcludeFileContent + "# Comment 1\n# Comment 2\n\n",
expected: "No patterns found in the exclude file.\n",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
reader := bytes.NewBufferString(tt.input)
var output bytes.Buffer
err := runListCommand(&output, reader)
if err != nil {
t.Fatalf("runListCommand returned an error: %v", err)
}
if output.String() != tt.expected {
t.Errorf("Expected output:\n%q\nGot:\n%q", tt.expected, output.String())
}
})
}
}