Browse code

Enable a unit test on windows.

Signed-off-by: Daniel Nephin <dnephin@docker.com>

Daniel Nephin authored on 2017/04/22 00:18:35
Showing 1 changed files
... ...
@@ -8,6 +8,10 @@ import (
8 8
 	"runtime"
9 9
 	"strings"
10 10
 	"testing"
11
+
12
+	"fmt"
13
+	"github.com/stretchr/testify/assert"
14
+	"github.com/stretchr/testify/require"
11 15
 )
12 16
 
13 17
 // CopyFile with invalid src
... ...
@@ -299,17 +303,14 @@ func TestMatchesWithMalformedPatterns(t *testing.T) {
299 299
 	}
300 300
 }
301 301
 
302
-// Test lots of variants of patterns & strings
302
+type matchesTestCase struct {
303
+	pattern string
304
+	text    string
305
+	pass    bool
306
+}
307
+
303 308
 func TestMatches(t *testing.T) {
304
-	// TODO Windows: Port this test
305
-	if runtime.GOOS == "windows" {
306
-		t.Skip("Needs porting to Windows")
307
-	}
308
-	tests := []struct {
309
-		pattern string
310
-		text    string
311
-		pass    bool
312
-	}{
309
+	tests := []matchesTestCase{
313 310
 		{"**", "file", true},
314 311
 		{"**", "file/", true},
315 312
 		{"**/", "file", true}, // weird one
... ...
@@ -361,9 +362,6 @@ func TestMatches(t *testing.T) {
361 361
 		{"abc.def", "abcZdef", false},
362 362
 		{"abc?def", "abcZdef", true},
363 363
 		{"abc?def", "abcdef", false},
364
-		{"a\\*b", "a*b", true},
365
-		{"a\\", "a", false},
366
-		{"a\\", "a\\", false},
367 364
 		{"a\\\\", "a\\", true},
368 365
 		{"**/foo/bar", "foo/bar", true},
369 366
 		{"**/foo/bar", "dir/foo/bar", true},
... ...
@@ -375,15 +373,20 @@ func TestMatches(t *testing.T) {
375 375
 		{"**/.foo", "bar.foo", false},
376 376
 	}
377 377
 
378
+	if runtime.GOOS != "windows" {
379
+		tests = append(tests, []matchesTestCase{
380
+			{"a\\*b", "a*b", true},
381
+			{"a\\", "a", false},
382
+			{"a\\", "a\\", false},
383
+		}...)
384
+	}
385
+
378 386
 	for _, test := range tests {
387
+		desc := fmt.Sprintf("pattern=%q text=%q", test.pattern, test.text)
379 388
 		pm, err := NewPatternMatcher([]string{test.pattern})
380
-		if err != nil {
381
-			t.Fatalf("invalid pattern %s", test.pattern)
382
-		}
389
+		require.NoError(t, err, desc)
383 390
 		res, _ := pm.Matches(test.text)
384
-		if res != test.pass {
385
-			t.Fatalf("Failed: %v - res:%v", test, res)
386
-		}
391
+		assert.Equal(t, test.pass, res, desc)
387 392
 	}
388 393
 }
389 394