Capture behaviors in walk.go

This commit is contained in:
Jefftree 2020-03-02 23:39:20 -08:00
parent 1836f95260
commit 6da6380d1b
2 changed files with 29 additions and 2 deletions

View File

@ -76,6 +76,8 @@ type conformanceData struct {
Release string Release string
// File is the filename where the test is defined. We intentionally don't save the line here to avoid meaningless changes. // File is the filename where the test is defined. We intentionally don't save the line here to avoid meaningless changes.
File string File string
// Behaviors is the list of conformance behaviors tested by a particular e2e test
Behaviors []string `yaml:"behaviors,omitempty"`
} }
func main() { func main() {
@ -292,23 +294,40 @@ func commentToConformanceData(comment string) *conformanceData {
lines := strings.Split(comment, "\n") lines := strings.Split(comment, "\n")
descLines := []string{} descLines := []string{}
cd := &conformanceData{} cd := &conformanceData{}
var curLine string
for _, line := range lines { for _, line := range lines {
line = strings.TrimSpace(line) line = strings.TrimSpace(line)
if len(line) == 0 { if len(line) == 0 {
continue continue
} }
if sline := regexp.MustCompile("^Testname\\s*:\\s*").Split(line, -1); len(sline) == 2 { if sline := regexp.MustCompile("^Testname\\s*:\\s*").Split(line, -1); len(sline) == 2 {
curLine = "Testname"
cd.TestName = sline[1] cd.TestName = sline[1]
continue continue
} }
if sline := regexp.MustCompile("^Release\\s*:\\s*").Split(line, -1); len(sline) == 2 { if sline := regexp.MustCompile("^Release\\s*:\\s*").Split(line, -1); len(sline) == 2 {
curLine = "Release"
cd.Release = sline[1] cd.Release = sline[1]
continue continue
} }
if sline := regexp.MustCompile("^Description\\s*:\\s*").Split(line, -1); len(sline) == 2 { if sline := regexp.MustCompile("^Description\\s*:\\s*").Split(line, -1); len(sline) == 2 {
line = sline[1] curLine = "Description"
descLines = append(descLines, sline[1])
continue
}
if sline := regexp.MustCompile("^Behaviors\\s*:\\s*").Split(line, -1); len(sline) == 2 {
curLine = "Behaviors"
continue
}
// Line has no header
if curLine == "Behaviors" {
if sline := regexp.MustCompile("^-\\s").Split(line, -1); len(sline) == 2 {
cd.Behaviors = append(cd.Behaviors, sline[1])
}
} else if curLine == "Description" {
descLines = append(descLines, line)
} }
descLines = append(descLines, line)
} }
if cd.Release == "" && cd.TestName == "" { if cd.Release == "" && cd.TestName == "" {
return nil return nil

View File

@ -158,6 +158,14 @@ func TestCommentToConformanceData(t *testing.T) {
desc: "All fields parsed and newlines and whitespace removed from description", desc: "All fields parsed and newlines and whitespace removed from description",
input: "Release: v1.1\n\t\tTestname: mytest\n\t\tDescription: foo\n\t\tbar\ndone", input: "Release: v1.1\n\t\tTestname: mytest\n\t\tDescription: foo\n\t\tbar\ndone",
expected: &conformanceData{TestName: "mytest", Release: "v1.1", Description: "foo bar done"}, expected: &conformanceData{TestName: "mytest", Release: "v1.1", Description: "foo bar done"},
}, {
desc: "Behaviors are read",
input: "Testname: behaviors\nBehaviors:\n- should behave\n- second behavior",
expected: &conformanceData{TestName: "behaviors", Behaviors: []string{"should behave", "second behavior"}},
}, {
desc: "Multiple behaviors are parsed",
input: "Testname: behaviors2\nBehaviors:\n- first behavior\n- second behavior",
expected: &conformanceData{TestName: "behaviors2", Behaviors: []string{"first behavior", "second behavior"}},
}, },
} }