/usr/share/gocode/src/github.com/smartystreets/goconvey/web/server/executor/executor_test.go is in golang-github-smartystreets-goconvey-dev 1.5.0-1.
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 | package executor
import (
"strings"
"testing"
"time"
. "github.com/smartystreets/goconvey/convey"
"github.com/smartystreets/goconvey/web/server/contract"
)
func TestExecutor(t *testing.T) {
var fixture *ExecutorFixture
Convey("Subject: Execution of test packages and aggregation of parsed results", t, func() {
fixture = newExecutorFixture()
Convey("When tests packages are executed", func() {
fixture.ExecuteTests()
Convey("The result should include parsed results for each test package.",
fixture.ResultShouldBePopulated)
})
Convey("When the executor is idle", func() {
Convey("The status of the executor should be 'idle'", func() {
So(fixture.executor.Status(), ShouldEqual, Idle)
})
})
Convey("When the status is updated, the notification channel should have a true value", func() {
fixture.executor.status = Idle
updateCount := 6
for i := 0; i < updateCount; i++ {
fixture.executor.setStatus(statusRotation(i, updateCount))
select {
case val := <-fixture.executor.statusNotif:
So(val, ShouldBeTrue)
default:
So(false, ShouldBeTrue)
}
/*Convey("The status notification channel should have a true value", func() {
// TODO: When issue #81 is fixed and Conveys can be nested
// inside loops agian, I'd rather put the select {...} stuff
// in this convey instead. Also see server_test.go for
// a similar issue.
select {
case val := <-fixture.executor.statusNotif:
So(val, ShouldBeTrue)
default:
fixture.executor.statusNotif <- true
So(false, ShouldBeTrue)
}
})*/
}
})
Convey("During test execution", func() {
status := fixture.CaptureStatusDuringExecutionPhase()
Convey("The status of the executor should be 'executing'", func() {
So(status, ShouldEqual, Executing)
})
})
Convey("During test output parsing", func() {
status := fixture.CaptureStatusDuringParsingPhase()
Convey("The status of the executor should be 'parsing'", func() {
So(status, ShouldEqual, Parsing)
})
})
})
}
func statusRotation(i, total int) string {
switch i % total {
case 0:
return Executing
case 1:
return Parsing
default:
return Idle
}
}
type ExecutorFixture struct {
executor *Executor
tester *FakeTester
parser *FakeParser
folders []*contract.Package
result *contract.CompleteOutput
expected *contract.CompleteOutput
stamp time.Time
}
func (self *ExecutorFixture) ExecuteTests() {
self.result = self.executor.ExecuteTests(self.folders)
}
func (self *ExecutorFixture) CaptureStatusDuringExecutionPhase() string {
nap, _ := time.ParseDuration("25ms")
self.tester.addDelay(nap)
return self.delayedExecution(nap)
}
func (self *ExecutorFixture) CaptureStatusDuringParsingPhase() string {
nap, _ := time.ParseDuration("25ms")
self.parser.addDelay(nap)
return self.delayedExecution(nap)
}
func (self *ExecutorFixture) delayedExecution(nap time.Duration) string {
go self.ExecuteTests()
time.Sleep(nap)
return self.executor.Status()
}
func (self *ExecutorFixture) ResultShouldBePopulated() {
So(self.result, ShouldResemble, self.expected)
}
var (
prefix = "/Users/blah/gopath/src/"
packageA = "github.com/smartystreets/goconvey/a"
packageB = "github.com/smartystreets/goconvey/b"
resultA = &contract.PackageResult{PackageName: packageA}
resultB = &contract.PackageResult{PackageName: packageB}
)
func newExecutorFixture() *ExecutorFixture {
self := &ExecutorFixture{}
self.tester = newFakeTester()
self.parser = newFakeParser()
self.executor = NewExecutor(self.tester, self.parser, make(chan bool, 1))
self.folders = []*contract.Package{
&contract.Package{Active: true, Path: prefix + packageA, Name: packageA},
&contract.Package{Active: true, Path: prefix + packageB, Name: packageB},
}
self.stamp = time.Now()
now = func() time.Time { return self.stamp }
self.expected = &contract.CompleteOutput{
Packages: []*contract.PackageResult{
resultA,
resultB,
},
Revision: self.stamp.String(),
}
return self
}
/******** FakeTester ********/
type FakeTester struct {
nap time.Duration
}
func (self *FakeTester) SetBatchSize(batchSize int) { panic("NOT SUPPORTED") }
func (self *FakeTester) TestAll(folders []*contract.Package) {
for _, p := range folders {
p.Output = p.Path
}
time.Sleep(self.nap)
}
func (self *FakeTester) addDelay(nap time.Duration) {
self.nap = nap
}
func newFakeTester() *FakeTester {
self := &FakeTester{}
zero, _ := time.ParseDuration("0")
self.nap = zero
return self
}
/******** FakeParser ********/
type FakeParser struct {
nap time.Duration
}
func (self *FakeParser) Parse(packages []*contract.Package) {
time.Sleep(self.nap)
for _, package_ := range packages {
if package_.Name == packageA && strings.HasSuffix(package_.Output, packageA) {
package_.Result = resultA
}
if package_.Name == packageB && strings.HasSuffix(package_.Output, packageB) {
package_.Result = resultB
}
}
}
func (self *FakeParser) addDelay(nap time.Duration) {
self.nap = nap
}
func newFakeParser() *FakeParser {
self := &FakeParser{}
zero, _ := time.ParseDuration("0")
self.nap = zero
return self
}
|