mirror of
https://github.com/onyx-and-iris/exclude.git
synced 2026-04-16 14:13:39 +00:00
add del command
add tests for all commands wrap entry point with fang add --version flag target to Taskfile
This commit is contained in:
46
cmd/list_test.go
Normal file
46
cmd/list_test.go
Normal file
@@ -0,0 +1,46 @@
|
||||
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())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user