From 332f7c42f82fdf86cb9dc8e25a9c4c98461242e1 Mon Sep 17 00:00:00 2001 From: guyhardonag Date: Sun, 8 Nov 2020 17:42:57 +0200 Subject: [PATCH] add tests for lastKeysInPrefixRegexp --- export/export_handler.go | 1 - export/export_handler_test.go | 43 +++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/export/export_handler.go b/export/export_handler.go index b952055543a..4d73e76fb1f 100644 --- a/export/export_handler.go +++ b/export/export_handler.go @@ -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 { diff --git a/export/export_handler_test.go b/export/export_handler_test.go index c66e2eadb52..b5072d17d1f 100644 --- a/export/export_handler_test.go +++ b/export/export_handler_test.go @@ -3,6 +3,7 @@ package export import ( "encoding/json" "io/ioutil" + "reflect" "strings" "testing" @@ -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) + } + } + } + }) + } +}