This file is indexed.

/usr/share/gocode/src/github.com/smartystreets/goconvey/web/server/watch/integration_test.go is in golang-github-smartystreets-goconvey-dev 1.6.1-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
package watch

import (
	"bytes"
	"io/ioutil"
	"log"
	"os"
	"os/exec"
	"path/filepath"
	"runtime"
	"testing"
	"time"

	. "github.com/smartystreets/goconvey/convey"
	"github.com/smartystreets/goconvey/web/server/messaging"
)

func TestWatcher(t *testing.T) {
	if testing.Short() {
		t.Skip("Skipping potentially long-running integration test...")
		return
	}

	log.SetFlags(log.LstdFlags | log.Lshortfile | log.Lmicroseconds)
	output := new(bytes.Buffer)
	log.SetOutput(output)
	defer func() { t.Log(output.String()) }()

	_, filename, _, _ := runtime.Caller(0)
	originalRoot := filepath.Join(filepath.Dir(filename), "integration_testing")
	temporary, err := ioutil.TempDir("/tmp", "goconvey")
	if err != nil {
		t.Fatal(err)
	}
	root := filepath.Join(temporary, "integration_testing")
	sub := filepath.Join(root, "sub")

	err = CopyDir(originalRoot, root)
	if err != nil {
		t.Fatal(err)
	}
	defer func() {
		err = os.RemoveAll(temporary)
		if err != nil {
			t.Fatal(err)
		}
	}()

	var ( // commands
		pause  = messaging.WatcherCommand{Instruction: messaging.WatcherPause}
		resume = messaging.WatcherCommand{Instruction: messaging.WatcherResume}

		ignore    = messaging.WatcherCommand{Instruction: messaging.WatcherIgnore, Details: sub}
		reinstate = messaging.WatcherCommand{Instruction: messaging.WatcherReinstate, Details: sub}

		adjustToSub  = messaging.WatcherCommand{Instruction: messaging.WatcherAdjustRoot, Details: sub}
		adjustToRoot = messaging.WatcherCommand{Instruction: messaging.WatcherAdjustRoot, Details: root}

		execute = messaging.WatcherCommand{Instruction: messaging.WatcherExecute}

		bogus = messaging.WatcherCommand{Instruction: 42}

		stop = messaging.WatcherCommand{Instruction: messaging.WatcherStop}
	)

	Convey("Subject: Watcher operations", t, func() {
		input := make(chan messaging.WatcherCommand)
		output := make(chan messaging.Folders)
		excludedDirs := []string{}
		watcher := NewWatcher(root, -1, time.Millisecond, input, output, ".go", excludedDirs)

		go watcher.Listen()

		Convey("Initial scan results", func() {
			go func() { input <- stop }()

			results := []messaging.Folders{}
			for result := range output {
				results = append(results, result)
			}

			So(len(results), ShouldEqual, 1)
		})

		Convey("Manual execution produces additional results", func() {
			go func() {
				input <- execute
				input <- stop
			}()

			results := []messaging.Folders{}
			for result := range output {
				results = append(results, result)
			}

			So(len(results), ShouldEqual, 2)
			So(len(results[0]), ShouldEqual, 2)
			So(len(results[1]), ShouldEqual, 2)
		})

		Convey("Ignore and Reinstate commands are not reflected in the scan results", func() {
			go func() {
				input <- ignore
				input <- reinstate
				input <- stop
			}()

			results := []messaging.Folders{}
			for result := range output {
				results = append(results, result)
			}

			So(len(results), ShouldEqual, 1)
			So(results[0][sub].Ignored, ShouldBeFalse) // initial
		})

		Convey("Adjusting the root changes the number of folders in the scanned results", func() {
			go func() {
				input <- adjustToSub
				input <- adjustToRoot
				input <- stop
			}()

			results := []messaging.Folders{}
			for result := range output {
				results = append(results, result)
			}

			So(len(results), ShouldEqual, 3)
			So(len(results[0]), ShouldEqual, 2) // initial
			So(len(results[1]), ShouldEqual, 1) // root moved to sub
			So(len(results[2]), ShouldEqual, 2) // root moved back to original location
		})

		Convey("A bogus command does not cause any additional scanning beyond the initial scan", func() {
			go func() {
				input <- bogus
				input <- stop
			}()

			results := []messaging.Folders{}
			for result := range output {
				results = append(results, result)
			}

			So(len(results), ShouldEqual, 1) // initial scan
		})

		Convey("Scanning occurs as a result of a file system update", func() {
			go func() {
				time.Sleep(time.Second)
				exec.Command("touch", filepath.Join(root, "main.go")).Run()
				time.Sleep(time.Second)
				input <- stop
			}()

			results := []messaging.Folders{}
			for result := range output {
				results = append(results, result)
			}

			So(len(results), ShouldEqual, 2)
		})

		Convey("Scanning does not occur as a result of resuming after a pause", func() {
			go func() {
				input <- pause
				input <- resume
				input <- stop
			}()

			results := []messaging.Folders{}
			for result := range output {
				results = append(results, result)
			}

			So(len(results), ShouldEqual, 1)
		})

		Convey("Scanning should not occur when the watcher is paused", func() {
			go func() {
				input <- pause
				for x := 0; x < 2; x++ {
					time.Sleep(time.Millisecond * 250)
					exec.Command("touch", filepath.Join(root, "main.go")).Run()
					time.Sleep(time.Millisecond * 250)
				}
				input <- resume
				input <- stop
			}()

			results := []messaging.Folders{}
			for result := range output {
				results = append(results, result)
			}

			So(len(results), ShouldEqual, 2)
		})
	})
}