github.com/onsi/ginkgo@v1.16.6-0.20211118180735-4e1925ba4c95/internal/internal_integration/internal_integration_suite_test.go (about) 1 package internal_integration_test 2 3 import ( 4 "io" 5 "reflect" 6 "testing" 7 8 . "github.com/onsi/ginkgo" 9 "github.com/onsi/ginkgo/internal" 10 "github.com/onsi/ginkgo/internal/global" 11 "github.com/onsi/ginkgo/internal/parallel_support" 12 . "github.com/onsi/ginkgo/internal/test_helpers" 13 "github.com/onsi/ginkgo/types" 14 . "github.com/onsi/gomega" 15 ) 16 17 func TestSuiteTests(t *testing.T) { 18 RegisterFailHandler(Fail) 19 RunSpecs(t, "Suite Integration Tests") 20 } 21 22 var conf types.SuiteConfig 23 var failer *internal.Failer 24 var writer *internal.Writer 25 var reporter *FakeReporter 26 var rt *RunTracker 27 var cl types.CodeLocation 28 var interruptHandler *FakeInterruptHandler 29 var outputInterceptor *FakeOutputInterceptor 30 31 var server parallel_support.Server 32 var client parallel_support.Client 33 var exitChannels map[int]chan interface{} 34 35 var _ = BeforeEach(func() { 36 conf = types.SuiteConfig{} 37 failer = internal.NewFailer() 38 writer = internal.NewWriter(io.Discard) 39 writer.SetMode(internal.WriterModeBufferOnly) 40 reporter = &FakeReporter{} 41 rt = NewRunTracker() 42 cl = types.NewCodeLocation(0) 43 interruptHandler = NewFakeInterruptHandler() 44 DeferCleanup(interruptHandler.Stop) 45 46 outputInterceptor = NewFakeOutputInterceptor() 47 48 conf.ParallelTotal = 1 49 conf.ParallelProcess = 1 50 conf.RandomSeed = 17 51 52 server, client, exitChannels = nil, nil, nil 53 }) 54 55 /* Helpers to set up and run test fixtures using the Ginkgo DSL */ 56 func WithSuite(suite *internal.Suite, callback func()) { 57 originalSuite, originalFailer := global.Suite, global.Failer 58 global.Suite = suite 59 global.Failer = failer 60 callback() 61 global.Suite = originalSuite 62 global.Failer = originalFailer 63 } 64 65 func SetUpForParallel(parallelTotal int) { 66 conf.ParallelTotal = parallelTotal 67 server, client, exitChannels = SetUpServerAndClient(conf.ParallelTotal) 68 conf.ParallelHost = server.Address() 69 } 70 71 func RunFixture(description string, callback func()) (bool, bool) { 72 suite := internal.NewSuite() 73 var success, hasProgrammaticFocus bool 74 WithSuite(suite, func() { 75 callback() 76 Ω(suite.BuildTree()).Should(Succeed()) 77 success, hasProgrammaticFocus = suite.Run(description, Label("TopLevelLabel"), "/path/to/suite", failer, reporter, writer, outputInterceptor, interruptHandler, client, conf) 78 }) 79 return success, hasProgrammaticFocus 80 } 81 82 func F(options ...interface{}) { 83 location := cl 84 message := "fail" 85 for _, option := range options { 86 if reflect.TypeOf(option).Kind() == reflect.String { 87 message = option.(string) 88 } else if reflect.TypeOf(option) == reflect.TypeOf(cl) { 89 location = option.(types.CodeLocation) 90 } 91 } 92 93 failer.Fail(message, location) 94 panic("panic to simulate how ginkgo's Fail works") 95 } 96 97 func Abort(options ...interface{}) { 98 location := cl 99 message := "abort" 100 for _, option := range options { 101 if reflect.TypeOf(option).Kind() == reflect.String { 102 message = option.(string) 103 } else if reflect.TypeOf(option) == reflect.TypeOf(cl) { 104 location = option.(types.CodeLocation) 105 } 106 } 107 108 failer.AbortSuite(message, location) 109 panic("panic to simulate how ginkgo's AbortSuite works") 110 } 111 112 func FixtureSkip(options ...interface{}) { 113 location := cl 114 message := "skip" 115 for _, option := range options { 116 if reflect.TypeOf(option).Kind() == reflect.String { 117 message = option.(string) 118 } else if reflect.TypeOf(option) == reflect.TypeOf(cl) { 119 location = option.(types.CodeLocation) 120 } 121 } 122 123 failer.Skip(message, location) 124 panic("panic to simulate how ginkgo's Skip works") 125 }