package integration import ( "edge-infra.dev/test/framework" "edge-infra.dev/test/framework/config" ) var isIntegrationTest bool func init() { config.Flags.BoolVar(&isIntegrationTest, "integration", false, "whether or not this is an integration test run") } func IsIntegrationTest() bool { return isIntegrationTest } // Skip wraps the provided framework.Step function (intended to be a // skipping function, like k8s.NeedsKustomizeKonfig), only running the skipping // function if the test run is an integration test run, e.g.: // Skip(k8s.NeedsKustomizeKonfig) will not skip the test if it isn't // an integration test run, otherwise will execute k8s.NeedsKustomizeKonfig. // Allows writing skippers which only make sense in the context of integration // tests without nesting every function in checks for IsIntegrationTest() func Skip(steps ...framework.Step) framework.Step { return func(f *framework.Framework) { if isIntegrationTest && len(steps) > 0 { for _, s := range steps { s(f) } } } } // SkipIf skips a test if the current test run is an integration test func SkipIf(f *framework.Framework) { if isIntegrationTest { f.Skip("integration", "this test can only be ran as a unit test") } } // SkipIfNot skips a test if the current test run is not an integration test func SkipIfNot(f *framework.Framework) { if !isIntegrationTest { f.Skip("integration", "this test can only be ran as an integration test") } } // Only &&s the provided bool with isIntegrationTest to simplify writing // logic that checks a bool only during integration test runs. func Only(e bool) bool { return isIntegrationTest && e }