From 4af480faff4c4d2816d170baa1565ca93d1bf3e7 Mon Sep 17 00:00:00 2001 From: Vitaliy Guschin Date: Thu, 7 Mar 2024 21:09:21 +0400 Subject: [PATCH] Refactor parallel package with passing excludedTests via Options. Signed-off-by: Vitaliy Guschin --- extensions/parallel/options.go | 31 +++++++++++++++++++++++++++++++ extensions/parallel/suite.go | 9 +++++++-- 2 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 extensions/parallel/options.go diff --git a/extensions/parallel/options.go b/extensions/parallel/options.go new file mode 100644 index 0000000000..c27432d070 --- /dev/null +++ b/extensions/parallel/options.go @@ -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 + } +} diff --git a/extensions/parallel/suite.go b/extensions/parallel/suite.go index 5eed1ebef9..d4492469dd 100644 --- a/extensions/parallel/suite.go +++ b/extensions/parallel/suite.go @@ -39,9 +39,14 @@ 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) { + parallelOpts := ¶llelOptions{} + for _, opt := range options { + opt(parallelOpts) + } + excludedTestsSet := make(map[string]struct{}) - for _, test := range excludedTests { + for _, test := range parallelOpts.excludedTests { excludedTestsSet[test] = struct{}{} }