mirror of
https://github.com/onyx-and-iris/exclude.git
synced 2026-03-30 23:19:09 +00:00
add tests for all commands wrap entry point with fang add --version flag target to Taskfile
47 lines
1.1 KiB
Go
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())
|
|
}
|
|
})
|
|
}
|
|
}
|