]> go.fuhry.dev Git - fsnotify.git/commitdiff
merge integration tests into one file
authorNathan Youngman <git@nathany.com>
Mon, 8 Sep 2014 02:14:15 +0000 (20:14 -0600)
committerNathan Youngman <git@nathany.com>
Mon, 8 Sep 2014 02:14:15 +0000 (20:14 -0600)
Already have some tests using runtime.GOOS, might as well be consistient.

fsnotify_darwin_test.go [deleted file]
fsnotify_symlink_test.go [deleted file]
fsnotify_test.go

diff --git a/fsnotify_darwin_test.go b/fsnotify_darwin_test.go
deleted file mode 100644 (file)
index 845b097..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-// Copyright 2014 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// +build darwin
-
-package fsnotify
-
-import (
-       "os"
-       "path/filepath"
-       "testing"
-)
-
-// TestConcurrentRemovalOfWatch tests that concurrent calls to RemoveWatch do not race.
-// See https://codereview.appspot.com/103300045/
-// go test -test.run=TestConcurrentRemovalOfWatch -test.cpu=1,1,1,1,1 -race
-func TestConcurrentRemovalOfWatch(t *testing.T) {
-       // Create directory to watch
-       testDir := tempMkdir(t)
-       defer os.RemoveAll(testDir)
-
-       // Create a file before watching directory
-       testFileAlreadyExists := filepath.Join(testDir, "TestFsnotifyEventsExisting.testfile")
-       {
-               var f *os.File
-               f, err := os.OpenFile(testFileAlreadyExists, os.O_WRONLY|os.O_CREATE, 0666)
-               if err != nil {
-                       t.Fatalf("creating test file failed: %s", err)
-               }
-               f.Sync()
-               f.Close()
-       }
-
-       watcher := newWatcher(t)
-       defer watcher.Close()
-
-       addWatch(t, watcher, testDir)
-
-       // Test that RemoveWatch can be invoked concurrently, with no data races.
-       removed1 := make(chan struct{})
-       go func() {
-               defer close(removed1)
-               watcher.Remove(testDir)
-       }()
-       removed2 := make(chan struct{})
-       go func() {
-               close(removed2)
-               watcher.Remove(testDir)
-       }()
-       <-removed1
-       <-removed2
-}
diff --git a/fsnotify_symlink_test.go b/fsnotify_symlink_test.go
deleted file mode 100644 (file)
index b5354b5..0000000
+++ /dev/null
@@ -1,74 +0,0 @@
-// Copyright 2010 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// +build freebsd openbsd netbsd darwin linux
-
-package fsnotify
-
-import (
-       "os"
-       "path/filepath"
-       "testing"
-       "time"
-)
-
-func TestFsnotifyFakeSymlink(t *testing.T) {
-       watcher := newWatcher(t)
-
-       // Create directory to watch
-       testDir := tempMkdir(t)
-       defer os.RemoveAll(testDir)
-
-       var errorsReceived counter
-       // Receive errors on the error channel on a separate goroutine
-       go func() {
-               for errors := range watcher.Errors {
-                       t.Logf("Received error: %s", errors)
-                       errorsReceived.increment()
-               }
-       }()
-
-       // Count the CREATE events received
-       var createEventsReceived, otherEventsReceived counter
-       go func() {
-               for ev := range watcher.Events {
-                       t.Logf("event received: %s", ev)
-                       if ev.Op&Create == Create {
-                               createEventsReceived.increment()
-                       } else {
-                               otherEventsReceived.increment()
-                       }
-               }
-       }()
-
-       addWatch(t, watcher, testDir)
-
-       if err := os.Symlink(filepath.Join(testDir, "zzz"), filepath.Join(testDir, "zzznew")); err != nil {
-               t.Fatalf("Failed to create bogus symlink: %s", err)
-       }
-       t.Logf("Created bogus symlink")
-
-       // We expect this event to be received almost immediately, but let's wait 500 ms to be sure
-       time.Sleep(500 * time.Millisecond)
-
-       // Should not be error, just no events for broken links (watching nothing)
-       if errorsReceived.value() > 0 {
-               t.Fatal("fsnotify errors have been received.")
-       }
-       if otherEventsReceived.value() > 0 {
-               t.Fatal("fsnotify other events received on the broken link")
-       }
-
-       // Except for 1 create event (for the link itself)
-       if createEventsReceived.value() == 0 {
-               t.Fatal("fsnotify create events were not received after 500 ms")
-       }
-       if createEventsReceived.value() > 1 {
-               t.Fatal("fsnotify more create events received than expected")
-       }
-
-       // Try closing the fsnotify instance
-       t.Log("calling Close()")
-       watcher.Close()
-}
index 1361071d16c69ac9f864fcbbe06f373ccd0d666a..ad51ab60b2212783e101e1c57332a767534954a3 100644 (file)
@@ -1001,6 +1001,114 @@ func TestFsnotifyClose(t *testing.T) {
        }
 }
 
+func TestFsnotifyFakeSymlink(t *testing.T) {
+       if runtime.GOOS == "windows" {
+               t.Skip("symlinks don't work on Windows.")
+       }
+
+       watcher := newWatcher(t)
+
+       // Create directory to watch
+       testDir := tempMkdir(t)
+       defer os.RemoveAll(testDir)
+
+       var errorsReceived counter
+       // Receive errors on the error channel on a separate goroutine
+       go func() {
+               for errors := range watcher.Errors {
+                       t.Logf("Received error: %s", errors)
+                       errorsReceived.increment()
+               }
+       }()
+
+       // Count the CREATE events received
+       var createEventsReceived, otherEventsReceived counter
+       go func() {
+               for ev := range watcher.Events {
+                       t.Logf("event received: %s", ev)
+                       if ev.Op&Create == Create {
+                               createEventsReceived.increment()
+                       } else {
+                               otherEventsReceived.increment()
+                       }
+               }
+       }()
+
+       addWatch(t, watcher, testDir)
+
+       if err := os.Symlink(filepath.Join(testDir, "zzz"), filepath.Join(testDir, "zzznew")); err != nil {
+               t.Fatalf("Failed to create bogus symlink: %s", err)
+       }
+       t.Logf("Created bogus symlink")
+
+       // We expect this event to be received almost immediately, but let's wait 500 ms to be sure
+       time.Sleep(500 * time.Millisecond)
+
+       // Should not be error, just no events for broken links (watching nothing)
+       if errorsReceived.value() > 0 {
+               t.Fatal("fsnotify errors have been received.")
+       }
+       if otherEventsReceived.value() > 0 {
+               t.Fatal("fsnotify other events received on the broken link")
+       }
+
+       // Except for 1 create event (for the link itself)
+       if createEventsReceived.value() == 0 {
+               t.Fatal("fsnotify create events were not received after 500 ms")
+       }
+       if createEventsReceived.value() > 1 {
+               t.Fatal("fsnotify more create events received than expected")
+       }
+
+       // Try closing the fsnotify instance
+       t.Log("calling Close()")
+       watcher.Close()
+}
+
+// TestConcurrentRemovalOfWatch tests that concurrent calls to RemoveWatch do not race.
+// See https://codereview.appspot.com/103300045/
+// go test -test.run=TestConcurrentRemovalOfWatch -test.cpu=1,1,1,1,1 -race
+func TestConcurrentRemovalOfWatch(t *testing.T) {
+       if runtime.GOOS != "darwin" {
+               t.Skip("regression test for race only present on darwin")
+       }
+
+       // Create directory to watch
+       testDir := tempMkdir(t)
+       defer os.RemoveAll(testDir)
+
+       // Create a file before watching directory
+       testFileAlreadyExists := filepath.Join(testDir, "TestFsnotifyEventsExisting.testfile")
+       {
+               var f *os.File
+               f, err := os.OpenFile(testFileAlreadyExists, os.O_WRONLY|os.O_CREATE, 0666)
+               if err != nil {
+                       t.Fatalf("creating test file failed: %s", err)
+               }
+               f.Sync()
+               f.Close()
+       }
+
+       watcher := newWatcher(t)
+       defer watcher.Close()
+
+       addWatch(t, watcher, testDir)
+
+       // Test that RemoveWatch can be invoked concurrently, with no data races.
+       removed1 := make(chan struct{})
+       go func() {
+               defer close(removed1)
+               watcher.Remove(testDir)
+       }()
+       removed2 := make(chan struct{})
+       go func() {
+               close(removed2)
+               watcher.Remove(testDir)
+       }()
+       <-removed1
+       <-removed2
+}
+
 func testRename(file1, file2 string) error {
        switch runtime.GOOS {
        case "windows", "plan9":