MCPcopy
hub / github.com/docker/compose / TestGitBranchSwitch

Function TestGitBranchSwitch

pkg/watch/notify_test.go:101–152  ·  view source on GitHub ↗

Simulate a git branch switch that creates a bunch of directories, creates files in them, then deletes them all quickly. Make sure there are no errors.

(t *testing.T)

Source from the content-addressed store, hash-verified

99// of directories, creates files in them, then deletes
100// them all quickly. Make sure there are no errors.
101func TestGitBranchSwitch(t *testing.T) {
102 f := newNotifyFixture(t)
103
104 count := 10
105 dirs := make([]string, count)
106 for i := range dirs {
107 dir := f.TempDir("watched")
108 dirs[i] = dir
109 f.watch(dir)
110 }
111
112 f.fsync()
113 f.events = nil
114
115 // consume all the events in the background
116 ctx, cancel := context.WithCancel(t.Context())
117 done := f.consumeEventsInBackground(ctx)
118
119 for i, dir := range dirs {
120 for j := range count {
121 base := fmt.Sprintf("x/y/dir-%d/x.txt", j)
122 p := filepath.Join(dir, base)
123 f.WriteFile(p, "contents")
124 }
125
126 if i != 0 {
127 err := os.RemoveAll(dir)
128 assert.NilError(t, err)
129 }
130 }
131
132 cancel()
133 err := <-done
134 if err != nil {
135 t.Fatal(err)
136 }
137
138 f.fsync()
139 f.events = nil
140
141 // Make sure the watch on the first dir still works.
142 dir := dirs[0]
143 path := filepath.Join(dir, "change")
144
145 f.WriteFile(path, "hello\n")
146 f.fsync()
147
148 f.assertEvents(path)
149
150 // Make sure there are no errors in the out stream
151 assert.Assert(t, f.out.String() == "")
152}
153
154func TestWatchesAreRecursive(t *testing.T) {
155 f := newNotifyFixture(t)

Callers

nothing calls this directly

Calls 9

newNotifyFixtureFunction · 0.85
TempDirMethod · 0.80
fsyncMethod · 0.80
WriteFileMethod · 0.80
RemoveAllMethod · 0.80
assertEventsMethod · 0.80
watchMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected