/usr/share/gocode/src/github.com/smartystreets/goconvey/web/server/system/shell_test.go is in golang-github-smartystreets-goconvey-dev 1.6.1-3.
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 | package system
import (
"errors"
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func TestShellCommandComposition(t *testing.T) {
var (
buildFailed = Command{Error: errors.New("BUILD FAILURE!")}
buildSucceeded = Command{Output: "ok"}
goConvey = Command{Output: "[fmt github.com/smartystreets/goconvey/convey net/http net/http/httptest path runtime strconv strings testing time]"}
noGoConvey = Command{Output: "[fmt net/http net/http/httptest path runtime strconv strings testing time]"}
errorGoConvey = Command{Output: "This is a wacky error", Error: errors.New("This happens when running goconvey outside your $GOPATH (symlinked code).")}
noCoveragePassed = Command{Output: "PASS\nok github.com/smartystreets/goconvey/examples 0.012s"}
coveragePassed = Command{Output: "PASS\ncoverage: 100.0% of statements\nok github.com/smartystreets/goconvey/examples 0.012s"}
coverageFailed = Command{
Error: errors.New("Tests bombed!"),
Output: "--- FAIL: TestIntegerManipulation (0.00 seconds)\nFAIL\ncoverage: 100.0% of statements\nexit status 1\nFAIL github.com/smartystreets/goconvey/examples 0.013s",
}
coverageFailedTimeout = Command{
Error: errors.New("Tests bombed!"),
Output: "=== RUN SomeTest\n--- PASS: SomeTest (0.00 seconds)\n=== RUN TimeoutTest\npanic: test timed out after 5s\n\ngoroutine 27 [running]:\n",
}
)
const (
yesCoverage = true
noCoverage = false
)
Convey("When attempting to run tests with coverage flags", t, func() {
Convey("And buildSucceeded failed", func() {
result := runWithCoverage(buildFailed, goConvey, noCoverage, "", "", "", "", "-tags=", nil)
Convey("Then no action should be taken", func() {
So(result, ShouldResemble, buildFailed)
})
})
Convey("And coverage is not wanted", func() {
result := runWithCoverage(buildSucceeded, goConvey, noCoverage, "", "", "", "", "-tags=", nil)
Convey("Then no action should be taken", func() {
So(result, ShouldResemble, buildSucceeded)
})
})
Convey("And the package being tested usees the GoConvey DSL (`convey` package)", func() {
result := runWithCoverage(buildSucceeded, goConvey, yesCoverage, "reportsPath", "/directory", "go", "5s", "-tags=bob", []string{"-arg1", "-arg2"})
Convey("The returned command should be well formed (and include the -json flag)", func() {
So(result, ShouldResemble, Command{
directory: "/directory",
executable: "go",
arguments: []string{"test", "-v", "-coverprofile=reportsPath", "-tags=bob", "-covermode=set", "-timeout=5s", "-convey-json", "-arg1", "-arg2"},
})
})
})
Convey("And the package being tested does NOT use the GoConvey DSL", func() {
result := runWithCoverage(buildSucceeded, noGoConvey, yesCoverage, "reportsPath", "/directory", "go", "1s", "-tags=bob", []string{"-arg1", "-arg2"})
Convey("The returned command should be well formed (and NOT include the -json flag)", func() {
So(result, ShouldResemble, Command{
directory: "/directory",
executable: "go",
arguments: []string{"test", "-v", "-coverprofile=reportsPath", "-tags=bob", "-covermode=set", "-timeout=1s", "-arg1", "-arg2"},
})
})
})
Convey("And the package being tested has been symlinked outside the $GOAPTH", func() {
result := runWithCoverage(buildSucceeded, errorGoConvey, yesCoverage, "reportsPath", "/directory", "go", "1s", "-tags=", nil)
Convey("The returned command should be the compilation command", func() {
So(result, ShouldResemble, buildSucceeded)
})
})
Convey("And the package being tested specifies an alternate covermode", func() {
result := runWithCoverage(buildSucceeded, noGoConvey, yesCoverage, "reportsPath", "/directory", "go", "1s", "-tags=", []string{"-covermode=atomic"})
Convey("The returned command should allow the alternate value", func() {
So(result, ShouldResemble, Command{
directory: "/directory",
executable: "go",
arguments: []string{"test", "-v", "-coverprofile=reportsPath", "-tags=", "-timeout=1s", "-covermode=atomic"},
})
})
})
Convey("And the package being tested specifies an alternate timeout", func() {
result := runWithCoverage(buildSucceeded, noGoConvey, yesCoverage, "reportsPath", "/directory", "go", "1s", "-tags=", []string{"-timeout=5s"})
Convey("The returned command should allow the alternate value", func() {
So(result, ShouldResemble, Command{
directory: "/directory",
executable: "go",
arguments: []string{"test", "-v", "-coverprofile=reportsPath", "-tags=", "-covermode=set", "-timeout=5s"},
})
})
})
})
Convey("When attempting to run tests without the coverage flags", t, func() {
Convey("And tests already succeeded with coverage", func() {
result := runWithoutCoverage(buildSucceeded, coveragePassed, goConvey, "/directory", "go", "1s", "-tags=", []string{"-arg1", "-arg2"})
Convey("Then no action should be taken", func() {
So(result, ShouldResemble, coveragePassed)
})
})
Convey("And tests already failed (legitimately) with coverage", func() {
result := runWithoutCoverage(buildSucceeded, coverageFailed, goConvey, "/directory", "go", "1s", "-tags=", []string{"-arg1", "-arg2"})
Convey("Then no action should be taken", func() {
So(result, ShouldResemble, coverageFailed)
})
})
Convey("And tests already failed (timeout) with coverage", func() {
result := runWithoutCoverage(buildSucceeded, coverageFailedTimeout, goConvey, "/directory", "go", "1s", "-tags=", []string{"-arg1", "-arg2"})
Convey("Then no action should be taken", func() {
So(result, ShouldResemble, coverageFailedTimeout)
})
})
Convey("And the build failed earlier", func() {
result := runWithoutCoverage(buildFailed, Command{}, goConvey, "/directory", "go", "1s", "-tags=", []string{"-arg1", "-arg2"})
Convey("Then no action should be taken", func() {
So(result, ShouldResemble, buildFailed)
})
})
Convey("And the goconvey dsl command failed (probably because of symlinks)", func() {
result := runWithoutCoverage(buildSucceeded, Command{}, errorGoConvey, "", "", "", "-tags=", nil)
Convey("Then no action should be taken", func() {
So(result, ShouldResemble, errorGoConvey)
})
})
Convey("And the package being tested uses the GoConvey DSL (`convey` package)", func() {
result := runWithoutCoverage(buildSucceeded, buildSucceeded, goConvey, "/directory", "go", "1s", "-tags=", []string{"-arg1", "-arg2"})
Convey("Then the returned command should be well formed (and include the -json flag)", func() {
So(result, ShouldResemble, Command{
directory: "/directory",
executable: "go",
arguments: []string{"test", "-v", "-tags=", "-timeout=1s", "-convey-json", "-arg1", "-arg2"},
})
})
})
Convey("And the package being tested does NOT use the GoConvey DSL", func() {
result := runWithoutCoverage(buildSucceeded, noCoveragePassed, noGoConvey, "/directory", "go", "1s", "-tags=", []string{"-arg1", "-arg2"})
Convey("Then the returned command should be well formed (and NOT include the -json flag)", func() {
So(result, ShouldResemble, Command{
directory: "/directory",
executable: "go",
arguments: []string{"test", "-v", "-tags=", "-timeout=1s", "-arg1", "-arg2"},
})
})
})
Convey("And the package being tested specifies an alternate timeout", func() {
result := runWithoutCoverage(buildSucceeded, buildSucceeded, noGoConvey, "/directory", "go", "1s", "-tags=", []string{"-timeout=5s"})
Convey("The returned command should allow the alternate value", func() {
So(result, ShouldResemble, Command{
directory: "/directory",
executable: "go",
arguments: []string{"test", "-v", "-tags=", "-timeout=5s"},
})
})
})
})
Convey("When generating coverage reports", t, func() {
Convey("And the previous command failed for any reason (compilation or failed tests)", func() {
result := generateReports(buildFailed, yesCoverage, "/directory", "go", "reportData", "reportHTML")
Convey("Then no action should be taken", func() {
So(result, ShouldResemble, buildFailed)
})
})
Convey("And coverage reports are unwanted", func() {
result := generateReports(noCoveragePassed, noCoverage, "/directory", "go", "reportData", "reportHTML")
Convey("Then no action should beg taken", func() {
So(result, ShouldResemble, noCoveragePassed)
})
})
Convey("And tests passed and coverage reports are wanted", func() {
result := generateReports(coveragePassed, yesCoverage, "/directory", "go", "reportData", "reportHTML")
Convey("Then the resulting command should be well-formed", func() {
So(result, ShouldResemble, Command{
directory: "/directory",
executable: "go",
arguments: []string{"tool", "cover", "-html=reportData", "-o", "reportHTML"},
})
})
})
})
}
|