-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtest_9x_frameworks_test.go
138 lines (112 loc) · 3.75 KB
/
test_9x_frameworks_test.go
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
// Copyright 2020 Bloomberg Finance L.P.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package docket_test
import (
"bufio"
"bytes"
"fmt"
"os"
"os/exec"
"path/filepath"
"regexp"
"testing"
"github.com/bloomberg/go-testgroup"
)
func Test_9x_frameworks(t *testing.T) {
if testing.Short() {
t.Skip("skipping docker-dependent test group in short mode")
}
testgroup.RunSerially(t, &frameworks{})
}
type frameworks struct{}
func (grp *frameworks) Testgroup(t *testgroup.T) {
t.RunSerially(&frameworkTests{dir: filepath.Join("testdata", "98_testgroup")})
}
func (grp *frameworks) TestifySuite(t *testgroup.T) {
t.RunSerially(&frameworkTests{dir: filepath.Join("testdata", "99_testify-suite")})
}
//------------------------------------------------------------------------------
type frameworkTests struct {
dir string
}
func (grp *frameworkTests) All(t *testgroup.T) {
grp.runGoTest(t)
}
func (grp *frameworkTests) Subset(t *testgroup.T) {
t.RunSerially(&frameworkSubsetTests{parent: grp})
}
func (grp *frameworkTests) runGoTest(t *testgroup.T, arg ...string) []byte {
cmd := exec.Command("go", "test", "-v")
cmd.Args = append(cmd.Args, goTestCoverageArgs(t.Name())...)
cmd.Args = append(cmd.Args, goTestRaceDetectorArgs()...)
cmd.Args = append(cmd.Args, arg...)
cmd.Dir = grp.dir
cmd.Env = append(os.Environ(), "DOCKET_MODE=full", "DOCKET_DOWN=1")
out, err := cmd.CombinedOutput()
if err != nil {
fmt.Printf("%s", out)
}
t.NoError(err)
return out
}
//------------------------------------------------------------------------------
type frameworkSubsetTests struct {
parent *frameworkTests
}
func (grp *frameworkSubsetTests) OnlySubtestA(t *testgroup.T) {
output, sawA, sawB, sawC, sawOthers := grp.testSubtestA(t, true)
t.Equalf(true, sawA, "should have seen test A, output: %s", output)
t.Equalf(false, sawB, "should not have seen test B, output: %s", output)
t.Equalf(false, sawC, "should not have seen test C, output: %s", output)
t.Equalf(false, sawOthers, "should not have seen other tests, output: %s", output)
}
func (grp *frameworkSubsetTests) EverythingButSubtestA(t *testgroup.T) {
output, sawA, sawB, sawC, sawOthers := grp.testSubtestA(t, false)
t.Equalf(false, sawA, "should not have seen test A, output: %s", output)
t.Equalf(true, sawB, "should have seen test B, output: %s", output)
t.Equalf(true, sawC, "should have seen test C, output: %s", output)
t.Equalf(false, sawOthers, "should not have seen other tests, output: %s", output)
}
// Helper routine that either runs ONLY subtestA or everything EXCEPT subtestA.
func (grp *frameworkSubsetTests) testSubtestA(t *testgroup.T, includeA bool) (
output []byte, sawA, sawB, sawC, sawOthers bool,
) {
negation := ""
if !includeA {
negation = "^"
}
runArg := fmt.Sprintf("-run=DocketRunAtTopLevel/[%sA]$", negation)
output = grp.parent.runGoTest(t, runArg)
ranTest := regexp.MustCompile(`^=== RUN Test.+/(Test)?[A-Z]$`)
scanner := bufio.NewScanner(bytes.NewReader(output))
for scanner.Scan() {
txt := scanner.Text()
if txt == "PASS" {
break
}
if ranTest.MatchString(txt) {
switch txt[len(txt)-1] {
case 'A':
sawA = true
case 'B':
sawB = true
case 'C':
sawC = true
default:
sawOthers = true
}
}
}
return output, sawA, sawB, sawC, sawOthers
}