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