-
Notifications
You must be signed in to change notification settings - Fork 384
/
skip.go
117 lines (96 loc) · 2.19 KB
/
skip.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
package testutil
import (
"fmt"
"os"
"strings"
"testing"
)
// Stability level enum
type Stability string
const (
Stable Stability = "stable"
Unstable Stability = "unstable"
Broken Stability = "broken"
AnyStability Stability = "any"
)
// Speed level enum
type Speed string
const (
Fast Speed = "fast"
Slow Speed = "slow"
AnySpeed Speed = "any"
)
// RacePolicy enum
type RacePolicy string
const (
SkipIfRace RacePolicy = "skip-if-race"
RunIfRace RacePolicy = "run-if-race"
)
// Default levels
const (
defaultStabilityFilter Stability = Stable
defaultSpeedFilter Speed = AnySpeed
)
var (
enabledStability = map[Stability]bool{}
enabledSpeed = map[Speed]bool{}
envParsed = false
)
func parseEnv() {
// Get stability filters
stabFilter := os.Getenv("TEST_STABILITY")
if stabFilter == "" {
stabFilter = string(defaultStabilityFilter)
}
for _, level := range strings.Split(stabFilter, ",") {
switch Stability(level) {
case Stable, Unstable, Broken:
enabledStability[Stability(level)] = true
case AnyStability:
enabledStability[Stable] = true
enabledStability[Unstable] = true
enabledStability[Broken] = true
default:
panic(fmt.Sprintf("invalid stability level: %q", level))
}
}
// Get speed filters
speedFilter := os.Getenv("TEST_SPEED")
if speedFilter == "" {
speedFilter = string(defaultSpeedFilter)
}
for _, level := range strings.Split(speedFilter, ",") {
switch Speed(level) {
case Slow, Fast:
enabledSpeed[Speed(level)] = true
case AnySpeed:
enabledSpeed[Slow] = true
enabledSpeed[Fast] = true
default:
panic(fmt.Sprintf("invalid speed level: %q", level))
}
}
envParsed = true
}
func FilterStability(t *testing.T, stability Stability) {
t.Helper()
if !envParsed {
parseEnv()
}
if !enabledStability[stability] {
t.Skip(fmt.Sprintf("skip test with %q stability", stability))
}
}
func FilterSpeed(t *testing.T, speed Speed) {
t.Helper()
if !envParsed {
parseEnv()
}
if !enabledSpeed[speed] {
t.Skip(fmt.Sprintf("skip test with %q speed", speed))
}
}
func FilterStabilityAndSpeed(t *testing.T, stability Stability, speed Speed) {
FilterStability(t, stability)
FilterSpeed(t, speed)
}