github.com/Jeffail/benthos/v3@v3.65.0/lib/test/integration/cache/integration_test.go (about) 1 package cache 2 3 import ( 4 "flag" 5 "fmt" 6 "regexp" 7 "testing" 8 9 _ "github.com/Jeffail/benthos/v3/public/components/all" 10 ) 11 12 var registeredIntegrationTests = map[string]func(*testing.T){} 13 14 // register an integration test that should only execute under the `integration` 15 // build tag. Returns an empty struct so that it can be called at a file root. 16 func registerIntegrationTest(name string, fn func(*testing.T)) struct{} { 17 if _, exists := registeredIntegrationTests[name]; exists { 18 panic(fmt.Sprintf("integration test double registered: %v", name)) 19 } 20 registeredIntegrationTests[name] = fn 21 return struct{}{} 22 } 23 24 // Placing this in its own function allows us to only execute under the 25 // integration build tag, but the tests themselves are always built. 26 func TestIntegration(t *testing.T) { 27 if m := flag.Lookup("test.run").Value.String(); m == "" || !regexp.MustCompile(m).MatchString(t.Name()) { 28 t.Skip("Skipping as execution was not requested explicitly using go test -run ^TestIntegration$") 29 } 30 31 for k, test := range registeredIntegrationTests { 32 test := test 33 t.Run(k, test) 34 } 35 }