Skip to content

Commit

Permalink
Refactor parallel package with passing excludedTests via Options.
Browse files Browse the repository at this point in the history
Signed-off-by: Vitaliy Guschin <vitaliy.guschin@spirent.com>
  • Loading branch information
Vitaliy Guschin committed Mar 7, 2024
1 parent 83f3cb0 commit afdd9e1
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
31 changes: 31 additions & 0 deletions extensions/parallel/options.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) 2024 Pragmagic Inc. and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package parallel

type parallelOptions struct {
excludedTests []string
}

// Option is an option pattern for parallel package
type Option func(o *parallelOptions)

// WithExcludedTests - set a list of tests to exclude from parallel execution
func WithExcludedTests(tests []string) Option {
return func(o *parallelOptions) {
o.excludedTests = tests
}
}
10 changes: 8 additions & 2 deletions extensions/parallel/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,15 @@ func failOnPanic(t *testing.T, r interface{}) {
}

// Run runs suite tests in parallel
func Run(t *testing.T, s suite.TestingSuite, excludedTests ...string) {
func Run(t *testing.T, s suite.TestingSuite, options ...Option) {

Check failure on line 42 in extensions/parallel/suite.go

View workflow job for this annotation

GitHub Actions / golangci-lint / golangci-lint

unnecessary leading newline (whitespace)

parallelOpts := &parallelOptions{}
for _, opt := range options {
opt(parallelOpts)
}

excludedTestsSet := make(map[string]struct{})
for _, test := range excludedTests {
for _, test := range parallelOpts.excludedTests {
excludedTestsSet[test] = struct{}{}
}

Expand Down

0 comments on commit afdd9e1

Please sign in to comment.