Skip to content

Commit

Permalink
Add ignorefile read all negative test case
Browse files Browse the repository at this point in the history
Signed-off-by: Austin Vazquez <[email protected]>
  • Loading branch information
austinvazquez committed Sep 7, 2024
1 parent 347bb8d commit d6eb338
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions ignorefile/ignorefile_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
package ignorefile

import (
"errors"
"strings"
"testing"
)

type emitErrorOnRead struct{}

var errRead = errors.New("read error")

func (r emitErrorOnRead) Read(_ []byte) (int, error) {
return 0, errRead
}

func TestReadAll(t *testing.T) {
actual, err := ReadAll(nil)
if err != nil {
Expand All @@ -14,6 +23,14 @@ func TestReadAll(t *testing.T) {
t.Fatalf("Expected to have zero entries, got %d", entries)
}

actual, err = ReadAll(emitErrorOnRead{})
if !errors.Is(err, errRead) {
t.Fatalf("Expected %v, got %v", errRead, err)
}
if entries := len(actual); entries != 0 {
t.Fatalf("Expected to have zero entries, got %d", entries)
}

const content = `test1
/test2
/a/file/here
Expand Down

0 comments on commit d6eb338

Please sign in to comment.