From f1f010b701c4fe87063aa2bb679438ad4d618a08 Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Fri, 21 Apr 2017 11:18:35 -0400 Subject: [PATCH] Enable a unit test on windows. Signed-off-by: Daniel Nephin Upstream-commit: 9484c3bd81fa8aab46b7268c5c3bfeb8e14aa369 Component: engine --- .../engine/pkg/fileutils/fileutils_test.go | 41 ++++++++++--------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/components/engine/pkg/fileutils/fileutils_test.go b/components/engine/pkg/fileutils/fileutils_test.go index 4b178a16bb..3d61d55c3a 100644 --- a/components/engine/pkg/fileutils/fileutils_test.go +++ b/components/engine/pkg/fileutils/fileutils_test.go @@ -8,6 +8,10 @@ import ( "runtime" "strings" "testing" + + "fmt" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) // CopyFile with invalid src @@ -299,17 +303,14 @@ func TestMatchesWithMalformedPatterns(t *testing.T) { } } -// Test lots of variants of patterns & strings +type matchesTestCase struct { + pattern string + text string + pass bool +} + func TestMatches(t *testing.T) { - // TODO Windows: Port this test - if runtime.GOOS == "windows" { - t.Skip("Needs porting to Windows") - } - tests := []struct { - pattern string - text string - pass bool - }{ + tests := []matchesTestCase{ {"**", "file", true}, {"**", "file/", true}, {"**/", "file", true}, // weird one @@ -361,9 +362,6 @@ func TestMatches(t *testing.T) { {"abc.def", "abcZdef", false}, {"abc?def", "abcZdef", true}, {"abc?def", "abcdef", false}, - {"a\\*b", "a*b", true}, - {"a\\", "a", false}, - {"a\\", "a\\", false}, {"a\\\\", "a\\", true}, {"**/foo/bar", "foo/bar", true}, {"**/foo/bar", "dir/foo/bar", true}, @@ -375,15 +373,20 @@ func TestMatches(t *testing.T) { {"**/.foo", "bar.foo", false}, } + if runtime.GOOS != "windows" { + tests = append(tests, []matchesTestCase{ + {"a\\*b", "a*b", true}, + {"a\\", "a", false}, + {"a\\", "a\\", false}, + }...) + } + for _, test := range tests { + desc := fmt.Sprintf("pattern=%q text=%q", test.pattern, test.text) pm, err := NewPatternMatcher([]string{test.pattern}) - if err != nil { - t.Fatalf("invalid pattern %s", test.pattern) - } + require.NoError(t, err, desc) res, _ := pm.Matches(test.text) - if res != test.pass { - t.Fatalf("Failed: %v - res:%v", test, res) - } + assert.Equal(t, test.pass, res, desc) } }