This file is indexed.

/usr/share/gocode/src/github.com/smartystreets/goconvey/web/server/watch/functional_core_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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
package watch

import (
	"fmt"
	"testing"

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

func TestCategorize(t *testing.T) {
	fileSystem := []*FileSystemItem{
		{
			Root:     "/.hello",
			Path:     "/.hello",
			Name:     "hello",
			IsFolder: true,
		},
		{
			Root:     "/.hello",
			Path:     "/.hello/1/hello/world.txt",
			Name:     "world.txt",
			IsFolder: false,
		},
		{
			Root:     "/.hello",
			Path:     "/.hello/1/2/3/4/5/hello/world.go",
			Name:     "world.go",
			IsFolder: false,
		},
		{
			Root:     "/.hello",
			Path:     "/.hello/world.go",
			Name:     "world.go",
			IsFolder: false,
		},
		{
			Root:     "/.hello",
			Path:     "/.hello/hello/world.tmpl",
			Name:     "world.tmpl",
			IsFolder: false,
		},
		{
			Root:     "/.hello",
			Path:     "/.hello/hello/.world.go",
			Name:     ".world.go",
			IsFolder: false,
		},
		{
			Root:     "/.hello",
			Path:     "/.hello/hello/_world.go",
			Name:     ".world.go",
			IsFolder: false,
		},
		{
			Root:     "/.hello",
			Path:     "/.hello/hello/flymake_world.go",
			Name:     "flymake_world.go",
			IsFolder: false,
		},
		{
			Root:     "/.hello",
			Path:     "/.hello/.hello",
			Name:     ".hello",
			IsFolder: true,
		},
		{
			Root:     "/.hello",
			Path:     "/.hello/.hello/hello",
			Name:     "hello",
			IsFolder: true,
		},
		{
			Root:     "/.hello",
			Path:     "/.hello/.hello/world.go",
			Name:     "world.go",
			IsFolder: false,
		},
		{
			Root:     "/.hello",
			Path:     "/.hello/hello/hi.goconvey",
			Name:     "hi.goconvey",
			IsFolder: false,
		},
		{
			Root:     "/.hello",
			Path:     "/.hello/hello2/.goconvey",
			Name:     ".goconvey",
			IsFolder: false,
		},
		{
			Root:     "/.hello",
			Path:     "/.hello/_hello",
			Name:     "_hello",
			IsFolder: true,
		},
	}

	Convey("A stream of file system items should be categorized correctly", t, func() {
		items := make(chan *FileSystemItem)

		go func() {
			for _, item := range fileSystem {
				items <- item
			}
			close(items)
		}()

		folders, profiles, goFiles := Categorize(items, "/.hello", []string{".go"})
		So(folders, ShouldResemble, fileSystem[:1])
		So(profiles, ShouldResemble, fileSystem[11:12])
		So(goFiles, ShouldResemble, fileSystem[2:4])
	})

	Convey("A stream of file system items should be categorized correctly", t, func() {
		items := make(chan *FileSystemItem)

		go func() {
			for _, item := range fileSystem {
				items <- item
			}
			close(items)
		}()

		folders, profiles, goFiles := Categorize(items, "/.hello", []string{".go", ".tmpl"})
		So(folders, ShouldResemble, fileSystem[:1])
		So(profiles, ShouldResemble, fileSystem[11:12])
		So(goFiles, ShouldResemble, fileSystem[2:5])
	})
}

func TestParseProfile(t *testing.T) {
	var parseProfileTestCases = []struct {
		SKIP           bool
		description    string
		input          string
		resultIgnored  bool
		resultTestTags []string
		resultTestArgs []string
	}{
		{
			SKIP:          false,
			description:   "Blank profile",
			input:         "",
			resultIgnored: false,
		},
		{
			SKIP:          false,
			description:   "All lines are blank or whitespace",
			input:         "\n \n \t\t\t  \n \n \n",
			resultIgnored: false,
		},
		{
			SKIP:          false,
			description:   "Ignored package, no args included",
			input:         "IGNORE\n-timeout=4s",
			resultIgnored: true,
		},
		{
			SKIP:           false,
			description:    "Ignore directive is commented, all args are included",
			input:          "#IGNORE\n-timeout=4s\n-parallel=5",
			resultIgnored:  false,
			resultTestArgs: []string{"-timeout=4s", "-parallel=5"},
		},
		{
			SKIP:           false,
			description:    "No ignore directive, all args are included",
			input:          "-run=TestBlah\n-timeout=42s",
			resultIgnored:  false,
			resultTestArgs: []string{"-run=TestBlah", "-timeout=42s"},
		},
		{
			SKIP:           false,
			description:    "Some args are commented, therefore ignored",
			input:          "-run=TestBlah\n #-timeout=42s",
			resultIgnored:  false,
			resultTestArgs: []string{"-run=TestBlah"},
		},
		{
			SKIP:          false,
			description:   "All args are commented, therefore all are ignored",
			input:         "#-run=TestBlah\n//-timeout=42",
			resultIgnored: false,
		},
		{
			SKIP:          false,
			description:   "We ignore certain flags like -v and -cover and -coverprofile because they are specified by the shell",
			input:         "-v\n-cover\n-coverprofile=blah.out",
			resultIgnored: false,
		},
		{
			SKIP:           false,
			description:    "We allow certain coverage flags like -coverpkg and -covermode",
			input:          "-coverpkg=blah\n-covermode=atomic",
			resultIgnored:  false,
			resultTestArgs: []string{"-coverpkg=blah", "-covermode=atomic"},
		},
		{
			SKIP:           false,
			description:    "We parse out -tags particularly",
			input:          "-coverpkg=blah\n-covermode=atomic\n-tags=foo,bar",
			resultIgnored:  false,
			resultTestTags: []string{"foo", "bar"},
			resultTestArgs: []string{"-coverpkg=blah", "-covermode=atomic"},
		},
	}

	for i, test := range parseProfileTestCases {
		if test.SKIP {
			SkipConvey(fmt.Sprintf("Profile Parsing, Test Case #%d: %s (SKIPPED)", i, test.description), t, nil)
		} else {
			Convey(fmt.Sprintf("Profile Parsing, Test Case #%d: %s", i, test.description), t, func() {
				ignored, testTags, testArgs := ParseProfile(test.input)

				So(ignored, ShouldEqual, test.resultIgnored)
				So(testTags, ShouldResemble, test.resultTestTags)
				So(testArgs, ShouldResemble, test.resultTestArgs)
			})
		}
	}
}

func TestCreateFolders(t *testing.T) {
	Convey("File system items that represent folders should be converted to folder structs correctly", t, func() {
		expected := map[string]*messaging.Folder{
			"/root/1":     {Path: "/root/1", Root: "/root"},
			"/root/1/2":   {Path: "/root/1/2", Root: "/root"},
			"/root/1/2/3": {Path: "/root/1/2/3", Root: "/root"},
		}

		inputs := []*FileSystemItem{
			{Path: "/root/1", Root: "/root", IsFolder: true},
			{Path: "/root/1/2", Root: "/root", IsFolder: true},
			{Path: "/root/1/2/3", Root: "/root", IsFolder: true},
		}

		actual := CreateFolders(inputs)

		for key, actualValue := range actual {
			So(actualValue, ShouldResemble, expected[key])
		}
	})
}

func TestLimitDepth(t *testing.T) {
	Convey("Subject: Limiting folders based on relative depth from a common root", t, func() {

		folders := map[string]*messaging.Folder{
			"/root/1": {
				Path: "/root/1",
				Root: "/root",
			},
			"/root/1/2": {
				Path: "/root/1/2",
				Root: "/root",
			},
			"/root/1/2/3": {
				Path: "/root/1/2/3",
				Root: "/root",
			},
		}

		Convey("When there is no depth limit", func() {
			LimitDepth(folders, -1)

			Convey("No folders should be excluded", func() {
				So(len(folders), ShouldEqual, 3)
			})
		})

		Convey("When there is a limit", func() {
			LimitDepth(folders, 2)

			Convey("The deepest folder (in this case) should be excluded", func() {
				So(len(folders), ShouldEqual, 2)
				_, exists := folders["/root/1/2/3"]
				So(exists, ShouldBeFalse)
			})
		})
	})
}

func TestAttachProfiles(t *testing.T) {
	Convey("Subject: Attaching profile information to a folder", t, func() {
		folders := map[string]*messaging.Folder{
			"/root/1": {
				Path: "/root/1",
				Root: "/root",
			},
			"/root/1/2": {
				Path: "/root/1/2",
				Root: "/root",
			},
			"/root/1/2/3": {
				Path: "/root/1/2/3",
				Root: "/root",
			},
		}

		profiles := []*FileSystemItem{
			{
				Path:             "/root/too-shallow.goconvey",
				ProfileDisabled:  true,
				ProfileArguments: []string{"1", "2"},
			},
			{
				Path:             "/root/1/2/hi.goconvey",
				ProfileDisabled:  true,
				ProfileArguments: []string{"1", "2"},
			},
			{
				Path:             "/root/1/2/3/4/does-not-exist",
				ProfileDisabled:  true,
				ProfileArguments: []string{"1", "2", "3", "4"},
			},
		}

		Convey("Profiles that match folders should be merged with those folders", func() {
			AttachProfiles(folders, profiles)

			Convey("No profiles matched the first folder, so no assignments should occur", func() {
				So(folders["/root/1"].Disabled, ShouldBeFalse)
				So(folders["/root/1"].TestArguments, ShouldBeEmpty)
			})

			Convey("The second folder should match the first profile", func() {
				So(folders["/root/1/2"].Disabled, ShouldBeTrue)
				So(folders["/root/1/2"].TestArguments, ShouldResemble, []string{"1", "2"})
			})

			Convey("No profiles match the third folder so no assignments should occur", func() {
				So(folders["/root/1/2/3"].Disabled, ShouldBeFalse)
				So(folders["/root/1/2/3"].TestArguments, ShouldBeEmpty)
			})
		})
	})
}

func TestMarkIgnored(t *testing.T) {
	Convey("Subject: folders that have been ignored should be marked as such", t, func() {
		folders := map[string]*messaging.Folder{
			"/root/1": {
				Path: "/root/1",
				Root: "/root",
			},
			"/root/1/2": {
				Path: "/root/1/2",
				Root: "/root",
			},
			"/root/1/2/3": {
				Path: "/root/1/2/3",
				Root: "/root",
			},
		}

		Convey("When there are no ignored folders", func() {
			ignored := map[string]struct{}{}
			MarkIgnored(folders, ignored)

			Convey("No folders should be marked as ignored", func() {
				So(folders["/root/1"].Ignored, ShouldBeFalse)
				So(folders["/root/1/2"].Ignored, ShouldBeFalse)
				So(folders["/root/1/2/3"].Ignored, ShouldBeFalse)
			})
		})
		Convey("When there are ignored folders", func() {
			ignored := map[string]struct{}{"1/2": {}}
			MarkIgnored(folders, ignored)

			Convey("The ignored folders should be marked as ignored", func() {
				So(folders["/root/1"].Ignored, ShouldBeFalse)
				So(folders["/root/1/2"].Ignored, ShouldBeTrue)
				So(folders["/root/1/2/3"].Ignored, ShouldBeFalse)
			})
		})
	})
}

func TestActiveFolders(t *testing.T) {
	Convey("Subject: Folders that are not ignored or disabled are active", t, func() {
		folders := map[string]*messaging.Folder{
			"/root/1": {
				Path:    "/root/1",
				Root:    "/root",
				Ignored: true,
			},
			"/root/1/2": {
				Path: "/root/1/2",
				Root: "/root",
			},
			"/root/1/2/3": {
				Path:     "/root/1/2/3",
				Root:     "/root",
				Disabled: true,
			},
		}

		active := ActiveFolders(folders)

		So(len(active), ShouldEqual, 1)
		So(active["/root/1/2"], ShouldResemble, folders["/root/1/2"])
	})
}

func TestSum(t *testing.T) {
	Convey("Subject: file system items within specified directores should be counted and summed", t, func() {
		folders := map[string]*messaging.Folder{
			"/root/1": {Path: "/root/1", Root: "/root", Ignored: true},
		}
		items := []*FileSystemItem{
			{Size: 1, Modified: 3, Path: "/root/1/hi.go"},
			{Size: 7, Modified: 13, Path: "/root/1/bye.go"},
			{Size: 33, Modified: 45, Path: "/root/1/2/salutations.go"}, // not counted
		}

		So(Sum(folders, items), ShouldEqual, 1+3+7+13)
	})
}