OSDN Git Service

new repo
[bytom/vapor.git] / vendor / github.com / rjeczalik / notify / tree_nonrecursive_test.go
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 package notify
6
7 import (
8         "fmt"
9         "testing"
10 )
11
12 func TestNonrecursiveTree(t *testing.T) {
13         n := NewNonrecursiveTreeTest(t, "testdata/vfs.txt")
14         defer n.Close()
15
16         ch := NewChans(5)
17
18         watches := [...]RCase{
19                 // i=0
20                 {
21                         Call: Call{
22                                 F: FuncWatch,
23                                 P: "src/github.com/rjeczalik/fs/fs.go",
24                                 C: ch[0],
25                                 E: Rename,
26                         },
27                         Record: []Call{
28                                 {
29                                         F: FuncWatch,
30                                         P: "src/github.com/rjeczalik/fs/fs.go",
31                                         E: Rename,
32                                 },
33                         },
34                 },
35                 // i=1
36                 {
37                         Call: Call{
38                                 F: FuncWatch,
39                                 P: "src/github.com/rjeczalik/fs/cmd/...",
40                                 C: ch[1],
41                                 E: Remove,
42                         },
43                         Record: []Call{
44                                 {
45                                         F: FuncWatch,
46                                         P: "src/github.com/rjeczalik/fs/cmd",
47                                         E: Create | Remove,
48                                 },
49                                 {
50                                         F: FuncWatch,
51                                         P: "src/github.com/rjeczalik/fs/cmd/gotree",
52                                         E: Create | Remove,
53                                 },
54                                 {
55                                         F: FuncWatch,
56                                         P: "src/github.com/rjeczalik/fs/cmd/mktree",
57                                         E: Create | Remove,
58                                 },
59                         },
60                 },
61                 // i=2
62                 {
63                         Call: Call{
64                                 F: FuncWatch,
65                                 P: "src/github.com/rjeczalik/fs/cmd/...",
66                                 C: ch[2],
67                                 E: Rename,
68                         },
69                         Record: []Call{
70                                 {
71                                         F:  FuncRewatch,
72                                         P:  "src/github.com/rjeczalik/fs/cmd",
73                                         E:  Create | Remove,
74                                         NE: Create | Remove | Rename,
75                                 },
76                                 {
77                                         F:  FuncRewatch,
78                                         P:  "src/github.com/rjeczalik/fs/cmd/gotree",
79                                         E:  Create | Remove,
80                                         NE: Create | Remove | Rename,
81                                 },
82                                 {
83                                         F:  FuncRewatch,
84                                         P:  "src/github.com/rjeczalik/fs/cmd/mktree",
85                                         E:  Create | Remove,
86                                         NE: Create | Remove | Rename,
87                                 },
88                         },
89                 },
90                 // i=3
91                 {
92                         Call: Call{
93                                 F: FuncWatch,
94                                 P: "src/github.com/rjeczalik/fs/cmd/mktree/...",
95                                 C: ch[2],
96                                 E: Write,
97                         },
98                         Record: []Call{
99                                 {
100                                         F:  FuncRewatch,
101                                         P:  "src/github.com/rjeczalik/fs/cmd/mktree",
102                                         E:  Create | Remove | Rename,
103                                         NE: Create | Remove | Rename | Write,
104                                 },
105                         },
106                 },
107                 // i=4
108                 {
109                         Call: Call{
110                                 F: FuncWatch,
111                                 P: "src/github.com/pblaszczyk/qttu/include",
112                                 C: ch[3],
113                                 E: Create,
114                         },
115                         Record: []Call{
116                                 {
117                                         F: FuncWatch,
118                                         P: "src/github.com/pblaszczyk/qttu/include",
119                                         E: Create,
120                                 },
121                         },
122                 },
123                 // i=5
124                 {
125                         Call: Call{
126                                 F: FuncWatch,
127                                 P: "src/github.com/pblaszczyk/qttu/include/qttu/detail/...",
128                                 C: ch[3],
129                                 E: Write,
130                         },
131                         Record: []Call{
132                                 {
133                                         F: FuncWatch,
134                                         P: "src/github.com/pblaszczyk/qttu/include/qttu/detail",
135                                         E: Create | Write,
136                                 },
137                         },
138                 },
139                 // i=6
140                 {
141                         Call: Call{
142                                 F: FuncWatch,
143                                 P: "src/github.com/pblaszczyk/qttu/include/...",
144                                 C: ch[0],
145                                 E: Rename,
146                         },
147                         Record: []Call{
148                                 {
149                                         F:  FuncRewatch,
150                                         P:  "src/github.com/pblaszczyk/qttu/include",
151                                         E:  Create,
152                                         NE: Create | Rename,
153                                 },
154                                 {
155                                         F: FuncWatch,
156                                         P: "src/github.com/pblaszczyk/qttu/include/qttu",
157                                         E: Create | Rename,
158                                 },
159                                 {
160                                         F:  FuncRewatch,
161                                         P:  "src/github.com/pblaszczyk/qttu/include/qttu/detail",
162                                         E:  Create | Write,
163                                         NE: Create | Write | Rename,
164                                 },
165                         },
166                 },
167                 // i=7
168                 {
169                         Call: Call{
170                                 F: FuncWatch,
171                                 P: "src/github.com/pblaszczyk/...",
172                                 C: ch[1],
173                                 E: Write,
174                         },
175                         Record: []Call{
176                                 {
177                                         F: FuncWatch,
178                                         P: "src/github.com/pblaszczyk",
179                                         E: Create | Write,
180                                 },
181                                 {
182                                         F: FuncWatch,
183                                         P: "src/github.com/pblaszczyk/qttu",
184                                         E: Create | Write,
185                                 },
186                                 {
187                                         F:  FuncRewatch,
188                                         P:  "src/github.com/pblaszczyk/qttu/include",
189                                         E:  Create | Rename,
190                                         NE: Create | Rename | Write,
191                                 },
192                                 {
193                                         F:  FuncRewatch,
194                                         P:  "src/github.com/pblaszczyk/qttu/include/qttu",
195                                         E:  Create | Rename,
196                                         NE: Create | Rename | Write,
197                                 },
198                                 {
199                                         F: FuncWatch,
200                                         P: "src/github.com/pblaszczyk/qttu/src",
201                                         E: Create | Write,
202                                 },
203                         },
204                 },
205                 // i=8
206                 {
207                         Call: Call{
208                                 F: FuncWatch,
209                                 P: "src/github.com/pblaszczyk/qttu/include/...",
210                                 C: ch[4],
211                                 E: Write,
212                         },
213                         Record: nil,
214                 },
215                 // i=9
216                 {
217                         Call: Call{
218                                 F: FuncWatch,
219                                 P: "src/github.com/pblaszczyk/qttu",
220                                 C: ch[3],
221                                 E: Remove,
222                         },
223                         Record: []Call{
224                                 {
225                                         F:  FuncRewatch,
226                                         P:  "src/github.com/pblaszczyk/qttu",
227                                         E:  Create | Write,
228                                         NE: Create | Write | Remove,
229                                 },
230                         },
231                 },
232         }
233
234         n.ExpectRecordedCalls(watches[:])
235
236         events := [...]TCase{
237                 // i=0
238                 {
239                         Event:    Call{P: "src/github.com/rjeczalik/fs/fs.go", E: Rename},
240                         Receiver: Chans{ch[0]},
241                 },
242                 // i=1
243                 {
244                         Event:    Call{P: "src/github.com/rjeczalik/fs/fs.go", E: Create},
245                         Receiver: nil,
246                 },
247                 // i=2
248                 {
249                         Event:    Call{P: "src/github.com/rjeczalik/fs/cmd/cmd.go", E: Remove},
250                         Receiver: Chans{ch[1]},
251                 },
252                 // i=3
253                 {
254                         Event:    Call{P: "src/github.com/rjeczalik/fs/cmd/doc.go", E: Write},
255                         Receiver: nil,
256                 },
257                 // i=4
258                 {
259                         Event:    Call{P: "src/github.com/rjeczalik/fs/cmd/mktree/main.go", E: Write},
260                         Receiver: Chans{ch[2]},
261                 },
262                 // i=5
263                 {
264                         Event:    Call{P: "src/github.com/rjeczalik/fs/cmd/mktree/tree.go", E: Create},
265                         Receiver: nil,
266                 },
267                 // i=6
268                 {
269                         Event:    Call{P: "src/github.com/pblaszczyk/qttu/include/.lock", E: Create},
270                         Receiver: Chans{ch[3]},
271                 },
272                 // i=7
273                 {
274                         Event:    Call{P: "src/github.com/pblaszczyk/qttu/include/qttu/detail/registry.hh", E: Write},
275                         Receiver: Chans{ch[3], ch[1], ch[4]},
276                 },
277                 // i=8
278                 {
279                         Event:    Call{P: "src/github.com/pblaszczyk/qttu/include/qttu", E: Remove},
280                         Receiver: nil,
281                 },
282                 // i=9
283                 {
284                         Event:    Call{P: "src/github.com/pblaszczyk/qttu/include", E: Remove},
285                         Receiver: Chans{ch[3]},
286                 },
287         }
288
289         n.ExpectTreeEvents(events[:], ch)
290
291         stops := [...]RCase{
292                 // i=0
293                 {
294                         Call: Call{
295                                 F: FuncStop,
296                                 C: ch[4],
297                         },
298                         Record: nil,
299                 },
300                 // i=1
301                 {
302                         Call: Call{
303                                 F: FuncStop,
304                                 C: ch[3],
305                         },
306                         Record: []Call{
307                                 {
308                                         F:  FuncRewatch,
309                                         P:  "src/github.com/pblaszczyk/qttu",
310                                         E:  Create | Write | Remove,
311                                         NE: Create | Write,
312                                 },
313                         },
314                 },
315                 // i=2
316                 {
317                         Call: Call{
318                                 F: FuncStop,
319                                 C: ch[2],
320                         },
321                         Record: []Call{
322                                 {
323                                         F:  FuncRewatch,
324                                         P:  "src/github.com/rjeczalik/fs/cmd",
325                                         E:  Create | Remove | Rename,
326                                         NE: Create | Remove,
327                                 },
328                                 {
329                                         F:  FuncRewatch,
330                                         P:  "src/github.com/rjeczalik/fs/cmd/gotree",
331                                         E:  Create | Remove | Rename,
332                                         NE: Create | Remove,
333                                 },
334                                 {
335                                         F:  FuncRewatch,
336                                         P:  "src/github.com/rjeczalik/fs/cmd/mktree",
337                                         E:  Create | Remove | Rename | Write,
338                                         NE: Create | Remove,
339                                 },
340                         },
341                 },
342                 // i=3
343                 {
344                         Call: Call{
345                                 F: FuncStop,
346                                 C: ch[1],
347                         },
348                         Record: []Call{
349                                 {
350                                         F: FuncUnwatch,
351                                         P: "src/github.com/pblaszczyk",
352                                 },
353                                 {
354                                         F: FuncUnwatch,
355                                         P: "src/github.com/pblaszczyk/qttu",
356                                 },
357                                 {
358                                         F:  FuncRewatch,
359                                         P:  "src/github.com/pblaszczyk/qttu/include",
360                                         E:  Create | Rename | Write,
361                                         NE: Create | Rename,
362                                 },
363                                 {
364                                         F:  FuncRewatch,
365                                         P:  "src/github.com/pblaszczyk/qttu/include/qttu",
366                                         E:  Create | Rename | Write,
367                                         NE: Create | Rename,
368                                 },
369                                 {
370                                         F:  FuncRewatch,
371                                         P:  "src/github.com/pblaszczyk/qttu/include/qttu/detail",
372                                         E:  Create | Rename | Write,
373                                         NE: Create | Rename,
374                                 },
375                                 {
376                                         F: FuncUnwatch,
377                                         P: "src/github.com/pblaszczyk/qttu/src",
378                                 },
379                                 {
380                                         F: FuncUnwatch,
381                                         P: "src/github.com/rjeczalik/fs/cmd",
382                                 },
383                                 {
384                                         F: FuncUnwatch,
385                                         P: "src/github.com/rjeczalik/fs/cmd/gotree",
386                                 },
387                                 {
388                                         F: FuncUnwatch,
389                                         P: "src/github.com/rjeczalik/fs/cmd/mktree",
390                                 },
391                         },
392                 },
393                 // i=4
394                 {
395                         Call: Call{
396                                 F: FuncStop,
397                                 C: ch[0],
398                         },
399                         Record: []Call{
400                                 {
401                                         F: FuncUnwatch,
402                                         P: "src/github.com/pblaszczyk/qttu/include",
403                                 },
404                                 {
405                                         F: FuncUnwatch,
406                                         P: "src/github.com/pblaszczyk/qttu/include/qttu",
407                                 },
408                                 {
409                                         F: FuncUnwatch,
410                                         P: "src/github.com/pblaszczyk/qttu/include/qttu/detail",
411                                 },
412                                 {
413                                         F: FuncUnwatch,
414                                         P: "src/github.com/rjeczalik/fs/fs.go",
415                                 },
416                         },
417                 },
418         }
419
420         n.ExpectRecordedCalls(stops[:])
421
422         n.Walk(func(nd node) error {
423                 if len(nd.Watch) != 0 {
424                         return fmt.Errorf("unexpected watchpoint: name=%s, eventset=%v (len=%d)",
425                                 nd.Name, nd.Watch.Total(), len(nd.Watch))
426                 }
427                 return nil
428         })
429 }
430
431 func TestNonrecursiveTreeInternal(t *testing.T) {
432         n, c := NewNonrecursiveTreeTestC(t, "testdata/vfs.txt")
433         defer n.Close()
434
435         ch := NewChans(5)
436
437         watches := [...]RCase{
438                 // i=0
439                 {
440                         Call: Call{
441                                 F: FuncWatch,
442                                 P: "src/github.com/rjeczalik/fs/cmd/...",
443                                 C: ch[0],
444                                 E: Remove,
445                         },
446                         Record: []Call{
447                                 {
448                                         F: FuncWatch,
449                                         P: "src/github.com/rjeczalik/fs/cmd",
450                                         E: Create | Remove,
451                                 },
452                                 {
453                                         F: FuncWatch,
454                                         P: "src/github.com/rjeczalik/fs/cmd/gotree",
455                                         E: Create | Remove,
456                                 },
457                                 {
458                                         F: FuncWatch,
459                                         P: "src/github.com/rjeczalik/fs/cmd/mktree",
460                                         E: Create | Remove,
461                                 },
462                         },
463                 },
464                 // i=1
465                 {
466                         Call: Call{
467                                 F: FuncWatch,
468                                 P: "src/github.com/ppknap/link/include/coost/...",
469                                 C: ch[1],
470                                 E: Create,
471                         },
472                         Record: []Call{
473                                 {
474                                         F: FuncWatch,
475                                         P: "src/github.com/ppknap/link/include/coost",
476                                         E: Create,
477                                 },
478                                 {
479                                         F: FuncWatch,
480                                         P: "src/github.com/ppknap/link/include/coost/link",
481                                         E: Create,
482                                 },
483                                 {
484                                         F: FuncWatch,
485                                         P: "src/github.com/ppknap/link/include/coost/link/detail",
486                                         E: Create,
487                                 },
488                                 {
489                                         F: FuncWatch,
490                                         P: "src/github.com/ppknap/link/include/coost/link/detail/stdhelpers",
491                                         E: Create,
492                                 },
493                         },
494                 },
495         }
496
497         n.ExpectRecordedCalls(watches[:])
498
499         events := [...]TCase{
500                 // i=0
501                 {
502                         Event:    Call{P: "src/github.com/rjeczalik/fs/cmd/dir", E: Create, Dir: true},
503                         Receiver: Chans{c},
504                 },
505                 // i=1
506                 {
507                         Event:    Call{P: "src/github.com/rjeczalik/fs/cmd/dir/another", E: Create, Dir: true},
508                         Receiver: Chans{c},
509                 },
510                 // i=2
511                 {
512                         Event:    Call{P: "src/github.com/rjeczalik/fs/cmd/file", E: Create, Dir: false},
513                         Receiver: nil,
514                 },
515                 // i=3
516                 {
517                         Event:    Call{P: "src/github.com/ppknap/link/include/coost/dir", E: Create, Dir: true},
518                         Receiver: Chans{ch[1], c},
519                 },
520                 // i=4
521                 {
522                         Event:    Call{P: "src/github.com/ppknap/link/include/coost/dir/another", E: Create, Dir: true},
523                         Receiver: Chans{ch[1], c},
524                 },
525                 // i=5
526                 {
527                         Event:    Call{P: "src/github.com/ppknap/link/include/coost/file", E: Create, Dir: false},
528                         Receiver: Chans{ch[1]},
529                 },
530                 // i=6
531                 {
532                         Event:    Call{P: "src/github.com/rjeczalik/fs/cmd/mktree", E: Remove},
533                         Receiver: Chans{ch[0]},
534                 },
535                 // i=7
536                 {
537                         Event:    Call{P: "src/github.com/rjeczalik/fs/cmd/rmtree", E: Create, Dir: true},
538                         Receiver: Chans{c},
539                 },
540         }
541
542         n.ExpectTreeEvents(events[:], ch)
543 }