Skip to content

Commit

Permalink
add tests for lastKeysInPrefixRegexp
Browse files Browse the repository at this point in the history
  • Loading branch information
guy-har committed Nov 8, 2020
1 parent cfb3774 commit 332f7c4
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
1 change: 0 additions & 1 deletion export/export_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ func entriesToDiff(entries []*catalog.Entry) []catalog.Difference {
return res
}

// Todo(guys) - add tests - not checked at all
func getGenerateSuccess(lastKeysInPrefixRegexp []string) func(path string) bool {
return func(path string) bool {
for _, regex := range lastKeysInPrefixRegexp {
Expand Down
43 changes: 43 additions & 0 deletions export/export_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package export
import (
"encoding/json"
"io/ioutil"
"reflect"
"strings"
"testing"

Expand Down Expand Up @@ -150,3 +151,45 @@ func TestTouch(t *testing.T) {
t.Errorf("expected %s, got %s\n", testData, string(val))
}
}

func Test_getGenerateSuccess(t *testing.T) {

tests := []struct {
name string
lastKeysInPrefixRegexp []string
expectTrue []string
expectFalse []string
want func(path string) bool
}{
{
name: "one regex",
lastKeysInPrefixRegexp: []string{".*\\.success$"},
expectTrue: []string{"a.success", "other.success"},
expectFalse: []string{"dfd", "a.suc", "a.successer"},
want: nil,
},
{
name: "two regexes",
lastKeysInPrefixRegexp: []string{".*\\.success$", ".*/success"},
expectTrue: []string{"path/to/a.success", "other.success", "path/to/success"},
expectFalse: []string{"dfd", "a.suc", "a.successer"},
want: nil,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if gs := getGenerateSuccess(tt.lastKeysInPrefixRegexp); !reflect.DeepEqual(gs, tt.want) {
for _, path := range tt.expectTrue {
if !gs(path) {
t.Errorf("expected path %s to return true", path)
}
}
for _, path := range tt.expectFalse {
if gs(path) {
t.Errorf("expected path %s to return false", path)
}
}
}
})
}
}

0 comments on commit 332f7c4

Please sign in to comment.