...

Source file src/edge-infra.dev/test/framework/integration/config.go

Documentation: edge-infra.dev/test/framework/integration

     1  package integration
     2  
     3  import (
     4  	"edge-infra.dev/test/framework"
     5  	"edge-infra.dev/test/framework/config"
     6  )
     7  
     8  var isIntegrationTest bool
     9  
    10  func init() {
    11  	config.Flags.BoolVar(&isIntegrationTest, "integration", false,
    12  		"whether or not this is an integration test run")
    13  }
    14  
    15  func IsIntegrationTest() bool {
    16  	return isIntegrationTest
    17  }
    18  
    19  // Skip wraps the provided framework.Step function (intended to be a
    20  // skipping function, like k8s.NeedsKustomizeKonfig), only running the skipping
    21  // function if the test run is an integration test run, e.g.:
    22  // Skip(k8s.NeedsKustomizeKonfig) will not skip the test if it isn't
    23  // an integration test run, otherwise will execute k8s.NeedsKustomizeKonfig.
    24  // Allows writing skippers which only make sense in the context of integration
    25  // tests without nesting every function in checks for IsIntegrationTest()
    26  func Skip(steps ...framework.Step) framework.Step {
    27  	return func(f *framework.Framework) {
    28  		if isIntegrationTest && len(steps) > 0 {
    29  			for _, s := range steps {
    30  				s(f)
    31  			}
    32  		}
    33  	}
    34  }
    35  
    36  // SkipIf skips a test if the current test run is an integration test
    37  func SkipIf(f *framework.Framework) {
    38  	if isIntegrationTest {
    39  		f.Skip("integration", "this test can only be ran as a unit test")
    40  	}
    41  }
    42  
    43  // SkipIfNot skips a test if the current test run is not an integration test
    44  func SkipIfNot(f *framework.Framework) {
    45  	if !isIntegrationTest {
    46  		f.Skip("integration", "this test can only be ran as an integration test")
    47  	}
    48  }
    49  
    50  // Only &&s the provided bool with isIntegrationTest to simplify writing
    51  // logic that checks a bool only during integration test runs.
    52  func Only(e bool) bool {
    53  	return isIntegrationTest && e
    54  }
    55  

View as plain text