Skip to content

Commit

Permalink
add TestNewIgnore (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
JunNishimura committed Jun 17, 2023
1 parent e9d4b06 commit 4812662
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/store/ignore.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func NewIgnore(rootGoitPath string) (*Ignore, error) {

func newIgnore() *Ignore {
return &Ignore{
paths: []string{".goit/.*"},
paths: []string{`\.goit/.*`},
}
}

Expand Down
66 changes: 66 additions & 0 deletions internal/store/ignore_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package store

import (
"os"
"path/filepath"
"reflect"
"testing"
)

func TestNewIgnore(t *testing.T) {
type fields struct {
content string
}
tests := []struct {
name string
fields fields
want *Ignore
wantErr bool
}{
{
name: "success: empty",
fields: fields{
content: "",
},
want: &Ignore{
paths: []string{`\.goit/.*`},
},
wantErr: false,
},
{
name: "success: some ignore list",
fields: fields{
content: "*.exe\ndir/",
},
want: &Ignore{
paths: []string{`\.goit/.*`, `.*\.exe`, `dir/.*`},
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tmpDir := t.TempDir()

goitignorePath := filepath.Join(tmpDir, ".goitignore")
f, err := os.Create(goitignorePath)
if err != nil {
t.Log(err)
}
_, err = f.WriteString(tt.fields.content)
if err != nil {
t.Log(err)
}
f.Close()

goitPath := filepath.Join(tmpDir, ".goit")
i, err := NewIgnore(goitPath)
if (err != nil) != tt.wantErr {
t.Errorf("got = %v, want = %v", err, tt.wantErr)
}
if !reflect.DeepEqual(i, tt.want) {
t.Errorf("got = %v, want = %v", i, tt.want)
}
})
}
}

0 comments on commit 4812662

Please sign in to comment.