|
| 1 | +/* |
| 2 | +Copyright 2026 Flant JSC |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package precheck |
| 18 | + |
| 19 | +import ( |
| 20 | + "context" |
| 21 | + "fmt" |
| 22 | + "os" |
| 23 | + |
| 24 | + . "github.com/onsi/ginkgo/v2" |
| 25 | + |
| 26 | + "github.com/deckhouse/virtualization/test/e2e/internal/framework" |
| 27 | +) |
| 28 | + |
| 29 | +const ( |
| 30 | + postCleanupPrecheckEnvName = "POST_CLEANUP" |
| 31 | +) |
| 32 | + |
| 33 | +// postcleanupPrecheck implements Precheck interface for postcleanup option. |
| 34 | +// This is a common precheck that runs for all tests. |
| 35 | +type postcleanupPrecheck struct{} |
| 36 | + |
| 37 | +func (c *postcleanupPrecheck) Label() string { |
| 38 | + return PrecheckPostCleanup |
| 39 | +} |
| 40 | + |
| 41 | +func (c *postcleanupPrecheck) Run(ctx context.Context, f *framework.Framework) error { |
| 42 | + if !isCheckEnabled(postCleanupPrecheckEnvName) { |
| 43 | + _, _ = GinkgoWriter.Write([]byte("PostCleanup precheck is disabled.\n")) |
| 44 | + return nil |
| 45 | + } |
| 46 | + |
| 47 | + // Validate POST_CLEANUP env var |
| 48 | + env := os.Getenv(postCleanupPrecheckEnvName) |
| 49 | + switch env { |
| 50 | + case "yes", "no", "": |
| 51 | + // valid values |
| 52 | + default: |
| 53 | + return fmt.Errorf("invalid value for the %s env: %q (allowed: \"\", \"yes\", \"no\")", postCleanupPrecheckEnvName, env) |
| 54 | + } |
| 55 | + |
| 56 | + return nil |
| 57 | +} |
| 58 | + |
| 59 | +// Register postcleanup precheck as common (runs for all tests). |
| 60 | +func init() { |
| 61 | + RegisterPrecheck(&postcleanupPrecheck{}, true) |
| 62 | +} |
0 commit comments