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