github.com/moby/docker@v26.1.3+incompatible/integration/plugin/common/main_test.go (about) 1 package common // import "github.com/docker/docker/integration/plugin/common" 2 3 import ( 4 "context" 5 "os" 6 "testing" 7 8 "github.com/docker/docker/testutil" 9 "github.com/docker/docker/testutil/environment" 10 "go.opentelemetry.io/otel" 11 "go.opentelemetry.io/otel/attribute" 12 "go.opentelemetry.io/otel/codes" 13 ) 14 15 var ( 16 testEnv *environment.Execution 17 baseContext context.Context 18 ) 19 20 func TestMain(m *testing.M) { 21 shutdown := testutil.ConfigureTracing() 22 ctx, span := otel.Tracer("").Start(context.Background(), "integration/plugin/common.TestMain") 23 baseContext = ctx 24 25 var err error 26 testEnv, err = environment.New(ctx) 27 if err != nil { 28 span.SetStatus(codes.Error, err.Error()) 29 span.End() 30 shutdown(ctx) 31 panic(err) 32 } 33 testEnv.Print() 34 ec := m.Run() 35 if ec != 0 { 36 span.SetStatus(codes.Error, "m.Run() returned non-zero exit code") 37 } 38 span.SetAttributes(attribute.Int("exit", ec)) 39 shutdown(ctx) 40 os.Exit(ec) 41 } 42 43 func setupTest(t *testing.T) context.Context { 44 ctx := testutil.StartSpan(baseContext, t) 45 environment.ProtectAll(ctx, t, testEnv) 46 t.Cleanup(func() { 47 testEnv.Clean(ctx, t) 48 }) 49 return ctx 50 }