// Package integrationlevels demonstrates how tests can conditionally change behavior based on the integration test level package integrationlevels import ( "context" "os" "testing" "gotest.tools/v3/assert" "edge-infra.dev/test/f2" "edge-infra.dev/test/f2/integration" ) // you can use flags to run these tests // bazel test //test/f2/examples/integrationlevels/... --test_arg=-integration-level=2 // or you can use the test/config.json file // ex: // { // "integration-level": 1 // } var f f2.Framework func TestMain(m *testing.M) { f = f2.New(context.Background()) os.Exit(f.Run(m)) } func TestSkipIfNot(t *testing.T) { // You can skip an entire Test function // if the integration level isnt what you expect integration.SkipIfNot(t, integration.L2) fin := f2.NewFeature("SkipIfNot"). Test("test skip if not", func(ctx f2.Context, t *testing.T) f2.Context { t.Log("in SkipIfNot", "level", 2) assert.Assert(t, true) return ctx }).Feature() f.Test(t, fin) } func TestSkipIf(t *testing.T) { fin := f2.NewFeature("SkipIf"). Test("test skip if", func(ctx f2.Context, t *testing.T) f2.Context { // or you can skip a specific test integration.SkipIf(t, integration.L2) t.Log("in SkipIf", "level", 1) assert.Assert(t, true) return ctx }).Feature() f.Test(t, fin) } func TestLevels(t *testing.T) { fin := f2.NewFeature("Levels"). Test("test levels", func(ctx f2.Context, t *testing.T) f2.Context { // If your test requires different functionality depending // on the integration level // ie: // level 1 needs to create an embedded postgres database if integration.IsL1() { t.Log("in TestLevels", "level", 1) } // level 2 needs to connect to a live postgres database if integration.IsL2() { t.Log("in TestLevels", "level", 2) } assert.Assert(t, true) return ctx }).Feature() f.Test(t, fin) }