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