@@ -17,7 +17,9 @@ package watch
17
17
18
18
import (
19
19
"context"
20
+ "fmt"
20
21
"io/ioutil"
22
+ "os"
21
23
"path/filepath"
22
24
"testing"
23
25
@@ -26,6 +28,7 @@ import (
26
28
)
27
29
28
30
func TestWatch (t * testing.T ) {
31
+ watchers := []string {"mtime" , "fsnotify" }
29
32
var tests = []struct {
30
33
description string
31
34
createFiles []string
@@ -57,50 +60,55 @@ func TestWatch(t *testing.T) {
57
60
},
58
61
}
59
62
60
- for _ , test := range tests {
61
- t .Run (test .description , func (t * testing.T ) {
62
- tmp , teardown := testutil .TempDir (t )
63
- defer teardown ()
64
-
65
- for _ , p := range prependParentDir (tmp , test .createFiles ) {
66
- write (t , p , "" )
67
- }
68
-
69
- watcher , err := NewWatcher (prependParentDir (tmp , test .watchFiles ))
70
- if err == nil && test .shouldErr {
71
- t .Errorf ("Expected error, but returned none" )
72
- return
73
- }
74
- if err != nil && ! test .shouldErr {
75
- t .Errorf ("Unexpected error: %s" , err )
76
- return
77
- }
78
- if err != nil && test .shouldErr {
79
- return
80
- }
81
-
82
- for _ , p := range prependParentDir (tmp , test .writes ) {
83
- write (t , p , "CONTENT" )
84
- }
85
-
86
- ctx , cancel := context .WithCancel (context .Background ())
87
- watcher .Start (ctx , ioutil .Discard , func (actual []string ) error {
88
- defer cancel ()
63
+ for _ , watcher := range watchers {
64
+ for _ , test := range tests {
65
+ t .Run (fmt .Sprintf ("%s %s" , test .description , watcher ), func (t * testing.T ) {
66
+ os .Setenv ("SKAFFOLD_FILE_WATCHER" , watcher )
67
+ defer os .Setenv ("SKAFFOLD_FILE_WATCHER" , "" )
68
+ tmp , teardown := testutil .TempDir (t )
69
+ defer teardown ()
89
70
90
- expected := prependParentDir (tmp , test .expectedChanges )
71
+ for _ , p := range prependParentDir (tmp , test .createFiles ) {
72
+ write (t , p , "" )
73
+ }
91
74
92
- if diff := cmp .Diff (expected , actual ); diff != "" {
93
- t .Errorf ("Expected %+v, Actual %+v" , expected , actual )
75
+ watcher , err := NewWatcher (prependParentDir (tmp , test .watchFiles ))
76
+ if err == nil && test .shouldErr {
77
+ t .Errorf ("Expected error, but returned none" )
78
+ return
79
+ }
80
+ if err != nil && ! test .shouldErr {
81
+ t .Errorf ("Unexpected error: %s" , err )
82
+ return
94
83
}
84
+ if err != nil && test .shouldErr {
85
+ return
86
+ }
87
+
88
+ ctx , cancel := context .WithCancel (context .Background ())
95
89
96
- return nil
90
+ defer cancel ()
91
+ go watcher .Start (ctx , ioutil .Discard , func (actual []string ) error {
92
+
93
+ expected := prependParentDir (tmp , test .expectedChanges )
94
+
95
+ if diff := cmp .Diff (expected , actual ); diff != "" {
96
+ t .Errorf ("Expected %+v, Actual %+v" , expected , actual )
97
+ }
98
+
99
+ return nil
100
+ })
101
+
102
+ for _ , p := range prependParentDir (tmp , test .writes ) {
103
+ write (t , p , "CONTENT" )
104
+ }
97
105
})
98
- })
106
+ }
99
107
}
100
108
}
101
109
func write (t * testing.T , path string , content string ) {
102
- if err := ioutil .WriteFile (path , []byte (content ), 0640 ); err != nil {
103
- t .Errorf ("writing mock fs file: %s" , err )
110
+ if err := ioutil .WriteFile (path , []byte (content ), 0644 ); err != nil {
111
+ t .Fatalf ("writing file: %s" , err )
104
112
}
105
113
}
106
114
0 commit comments