Skip to content

Commit 5e44d8e

Browse files
authored
Merge pull request kubernetes#95015 from Jefftree/bdd-remove-dependency
Remove dependency on behaviors for conformance walk.go
2 parents 613ee7f + 6b8c8e4 commit 5e44d8e

File tree

6 files changed

+36
-51
lines changed

6 files changed

+36
-51
lines changed

test/conformance/BUILD

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ go_library(
99
importpath = "k8s.io/kubernetes/test/conformance",
1010
visibility = ["//visibility:private"],
1111
deps = [
12-
"//test/conformance/behaviors:go_default_library",
1312
"//vendor/github.com/onsi/ginkgo/types:go_default_library",
1413
"//vendor/gopkg.in/yaml.v2:go_default_library",
1514
],
@@ -79,7 +78,6 @@ go_test(
7978
srcs = ["walk_test.go"],
8079
data = glob(["testdata/**"]),
8180
embed = [":go_default_library"],
82-
deps = ["//test/conformance/behaviors:go_default_library"],
8381
)
8482

8583
genrule(

test/conformance/testdata/conformance.yaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,6 @@
244244
Query for the Pod with the new value for the label MUST be successful.
245245
release: v1.9
246246
file: test/e2e/common/pods.go
247-
behaviors:
248-
- pod/spec/label/create
249-
- pod/spec/label/patch
250247
- testname: Pods, service environment variables
251248
codename: '[k8s.io] Pods should contain environment variables for services [NodeConformance]
252249
[Conformance]'
@@ -484,8 +481,6 @@
484481
have QOSClass set to PodQOSGuaranteed.
485482
release: v1.9
486483
file: test/e2e/node/pods.go
487-
behaviors:
488-
- pod/spec/container/resources
489484
- testname: Pods, prestop hook
490485
codename: '[k8s.io] [sig-node] PreStop should call prestop when killing a pod [Conformance]'
491486
description: Create a server pod with a rest endpoint '/write' that changes state.Received

test/conformance/walk.go

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"go/ast"
2424
"go/parser"
2525
"go/token"
26-
"gopkg.in/yaml.v2"
2726
"io"
2827
"log"
2928
"os"
@@ -33,11 +32,27 @@ import (
3332
"strings"
3433
"text/template"
3534

36-
"github.com/onsi/ginkgo/types"
35+
"gopkg.in/yaml.v2"
3736

38-
"k8s.io/kubernetes/test/conformance/behaviors"
37+
"github.com/onsi/ginkgo/types"
3938
)
4039

40+
// ConformanceData describes the structure of the conformance.yaml file
41+
type ConformanceData struct {
42+
// A URL to the line of code in the kube src repo for the test. Omitted from the YAML to avoid exposing line number.
43+
URL string `yaml:"-"`
44+
// Extracted from the "Testname:" comment before the test
45+
TestName string
46+
// CodeName is taken from the actual ginkgo descriptions, e.g. `[sig-apps] Foo should bar [Conformance]`
47+
CodeName string
48+
// Extracted from the "Description:" comment before the test
49+
Description string
50+
// Version when this test is added or modified ex: v1.12, v1.13
51+
Release string
52+
// File is the filename where the test is defined. We intentionally don't save the line here to avoid meaningless changes.
53+
File string
54+
}
55+
4156
var (
4257
baseURL = flag.String("url", "https://github.com/kubernetes/kubernetes/tree/master/", "location of the current source")
4358
k8sPath = flag.String("source", "", "location of the current source on the current machine")
@@ -80,7 +95,7 @@ func main() {
8095

8196
seenLines = map[string]struct{}{}
8297
dec := json.NewDecoder(f)
83-
testInfos := []*behaviors.ConformanceData{}
98+
testInfos := []*ConformanceData{}
8499
for {
85100
var spec *types.SpecSummary
86101
if err := dec.Decode(&spec); err == io.EOF {
@@ -109,8 +124,8 @@ func isConformance(spec *types.SpecSummary) bool {
109124
return strings.Contains(getTestName(spec), "[Conformance]")
110125
}
111126

112-
func getTestInfo(spec *types.SpecSummary) *behaviors.ConformanceData {
113-
var c *behaviors.ConformanceData
127+
func getTestInfo(spec *types.SpecSummary) *ConformanceData {
128+
var c *ConformanceData
114129
var err error
115130
// The key to this working is that we don't need to parse every file or walk
116131
// every componentCodeLocation. The last componentCodeLocation is going to typically start
@@ -140,7 +155,7 @@ func getTestName(spec *types.SpecSummary) string {
140155
return strings.Join(spec.ComponentTexts[1:], " ")
141156
}
142157

143-
func saveAllTestInfo(dataSet []*behaviors.ConformanceData) {
158+
func saveAllTestInfo(dataSet []*ConformanceData) {
144159
if *confDoc {
145160
// Note: this assumes that you're running from the root of the kube src repo
146161
templ, err := template.ParseFiles("./test/conformance/cf_header.md")
@@ -171,7 +186,7 @@ func saveAllTestInfo(dataSet []*behaviors.ConformanceData) {
171186
fmt.Println(string(b))
172187
}
173188

174-
func getConformanceDataFromStackTrace(fullstackstrace string) (*behaviors.ConformanceData, error) {
189+
func getConformanceDataFromStackTrace(fullstackstrace string) (*ConformanceData, error) {
175190
// The full stacktrace to parse from ginkgo is of the form:
176191
// k8s.io/kubernetes/test/e2e/storage/utils.SIGDescribe(0x51f4c4f, 0xf, 0x53a0dd8, 0xc000ab6e01)\n\ttest/e2e/storage/utils/framework.go:23 +0x75\n ... ...
177192
// So we need to split it into lines, remove whitespace, and then grab the files/lines.
@@ -225,7 +240,7 @@ func getConformanceDataFromStackTrace(fullstackstrace string) (*behaviors.Confor
225240

226241
// scanFileForFrame will scan the target and look for a conformance comment attached to the function
227242
// described by the target frame. If the comment can't be found then nil, nil is returned.
228-
func scanFileForFrame(filename string, src interface{}, targetFrame frame) (*behaviors.ConformanceData, error) {
243+
func scanFileForFrame(filename string, src interface{}, targetFrame frame) (*ConformanceData, error) {
229244
fset := token.NewFileSet() // positions are relative to fset
230245
f, err := parser.ParseFile(fset, filename, src, parser.ParseComments)
231246
if err != nil {
@@ -251,7 +266,7 @@ func validateTestName(s string) error {
251266
return nil
252267
}
253268

254-
func tryCommentGroupAndFrame(fset *token.FileSet, cg *ast.CommentGroup, f frame) *behaviors.ConformanceData {
269+
func tryCommentGroupAndFrame(fset *token.FileSet, cg *ast.CommentGroup, f frame) *ConformanceData {
255270
if !shouldProcessCommentGroup(fset, cg, f) {
256271
return nil
257272
}
@@ -275,10 +290,10 @@ func shouldProcessCommentGroup(fset *token.FileSet, cg *ast.CommentGroup, f fram
275290
return lineDiff > 0 && lineDiff <= conformanceCommentsLineWindow
276291
}
277292

278-
func commentToConformanceData(comment string) *behaviors.ConformanceData {
293+
func commentToConformanceData(comment string) *ConformanceData {
279294
lines := strings.Split(comment, "\n")
280295
descLines := []string{}
281-
cd := &behaviors.ConformanceData{}
296+
cd := &ConformanceData{}
282297
var curLine string
283298
for _, line := range lines {
284299
line = strings.TrimSpace(line)
@@ -300,17 +315,9 @@ func commentToConformanceData(comment string) *behaviors.ConformanceData {
300315
descLines = append(descLines, sline[1])
301316
continue
302317
}
303-
if sline := regexp.MustCompile("^Behaviors\\s*:\\s*").Split(line, -1); len(sline) == 2 {
304-
curLine = "Behaviors"
305-
continue
306-
}
307318

308319
// Line has no header
309-
if curLine == "Behaviors" {
310-
if sline := regexp.MustCompile("^-\\s").Split(line, -1); len(sline) == 2 {
311-
cd.Behaviors = append(cd.Behaviors, sline[1])
312-
}
313-
} else if curLine == "Description" {
320+
if curLine == "Description" {
314321
descLines = append(descLines, line)
315322
}
316323
}

test/conformance/walk_test.go

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ import (
2020
"fmt"
2121
"reflect"
2222
"testing"
23-
24-
"k8s.io/kubernetes/test/conformance/behaviors"
2523
)
2624

2725
func TestConformance(t *testing.T) {
@@ -30,7 +28,7 @@ func TestConformance(t *testing.T) {
3028
filename string
3129
code string
3230
targetFrame frame
33-
output *behaviors.ConformanceData
31+
output *ConformanceData
3432
}{
3533
{
3634
desc: "Grabs comment above test",
@@ -47,7 +45,7 @@ func TestConformance(t *testing.T) {
4745
*/
4846
framework.ConformanceIt("validates describe with ConformanceIt", func() {})
4947
})`,
50-
output: &behaviors.ConformanceData{
48+
output: &ConformanceData{
5149
URL: "https://github.com/kubernetes/kubernetes/tree/master/test/list/main_test.go#L11",
5250
TestName: "Kubelet-OutputToLogs",
5351
Description: `By default the stdout and stderr from the process being executed in a pod MUST be sent to the pod's logs.`,
@@ -67,7 +65,7 @@ func TestConformance(t *testing.T) {
6765
framework.ConformanceIt("should work", func() {})
6866
})
6967
})`,
70-
output: &behaviors.ConformanceData{
68+
output: &ConformanceData{
7169
URL: "https://github.com/kubernetes/kubernetes/tree/master/e2e/foo.go#L8",
7270
TestName: "Test with spaces",
7371
Description: `Should pick up testname even if it is not within 3 spaces even when executed from memory.`,
@@ -91,7 +89,7 @@ func TestConformance(t *testing.T) {
9189
framework.ConformanceIt("should work", func() {})
9290
})
9391
})`,
94-
output: &behaviors.ConformanceData{
92+
output: &ConformanceData{
9593
URL: "https://github.com/kubernetes/kubernetes/tree/master/e2e/foo.go#L13",
9694
TestName: "Second test",
9795
Description: `Should target the correct test/comment based on the line numbers`,
@@ -114,7 +112,7 @@ func TestConformance(t *testing.T) {
114112
framework.ConformanceIt("should work", func() {})
115113
})
116114
})`,
117-
output: &behaviors.ConformanceData{
115+
output: &ConformanceData{
118116
URL: "https://github.com/kubernetes/kubernetes/tree/master/e2e/foo.go#L8",
119117
TestName: "First test",
120118
Description: `Should target the correct test/comment based on the line numbers`,
@@ -141,7 +139,7 @@ func TestCommentToConformanceData(t *testing.T) {
141139
tcs := []struct {
142140
desc string
143141
input string
144-
expected *behaviors.ConformanceData
142+
expected *ConformanceData
145143
}{
146144
{
147145
desc: "Empty comment leads to nil",
@@ -154,19 +152,11 @@ func TestCommentToConformanceData(t *testing.T) {
154152
}, {
155153
desc: "Testname but no Release does not result in nil",
156154
input: "Testname: mytest\nDescription: foo",
157-
expected: &behaviors.ConformanceData{TestName: "mytest", Description: "foo"},
155+
expected: &ConformanceData{TestName: "mytest", Description: "foo"},
158156
}, {
159157
desc: "All fields parsed and newlines and whitespace removed from description",
160158
input: "Release: v1.1\n\t\tTestname: mytest\n\t\tDescription: foo\n\t\tbar\ndone",
161-
expected: &behaviors.ConformanceData{TestName: "mytest", Release: "v1.1", Description: "foo bar done"},
162-
}, {
163-
desc: "Behaviors are read",
164-
input: "Testname: behaviors\nBehaviors:\n- should behave\n- second behavior",
165-
expected: &behaviors.ConformanceData{TestName: "behaviors", Behaviors: []string{"should behave", "second behavior"}},
166-
}, {
167-
desc: "Multiple behaviors are parsed",
168-
input: "Testname: behaviors2\nBehaviors:\n- first behavior\n- second behavior",
169-
expected: &behaviors.ConformanceData{TestName: "behaviors2", Behaviors: []string{"first behavior", "second behavior"}},
159+
expected: &ConformanceData{TestName: "mytest", Release: "v1.1", Description: "foo bar done"},
170160
},
171161
}
172162

test/e2e/common/pods.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,9 +339,6 @@ var _ = framework.KubeDescribe("Pods", func() {
339339
Release: v1.9
340340
Testname: Pods, update
341341
Description: Create a Pod with a unique label. Query for the Pod with the label as selector MUST be successful. Update the pod to change the value of the Label. Query for the Pod with the new value for the label MUST be successful.
342-
Behaviors:
343-
- pod/spec/label/create
344-
- pod/spec/label/patch
345342
*/
346343
framework.ConformanceIt("should be updated [NodeConformance]", func() {
347344
ginkgo.By("creating the pod")

test/e2e/node/pods.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,6 @@ var _ = SIGDescribe("Pods Extended", func() {
155155
Release: v1.9
156156
Testname: Pods, QOS
157157
Description: Create a Pod with CPU and Memory request and limits. Pod status MUST have QOSClass set to PodQOSGuaranteed.
158-
Behaviors:
159-
- pod/spec/container/resources
160158
*/
161159
framework.ConformanceIt("should be set on Pods with matching resource requests and limits for memory and cpu", func() {
162160
ginkgo.By("creating the pod")

0 commit comments

Comments
 (0)