Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions pkg/api/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,15 @@ func (m *Metadata) AsString() string {
return identifier
}

var shardSuffix = regexp.MustCompile(`-\d+of\d+$`)
// ShardSuffix matches shard suffixes like -1of2, -3of10 at the end of a string.
// These suffixes are reserved for infrastructure use and are stripped from test
// names during rehearsals.
var ShardSuffix = regexp.MustCompile(`-\d+of\d+$`)

// TestNameFromJobName returns the name of the test from a given job name and prefix
// If the test contains shard information in the suffix, that will also be trimmed
func (m *Metadata) TestNameFromJobName(jobName, prefix string) string {
jobName = shardSuffix.ReplaceAllString(jobName, "")
jobName = ShardSuffix.ReplaceAllString(jobName, "")
return strings.TrimPrefix(jobName, m.JobName(prefix, ""))
}

Expand Down
2 changes: 2 additions & 0 deletions pkg/validation/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ func (v *Validator) validateTestStepConfiguration(
validationErrors = append(validationErrors, fmt.Errorf("%s.as: duplicated name %q already declared in 'images'", fieldRootN, test.As))
} else if len(validation.IsDNS1123Subdomain(test.As)) != 0 {
validationErrors = append(validationErrors, fmt.Errorf("%s.as: '%s' is not a valid Kubernetes object name", fieldRootN, test.As))
} else if api.ShardSuffix.MatchString(test.As) {
validationErrors = append(validationErrors, fmt.Errorf("%s.as: '%s' ends with a shard suffix (e.g. -1of2) which is reserved for infrastructure use and will be stripped from the test name during rehearsals", fieldRootN, test.As))
}
if hasCommands, hasSteps, hasLiteral := len(test.Commands) != 0, test.MultiStageTestConfiguration != nil, test.MultiStageTestConfigurationLiteral != nil; !hasCommands && !hasSteps && !hasLiteral {
validationErrors = append(validationErrors, fmt.Errorf("%s: either `commands`, `steps`, or `literal_steps` should be set", fieldRootN))
Expand Down
22 changes: 22 additions & 0 deletions pkg/validation/test_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,28 @@ func TestValidateTests(t *testing.T) {
},
expectedError: errors.New("tests[0].as: should not begin with 'ci-index' because it gets confused with 'ci-index' and `ci-index-...` targets"),
},
{
id: `ReleaseBuildConfiguration{Tests: {As: "e2e-gcp-op-ocl-1of2"}}`,
tests: []api.TestStepConfiguration{
{
As: "e2e-gcp-op-ocl-1of2",
Commands: "commands",
ContainerTestConfiguration: &api.ContainerTestConfiguration{From: "ignored"},
},
},
expectedError: errors.New("tests[0].as: 'e2e-gcp-op-ocl-1of2' ends with a shard suffix (e.g. -1of2) which is reserved for infrastructure use and will be stripped from the test name during rehearsals"),
},
{
id: `ReleaseBuildConfiguration{Tests: {As: "e2e-test-3of10"}}`,
tests: []api.TestStepConfiguration{
{
As: "e2e-test-3of10",
Commands: "commands",
ContainerTestConfiguration: &api.ContainerTestConfiguration{From: "ignored"},
},
},
expectedError: errors.New("tests[0].as: 'e2e-test-3of10' ends with a shard suffix (e.g. -1of2) which is reserved for infrastructure use and will be stripped from the test name during rehearsals"),
},
{
id: "No test type",
tests: []api.TestStepConfiguration{
Expand Down