From 844f9be3e757c049a07b6e3384f46d8c30275a81 Mon Sep 17 00:00:00 2001 From: Paco Xu Date: Fri, 1 Apr 2022 18:04:27 +0800 Subject: [PATCH] prevent the unit test name too long in report --- .../schema/cel/celcoststability_test.go | 41 +++++++++---------- .../apiserver/schema/cel/validation_test.go | 12 +++++- 2 files changed, 30 insertions(+), 23 deletions(-) diff --git a/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/cel/celcoststability_test.go b/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/cel/celcoststability_test.go index 30c65b967a8..20a38d4171b 100644 --- a/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/cel/celcoststability_test.go +++ b/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/cel/celcoststability_test.go @@ -1087,28 +1087,27 @@ func TestCelCostStability(t *testing.T) { t.Run(tt.name, func(t *testing.T) { t.Parallel() for validRule, expectedCost := range tt.expectCost { - t.Run(validRule, func(t *testing.T) { - validRule := validRule - expectedCost := expectedCost - t.Run(validRule, func(t *testing.T) { - t.Parallel() - s := withRule(*tt.schema, validRule) - celValidator := NewValidator(&s, PerCallLimit) - if celValidator == nil { - t.Fatal("expected non nil validator") - } - ctx := context.TODO() - errs, remainingBudegt := celValidator.Validate(ctx, field.NewPath("root"), &s, tt.obj, nil, RuntimeCELCostBudget) - for _, err := range errs { - t.Errorf("unexpected error: %v", err) - } - rtCost := RuntimeCELCostBudget - remainingBudegt - if rtCost != expectedCost { - t.Fatalf("runtime cost %d does not match expected runtime cost %d", rtCost, expectedCost) - } - }) + testName := validRule + if len(testName) > 127 { + testName = testName[:127] + } + t.Run(testName, func(t *testing.T) { + t.Parallel() + s := withRule(*tt.schema, validRule) + celValidator := NewValidator(&s, PerCallLimit) + if celValidator == nil { + t.Fatal("expected non nil validator") + } + ctx := context.TODO() + errs, remainingBudegt := celValidator.Validate(ctx, field.NewPath("root"), &s, tt.obj, nil, RuntimeCELCostBudget) + for _, err := range errs { + t.Errorf("unexpected error: %v", err) + } + rtCost := RuntimeCELCostBudget - remainingBudegt + if rtCost != expectedCost { + t.Fatalf("runtime cost %d does not match expected runtime cost %d", rtCost, expectedCost) + } }) - } }) } diff --git a/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/cel/validation_test.go b/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/cel/validation_test.go index b52c2263bcd..c1d827b25cb 100644 --- a/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/cel/validation_test.go +++ b/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/cel/validation_test.go @@ -1760,7 +1760,11 @@ func TestValidationExpressions(t *testing.T) { ctx := context.TODO() for j := range tt.valid { validRule := tt.valid[j] - t.Run(validRule, func(t *testing.T) { + testName := validRule + if len(testName) > 127 { + testName = testName[:127] + } + t.Run(testName, func(t *testing.T) { t.Parallel() s := withRule(*tt.schema, validRule) celValidator := validator(&s, tt.isRoot, PerCallLimit) @@ -1781,7 +1785,11 @@ func TestValidationExpressions(t *testing.T) { }) } for rule, expectErrToContain := range tt.errors { - t.Run(rule, func(t *testing.T) { + testName := rule + if len(testName) > 127 { + testName = testName[:127] + } + t.Run(testName, func(t *testing.T) { s := withRule(*tt.schema, rule) celValidator := NewValidator(&s, PerCallLimit) if celValidator == nil {