Skip to content

Commit 6da6380

Browse files
committed
Capture behaviors in walk.go
1 parent 1836f95 commit 6da6380

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

test/conformance/walk.go

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ type conformanceData struct {
7676
Release string
7777
// File is the filename where the test is defined. We intentionally don't save the line here to avoid meaningless changes.
7878
File string
79+
// Behaviors is the list of conformance behaviors tested by a particular e2e test
80+
Behaviors []string `yaml:"behaviors,omitempty"`
7981
}
8082

8183
func main() {
@@ -292,23 +294,40 @@ func commentToConformanceData(comment string) *conformanceData {
292294
lines := strings.Split(comment, "\n")
293295
descLines := []string{}
294296
cd := &conformanceData{}
297+
var curLine string
295298
for _, line := range lines {
296299
line = strings.TrimSpace(line)
297300
if len(line) == 0 {
298301
continue
299302
}
300303
if sline := regexp.MustCompile("^Testname\\s*:\\s*").Split(line, -1); len(sline) == 2 {
304+
curLine = "Testname"
301305
cd.TestName = sline[1]
302306
continue
303307
}
304308
if sline := regexp.MustCompile("^Release\\s*:\\s*").Split(line, -1); len(sline) == 2 {
309+
curLine = "Release"
305310
cd.Release = sline[1]
306311
continue
307312
}
308313
if sline := regexp.MustCompile("^Description\\s*:\\s*").Split(line, -1); len(sline) == 2 {
309-
line = sline[1]
314+
curLine = "Description"
315+
descLines = append(descLines, sline[1])
316+
continue
317+
}
318+
if sline := regexp.MustCompile("^Behaviors\\s*:\\s*").Split(line, -1); len(sline) == 2 {
319+
curLine = "Behaviors"
320+
continue
321+
}
322+
323+
// Line has no header
324+
if curLine == "Behaviors" {
325+
if sline := regexp.MustCompile("^-\\s").Split(line, -1); len(sline) == 2 {
326+
cd.Behaviors = append(cd.Behaviors, sline[1])
327+
}
328+
} else if curLine == "Description" {
329+
descLines = append(descLines, line)
310330
}
311-
descLines = append(descLines, line)
312331
}
313332
if cd.Release == "" && cd.TestName == "" {
314333
return nil

test/conformance/walk_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,14 @@ func TestCommentToConformanceData(t *testing.T) {
158158
desc: "All fields parsed and newlines and whitespace removed from description",
159159
input: "Release: v1.1\n\t\tTestname: mytest\n\t\tDescription: foo\n\t\tbar\ndone",
160160
expected: &conformanceData{TestName: "mytest", Release: "v1.1", Description: "foo bar done"},
161+
}, {
162+
desc: "Behaviors are read",
163+
input: "Testname: behaviors\nBehaviors:\n- should behave\n- second behavior",
164+
expected: &conformanceData{TestName: "behaviors", Behaviors: []string{"should behave", "second behavior"}},
165+
}, {
166+
desc: "Multiple behaviors are parsed",
167+
input: "Testname: behaviors2\nBehaviors:\n- first behavior\n- second behavior",
168+
expected: &conformanceData{TestName: "behaviors2", Behaviors: []string{"first behavior", "second behavior"}},
161169
},
162170
}
163171

0 commit comments

Comments
 (0)