Debian Codegraph @

watcher_fen_test.go

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