Skip to content

Commit

Permalink
windows: test symlinks (#491)
Browse files Browse the repository at this point in the history
Symlinks are supported since Windows Vista; there's no reason to not
test it.
  • Loading branch information
arp242 committed Aug 5, 2022
1 parent f45391f commit a24f78c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
15 changes: 12 additions & 3 deletions helpers_test.go
Expand Up @@ -348,12 +348,15 @@ func (e Events) copy() Events {
// # Windows-specific test.
// windows:
// WRITE path
//
// You can specify multiple platforms with a comma (e.g. "windows, linux:").
// "kqueue" is a shortcut for all kqueue systems (BSD, macOS).
func newEvents(t *testing.T, s string) Events {
t.Helper()

var (
lines = strings.Split(s, "\n")
group string
groups = []string{""}
events = make(map[string]Events)
)
for no, line := range lines {
Expand All @@ -365,7 +368,10 @@ func newEvents(t *testing.T, s string) Events {
continue
}
if strings.HasSuffix(line, ":") {
group = strings.TrimRight(line, ":")
groups = strings.Split(strings.TrimRight(line, ":"), ",")
for i := range groups {
groups[i] = strings.TrimSpace(groups[i])
}
continue
}

Expand Down Expand Up @@ -398,7 +404,10 @@ func newEvents(t *testing.T, s string) Events {
}
}
}
events[group] = append(events[group], Event{Name: path, Op: op})

for _, g := range groups {
events[g] = append(events[g], Event{Name: path, Op: op})
}
}

if e, ok := events[runtime.GOOS]; ok {
Expand Down
10 changes: 5 additions & 5 deletions integration_test.go
Expand Up @@ -196,17 +196,17 @@ func TestWatchRename(t *testing.T) {
}

func TestWatchSymlink(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("symlinks don't work on Windows")
}

tests := []testCase{
{"create unresolvable symlink", func(t *testing.T, w *Watcher, tmp string) {
addWatch(t, w, tmp)

symlink(t, filepath.Join(tmp, "target"), tmp, "link")
}, `
create /link
windows:
create /link
write /link
`},

{"cyclic symlink", func(t *testing.T, w *Watcher, tmp string) {
Expand Down Expand Up @@ -234,7 +234,7 @@ func TestWatchSymlink(t *testing.T) {
write /link
create /link
linux:
linux, windows:
remove /link
create /link
write /link
Expand Down

0 comments on commit a24f78c

Please sign in to comment.