github.com/misseven0/notify@v0.0.0-20230519123055-c1422e46da05/watcher_fen_test.go (about) 1 // Copyright (c) 2014-2015 The Notify Authors. All rights reserved. 2 // Use of this source code is governed by the MIT license that can be 3 // found in the LICENSE file. 4 5 //go:build solaris || illumos 6 // +build solaris illumos 7 8 package notify 9 10 import ( 11 "os" 12 "path/filepath" 13 "testing" 14 ) 15 16 func fremove(w *W, path string, files []string) WCase { 17 cas := remove(w, path) 18 cas.Events[0] = &Call{P: path, E: FileDelete} 19 for _, f := range files { 20 cas.Events = append(cas.Events, &Call{P: f, E: FileDelete}) 21 } 22 return cas 23 } 24 25 func fwrite(w *W, path string, p []byte) WCase { 26 cas := write(w, path, p) 27 path = cas.Events[0].Path() 28 cas.Events[0] = &Call{P: path, E: FileModified} 29 return cas 30 } 31 32 func frename(w *W, path string, files []string) WCase { 33 const ext = ".notify" 34 cas := WCase{ 35 Action: func() { 36 file := filepath.Join(w.root, path) 37 if err := os.Rename(file, file+ext); err != nil { 38 w.Fatalf("Rename(%q, %q)=%v", path, path+ext, err) 39 } 40 }, 41 Events: []EventInfo{ 42 &Call{P: path + ext, E: osSpecificCreate}, 43 &Call{P: path, E: FileRenameFrom}, 44 }, 45 } 46 for _, f := range files { 47 cas.Events = append(cas.Events, &Call{P: f, E: FileRenameFrom}) 48 } 49 return cas 50 } 51 52 var events = []Event{ 53 FileModified, 54 FileAttrib, 55 FileRenameFrom, 56 osSpecificCreate, 57 FileDelete, 58 } 59 60 func TestWatcherFen(t *testing.T) { 61 w := NewWatcherTest(t, "testdata/vfs.txt", events...) 62 defer w.Close() 63 64 cases := [...]WCase{ 65 fremove(w, "src/github.com/ppknap/link/include/coost/link", []string{ 66 "src/github.com/ppknap/link/include/coost/link/definitions.hpp", 67 "src/github.com/ppknap/link/include/coost/link/detail/bundle.hpp", 68 "src/github.com/ppknap/link/include/coost/link/detail/container_invoker.hpp", 69 "src/github.com/ppknap/link/include/coost/link/detail/container_value_trait.hpp", 70 "src/github.com/ppknap/link/include/coost/link/detail/dummy_type.hpp", 71 "src/github.com/ppknap/link/include/coost/link/detail/function_trait.hpp", 72 "src/github.com/ppknap/link/include/coost/link/detail/immediate_invoker.hpp", 73 "src/github.com/ppknap/link/include/coost/link/detail/stdhelpers/always_same.hpp", 74 "src/github.com/ppknap/link/include/coost/link/detail/stdhelpers/make_unique.hpp", 75 "src/github.com/ppknap/link/include/coost/link/detail/stdhelpers", 76 "src/github.com/ppknap/link/include/coost/link/detail/vertex.hpp", 77 "src/github.com/ppknap/link/include/coost/link/detail/wire.hpp", 78 "src/github.com/ppknap/link/include/coost/link/detail", 79 "src/github.com/ppknap/link/include/coost/link/link.hpp", 80 }, 81 ), 82 fwrite(w, "src/github.com/rjeczalik/fs/fs.go", []byte("XD")), 83 fremove(w, "src/github.com/ppknap/link/README.md", nil), 84 frename(w, "src/github.com/rjeczalik/fs/fs.go", nil), 85 frename(w, "src/github.com/rjeczalik/fs/cmd/gotree", []string{ 86 "src/github.com/rjeczalik/fs/cmd/gotree/go.go", 87 "src/github.com/rjeczalik/fs/cmd/gotree/main.go", 88 }, 89 ), 90 } 91 92 w.ExpectAll(cases[:]) 93 }