...
1
16
17 package bugs
18
19 import (
20 "bytes"
21 "testing"
22
23 "github.com/onsi/ginkgo/v2"
24 "k8s.io/kubernetes/test/e2e/framework"
25 "k8s.io/kubernetes/test/e2e/framework/internal/unittests/bugs/features"
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 func helper() {
53 framework.RecordBug(framework.NewBug("new bug", 0))
54 framework.RecordBug(framework.NewBug("parent", 1))
55 }
56
57 func RecordBugs() {
58 helper()
59 framework.RecordBug(framework.Bug{FileName: "buggy/buggy.go", LineNumber: 100, Message: "hello world"})
60 framework.RecordBug(framework.Bug{FileName: "some/relative/path/buggy.go", LineNumber: 200, Message: " with spaces \n"})
61 }
62
63 var (
64 validFeature = framework.ValidFeatures.Add("feature-foo")
65 validEnvironment = framework.ValidEnvironments.Add("Linux")
66 validNodeFeature = framework.ValidNodeFeatures.Add("node-feature-foo")
67 )
68
69 func Describe() {
70
71
72 framework.SIGDescribe("testing")("abc",
73
74 "",
75 " space1",
76 "space2 ",
77 framework.WithFeature("no-such-feature"),
78 framework.WithFeature(validFeature),
79 framework.WithEnvironment("no-such-env"),
80 framework.WithEnvironment(validEnvironment),
81 framework.WithNodeFeature("no-such-node-env"),
82 framework.WithNodeFeature(validNodeFeature),
83 framework.WithFeatureGate("no-such-feature-gate"),
84 framework.WithFeatureGate(features.Alpha),
85 framework.WithFeatureGate(features.Beta),
86 framework.WithFeatureGate(features.GA),
87 framework.WithConformance(),
88 framework.WithNodeConformance(),
89 framework.WithSlow(),
90 framework.WithSerial(),
91 framework.WithDisruptive(),
92 framework.WithLabel("custom-label"),
93 "xyz",
94 func() {
95 f := framework.NewDefaultFramework("abc")
96
97 framework.Context("y", framework.WithLabel("foo"), func() {
98 framework.It("should", f.WithLabel("bar"), func() {
99 })
100 })
101
102 f.Context("x", f.WithLabel("foo"), func() {
103 f.It("should", f.WithLabel("bar"), func() {
104 })
105 })
106 },
107 )
108
109 framework.SIGDescribe("123")
110 }
111
112 const (
113 numBugs = 3
114 bugOutput = `ERROR: bugs.go:53: new bug
115 ERROR: bugs.go:58: parent
116 ERROR: bugs.go:72: empty strings as separators are unnecessary and need to be removed
117 ERROR: bugs.go:72: trailing or leading spaces are unnecessary and need to be removed: " space1"
118 ERROR: bugs.go:72: trailing or leading spaces are unnecessary and need to be removed: "space2 "
119 ERROR: bugs.go:77: WithFeature: unknown feature "no-such-feature"
120 ERROR: bugs.go:79: WithEnvironment: unknown environment "no-such-env"
121 ERROR: bugs.go:81: WithNodeFeature: unknown environment "no-such-node-env"
122 ERROR: bugs.go:83: WithFeatureGate: the feature gate "no-such-feature-gate" is unknown
123 ERROR: bugs.go:109: SIG label must be lowercase, no spaces and no sig- prefix, got instead: "123"
124 ERROR: buggy/buggy.go:100: hello world
125 ERROR: some/relative/path/buggy.go:200: with spaces
126 `
127
128 ListTestsOutput = `The following spec names can be used with 'ginkgo run --focus/skip':
129 ../bugs/bugs.go:103: [sig-testing] abc space1 space2 [Feature:no-such-feature] [Feature:feature-foo] [Environment:no-such-env] [Environment:Linux] [NodeFeature:no-such-node-env] [NodeFeature:node-feature-foo] [FeatureGate:no-such-feature-gate] [FeatureGate:TestAlphaFeature] [Alpha] [FeatureGate:TestBetaFeature] [Beta] [FeatureGate:TestGAFeature] [Conformance] [NodeConformance] [Slow] [Serial] [Disruptive] [custom-label] xyz x [foo] should [bar]
130 ../bugs/bugs.go:98: [sig-testing] abc space1 space2 [Feature:no-such-feature] [Feature:feature-foo] [Environment:no-such-env] [Environment:Linux] [NodeFeature:no-such-node-env] [NodeFeature:node-feature-foo] [FeatureGate:no-such-feature-gate] [FeatureGate:TestAlphaFeature] [Alpha] [FeatureGate:TestBetaFeature] [Beta] [FeatureGate:TestGAFeature] [Conformance] [NodeConformance] [Slow] [Serial] [Disruptive] [custom-label] xyz y [foo] should [bar]
131
132 `
133
134
135 ListLabelsOutput = `The following labels can be used with 'ginkgo run --label-filter':
136 Alpha
137 Beta
138 Conformance
139 Disruptive
140 Environment:Linux
141 Environment:no-such-env
142 Feature:feature-foo
143 Feature:no-such-feature
144 FeatureGate:TestAlphaFeature
145 FeatureGate:TestBetaFeature
146 FeatureGate:TestGAFeature
147 FeatureGate:no-such-feature-gate
148 NodeConformance
149 NodeFeature:no-such-node-env
150 NodeFeature:node-feature-foo
151 Serial
152 Slow
153 bar
154 custom-label
155 foo
156 sig-testing
157
158 `
159 )
160
161 func GetGinkgoOutput(t *testing.T) string {
162 var buffer bytes.Buffer
163 ginkgo.GinkgoWriter.TeeTo(&buffer)
164 t.Cleanup(ginkgo.GinkgoWriter.ClearTeeWriters)
165
166 suiteConfig, reporterConfig := framework.CreateGinkgoConfig()
167 fakeT := &testing.T{}
168 ginkgo.RunSpecs(fakeT, "Buggy Suite", suiteConfig, reporterConfig)
169
170 return buffer.String()
171 }
172
View as plain text