Skip to content

Commit

Permalink
Add ignore package tests
Browse files Browse the repository at this point in the history
  • Loading branch information
caitlinelfring committed Aug 31, 2020
1 parent b848e14 commit f61691b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ require (
github.com/rs/zerolog v1.19.0
github.com/sabhiram/go-gitignore v0.0.0-20180611051255-d3107576ba94
github.com/spf13/cobra v1.0.0
github.com/stretchr/testify v1.2.2
gopkg.in/yaml.v2 v2.3.0
)
2 changes: 1 addition & 1 deletion pkg/ignore/ignore.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,5 @@ func readIgnoreFile(file string) []string {
_event.Err(err).Str("file", file).Msg("skipping ignorefile")
}

return strings.Split(string(buffer), "\n")
return strings.Split(strings.TrimSpace(string(buffer)), "\n")
}
22 changes: 22 additions & 0 deletions pkg/ignore/ignore_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package ignore

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestIgnoreMatch(t *testing.T) {
i, err := NewIgnore([]string{"my/files/*"})
assert.NoError(t, err)
assert.NotNil(t, i)

assert.False(t, i.Match("not/foo"))
assert.True(t, i.Match("my/files/file1"))
}

func TestReadIgnoreFIle(t *testing.T) {
lines := readIgnoreFile("testdata/.gitignore")

assert.Equal(t, []string{"*.DS_Store"}, lines)
}
1 change: 1 addition & 0 deletions pkg/ignore/testdata/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.DS_Store

0 comments on commit f61691b

Please sign in to comment.