-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(e2e): support stopping on failure (#482)
* refactor(e2e): support stopping on failure, use FOCUS env - Remove dedicated task run_one - Rename run to run:ci, run_local to run. - STOP_ON_FAILURE=yes env to stop test on first failure - Add KUBECONFIG env into documentation --------- Signed-off-by: Ivan Mikheykin <[email protected]>
- Loading branch information
Showing
16 changed files
with
226 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
Copyright 2024 Flant JSC | ||
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 ginkgoutil | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/onsi/ginkgo/v2" | ||
) | ||
|
||
// Ginkgo decorators helpers: | ||
// - Common decorators for e2e: Ordered and ContinueOnFailure. | ||
// - ContinueOnFailure decorator is switchable and can be disabled with STOP_ON_FAILURE=yes env. | ||
// | ||
// A quote from Ginkgo documentation: | ||
// Moreover, Ginkgo also supports passing in arbitrarily nested slices of decorators. | ||
// Ginkgo will unroll these slices and process the flattened list. This makes it easier | ||
// to pass around groups of decorators. For example, this is valid: | ||
// markFlaky := []interface{}{Label("flaky"), FlakeAttempts(3)} | ||
// var _ = Describe("a bunch of flaky controller tests", markFlaky, Label("controller"), func() { | ||
// ... | ||
// } | ||
// The resulting tests will be decorated with FlakeAttempts(3) and the two labels flaky and controller. | ||
// | ||
// This helper uses this "flattening" feature, so DecoratorsFromEnv implements | ||
// dynamic list of switchable decorators by returning an array of decorators. | ||
|
||
type EnvSwitchable interface { | ||
Decorator() interface{} | ||
} | ||
|
||
func DecoratorsFromEnv(decorators ...interface{}) []interface{} { | ||
out := make([]interface{}, 0) | ||
|
||
for _, decorator := range decorators { | ||
switch v := decorator.(type) { | ||
case EnvSwitchable: | ||
gdeco := v.Decorator() | ||
if gdeco != nil { | ||
out = append(out, gdeco) | ||
} | ||
default: | ||
out = append(out, decorator) | ||
} | ||
} | ||
|
||
return out | ||
} | ||
|
||
const StopOnFailureEnv = "STOP_ON_FAILURE" | ||
|
||
type FailureBehaviourEnvSwitcher struct{} | ||
|
||
func (f FailureBehaviourEnvSwitcher) Decorator() interface{} { | ||
if !f.IsStopOnFailure() { | ||
return ginkgo.ContinueOnFailure | ||
} | ||
return nil | ||
} | ||
|
||
// IsStopOnFailure returns true if Stop on error is enabled. | ||
func (f FailureBehaviourEnvSwitcher) IsStopOnFailure() bool { | ||
return os.Getenv(StopOnFailureEnv) == "yes" | ||
} | ||
|
||
// CommonE2ETestDecorators returns common decorators for e2e tests: Ordered and ContinueOnFailure switchable with env. | ||
func CommonE2ETestDecorators() []interface{} { | ||
return DecoratorsFromEnv( | ||
ginkgo.Ordered, | ||
FailureBehaviourEnvSwitcher{}, | ||
) | ||
} |
Oops, something went wrong.