Skip to content

Commit 7f86cb1

Browse files
authored
Merge pull request kubernetes#72167 from brahmaroutu/conformance_context
Comment association to ConformanceIt block should be validated properly.
2 parents 5f91b68 + 1cb5872 commit 7f86cb1

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

test/conformance/walk.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,26 @@ func (v *visitor) failf(expr ast.Expr, format string, a ...interface{}) {
166166
func (v *visitor) comment(x *ast.BasicLit) string {
167167
for _, comm := range v.cMap.Comments() {
168168
testOffset := int(x.Pos()-comm.End()) - len("framework.ConformanceIt(\"")
169-
if 0 < testOffset && testOffset < 3 {
170-
return comm.Text()
169+
//Cannot assume the offset is within three or four tabs from the test block itself.
170+
//It is better to trim the newlines, tabs, etc and then we if the comment is followed
171+
//by the test block itself so that we can associate the comment with it properly.
172+
if 0 <= testOffset && testOffset <= 10 {
173+
b1 := make([]byte, x.Pos()-comm.End())
174+
//if we fail to open the file to compare the content we just assume the
175+
//proximity of the comment and apply it.
176+
myf, err := os.Open(v.FileSet.File(x.Pos()).Name())
177+
if err == nil {
178+
if _, err := myf.Seek(int64(comm.End()), 0); err == nil {
179+
if _, err := myf.Read(b1); err == nil {
180+
if strings.Compare(strings.Trim(string(b1), "\t \r\n"), "framework.ConformanceIt(\"") == 0 {
181+
return comm.Text()
182+
}
183+
}
184+
}
185+
} else {
186+
//comment section's end is noticed within 10 characters from framework.ConformanceIt block
187+
return comm.Text()
188+
}
171189
}
172190
}
173191
return ""

test/conformance/walk_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,18 @@ var _ = framework.KubeDescribe("Feature", func() {
8080
Description: `By default the stdout and stderr from the process
8181
being executed in a pod MUST be sent to the pod's logs.` + "\n\n"}},
8282
},
83+
{"e2e/foo.go", `
84+
var _ = framework.KubeDescribe("Feature", func() {
85+
Context("with context and extra spaces before It block should still pick up Testname", func() {
86+
// Testname: Test with spaces
87+
//Description: Should pick up testname even if it is not within 3 spaces
88+
//even when executed from memory.
89+
framework.ConformanceIt("should work", func() {})
90+
})
91+
})`, []conformanceData{{URL: "https://github.com/kubernetes/kubernetes/tree/master/e2e/foo.go#L8", TestName: "Test with spaces",
92+
Description: `Should pick up testname even if it is not within 3 spaces
93+
even when executed from memory.` + "\n\n"}},
94+
},
8395
}
8496

8597
func TestConformance(t *testing.T) {

0 commit comments

Comments
 (0)