Unverified Commit 5fa945a1 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #64128 from yujuhong/conformance-txt

Automatic merge from submit-queue (batch tested with PRs 63417, 64249, 64242, 64128, 64275). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. conformance testdata: remove tags and trim spaces **What this PR does / why we need it**: To detect whether conformance tests have been changed, the test argument with the `ConformanceIt` is recorded to conformance.txt. This change remove additional tags (e.g., [Feature:]) and trim spaces, so that the detection is less-prone to noise. **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*: Fixes # **Special notes for your reviewer**: **Release note**: ```release-note NONE ```
parents 7a7ab200 1816d4ec
...@@ -176,10 +176,11 @@ func (v *visitor) emit(arg ast.Expr) { ...@@ -176,10 +176,11 @@ func (v *visitor) emit(arg ast.Expr) {
return return
} }
at.Value = normalizeTestName(at.Value)
if *confDoc { if *confDoc {
v.convertToConformanceData(at) v.convertToConformanceData(at)
} else { } else {
fmt.Printf("%s: %s\n", v.FileSet.Position(at.Pos()).Filename, at.Value) fmt.Printf("%s: %q\n", v.FileSet.Position(at.Pos()).Filename, at.Value)
} }
default: default:
v.failf(at, "framework.ConformanceIt() called with non-literal argument") v.failf(at, "framework.ConformanceIt() called with non-literal argument")
...@@ -197,6 +198,18 @@ func (v *visitor) getDescription(value string) string { ...@@ -197,6 +198,18 @@ func (v *visitor) getDescription(value string) string {
" " + strings.Trim(value, "\"") " " + strings.Trim(value, "\"")
} }
var (
regexTag = regexp.MustCompile(`(\[[a-zA-Z0-9:-]+\])`)
)
// normalizeTestName removes tags (e.g., [Feature:Foo]), double quotes and trim
// the spaces to normalize the test name.
func normalizeTestName(s string) string {
r := regexTag.ReplaceAllString(s, "")
r = strings.Trim(r, "\"")
return strings.TrimSpace(r)
}
// funcName converts a selectorExpr with two idents into a string, // funcName converts a selectorExpr with two idents into a string,
// x.y -> "x.y" // x.y -> "x.y"
func funcName(n ast.Expr) string { func funcName(n ast.Expr) string {
......
...@@ -93,3 +93,25 @@ func TestConformance(t *testing.T) { ...@@ -93,3 +93,25 @@ func TestConformance(t *testing.T) {
} }
} }
} }
func TestNormalizeTestNames(t *testing.T) {
testCases := []struct {
rawName string
normalizedName string
}{
{
"should have monotonically increasing restart count [Slow]",
"should have monotonically increasing restart count",
},
{
" should check is all data is printed ",
"should check is all data is printed",
},
}
for i, tc := range testCases {
actualName := normalizeTestName(tc.rawName)
if actualName != tc.normalizedName {
t.Errorf("test case[%d]: expected normalized name %q, got %q", i, tc.normalizedName, actualName)
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment