How to use It method of ginkgo Package

Best Ginkgo code snippet using ginkgo.It

ginkgo_dsl.go

Source:ginkgo_dsl.go Github

copy

Full Screen

...53//The interface by which Ginkgo receives *testing.T54type GinkgoTestingT interface {55 Fail()56}57//GinkgoRandomSeed returns the seed used to randomize spec execution order. It is58//useful for seeding your own pseudorandom number generators (PRNGs) to ensure59//consistent executions from run to run, where your tests contain variability (for60//example, when selecting random test data).61func GinkgoRandomSeed() int64 {62 return config.GinkgoConfig.RandomSeed63}64//GinkgoParallelNode returns the parallel node number for the current ginkgo process65//The node number is 1-indexed66func GinkgoParallelNode() int {67 return config.GinkgoConfig.ParallelNode68}69//Some matcher libraries or legacy codebases require a *testing.T70//GinkgoT implements an interface analogous to *testing.T and can be used if71//the library in question accepts *testing.T through an interface72//73// For example, with testify:74// assert.Equal(GinkgoT(), 123, 123, "they should be equal")75//76// Or with gomock:77// gomock.NewController(GinkgoT())78//79// GinkgoT() takes an optional offset argument that can be used to get the80// correct line number associated with the failure.81func GinkgoT(optionalOffset ...int) GinkgoTInterface {82 offset := 383 if len(optionalOffset) > 0 {84 offset = optionalOffset[0]85 }86 return testingtproxy.New(GinkgoWriter, Fail, offset)87}88//The interface returned by GinkgoT(). This covers most of the methods89//in the testing package's T.90type GinkgoTInterface interface {91 Fail()92 Error(args ...interface{})93 Errorf(format string, args ...interface{})94 FailNow()95 Fatal(args ...interface{})96 Fatalf(format string, args ...interface{})97 Log(args ...interface{})98 Logf(format string, args ...interface{})99 Failed() bool100 Parallel()101 Skip(args ...interface{})102 Skipf(format string, args ...interface{})103 SkipNow()104 Skipped() bool105}106//Custom Ginkgo test reporters must implement the Reporter interface.107//108//The custom reporter is passed in a SuiteSummary when the suite begins and ends,109//and a SpecSummary just before a spec begins and just after a spec ends110type Reporter reporters.Reporter111//Asynchronous specs are given a channel of the Done type. You must close or write to the channel112//to tell Ginkgo that your async test is done.113type Done chan<- interface{}114//GinkgoTestDescription represents the information about the current running test returned by CurrentGinkgoTestDescription115// FullTestText: a concatenation of ComponentTexts and the TestText116// ComponentTexts: a list of all texts for the Describes & Contexts leading up to the current test117// TestText: the text in the actual It or Measure node118// IsMeasurement: true if the current test is a measurement119// FileName: the name of the file containing the current test120// LineNumber: the line number for the current test121// Failed: if the current test has failed, this will be true (useful in an AfterEach)122type GinkgoTestDescription struct {123 FullTestText string124 ComponentTexts []string125 TestText string126 IsMeasurement bool127 FileName string128 LineNumber int129 Failed bool130 Duration time.Duration131}132//CurrentGinkgoTestDescripton returns information about the current running test.133func CurrentGinkgoTestDescription() GinkgoTestDescription {134 summary, ok := globalSuite.CurrentRunningSpecSummary()135 if !ok {136 return GinkgoTestDescription{}137 }138 subjectCodeLocation := summary.ComponentCodeLocations[len(summary.ComponentCodeLocations)-1]139 return GinkgoTestDescription{140 ComponentTexts: summary.ComponentTexts[1:],141 FullTestText: strings.Join(summary.ComponentTexts[1:], " "),142 TestText: summary.ComponentTexts[len(summary.ComponentTexts)-1],143 IsMeasurement: summary.IsMeasurement,144 FileName: subjectCodeLocation.FileName,145 LineNumber: subjectCodeLocation.LineNumber,146 Failed: summary.HasFailureState(),147 Duration: summary.RunTime,148 }149}150//Measurement tests receive a Benchmarker.151//152//You use the Time() function to time how long the passed in body function takes to run153//You use the RecordValue() function to track arbitrary numerical measurements.154//The RecordValueWithPrecision() function can be used alternatively to provide the unit155//and resolution of the numeric measurement.156//The optional info argument is passed to the test reporter and can be used to157// provide the measurement data to a custom reporter with context.158//159//See http://onsi.github.io/ginkgo/#benchmark_tests for more details160type Benchmarker interface {161 Time(name string, body func(), info ...interface{}) (elapsedTime time.Duration)162 RecordValue(name string, value float64, info ...interface{})163 RecordValueWithPrecision(name string, value float64, units string, precision int, info ...interface{})164}165//RunSpecs is the entry point for the Ginkgo test runner.166//You must call this within a Golang testing TestX(t *testing.T) function.167//168//To bootstrap a test suite you can use the Ginkgo CLI:169//170// ginkgo bootstrap171func RunSpecs(t GinkgoTestingT, description string) bool {172 specReporters := []Reporter{buildDefaultReporter()}173 return RunSpecsWithCustomReporters(t, description, specReporters)174}175//To run your tests with Ginkgo's default reporter and your custom reporter(s), replace176//RunSpecs() with this method.177func RunSpecsWithDefaultAndCustomReporters(t GinkgoTestingT, description string, specReporters []Reporter) bool {178 specReporters = append(specReporters, buildDefaultReporter())179 return RunSpecsWithCustomReporters(t, description, specReporters)180}181//To run your tests with your custom reporter(s) (and *not* Ginkgo's default reporter), replace182//RunSpecs() with this method. Note that parallel tests will not work correctly without the default reporter183func RunSpecsWithCustomReporters(t GinkgoTestingT, description string, specReporters []Reporter) bool {184 writer := GinkgoWriter.(*writer.Writer)185 writer.SetStream(config.DefaultReporterConfig.Verbose)186 reporters := make([]reporters.Reporter, len(specReporters))187 for i, reporter := range specReporters {188 reporters[i] = reporter189 }190 passed, hasFocusedTests := globalSuite.Run(t, description, reporters, writer, config.GinkgoConfig)191 if passed && hasFocusedTests && strings.TrimSpace(os.Getenv("GINKGO_EDITOR_INTEGRATION")) == "" {192 fmt.Println("PASS | FOCUSED")193 os.Exit(types.GINKGO_FOCUS_EXIT_CODE)194 }195 return passed196}197func buildDefaultReporter() Reporter {198 remoteReportingServer := config.GinkgoConfig.StreamHost199 if remoteReportingServer == "" {200 stenographer := stenographer.New(!config.DefaultReporterConfig.NoColor, config.GinkgoConfig.FlakeAttempts > 1, colorable.NewColorableStdout())201 return reporters.NewDefaultReporter(config.DefaultReporterConfig, stenographer)202 } else {203 debugFile := ""204 if config.GinkgoConfig.DebugParallel {205 debugFile = fmt.Sprintf("ginkgo-node-%d.log", config.GinkgoConfig.ParallelNode)206 }207 return remote.NewForwardingReporter(config.DefaultReporterConfig, remoteReportingServer, &http.Client{}, remote.NewOutputInterceptor(), GinkgoWriter.(*writer.Writer), debugFile)208 }209}210//Skip notifies Ginkgo that the current spec was skipped.211func Skip(message string, callerSkip ...int) {212 skip := 0213 if len(callerSkip) > 0 {214 skip = callerSkip[0]215 }216 globalFailer.Skip(message, codelocation.New(skip+1))217 panic(GINKGO_PANIC)218}219//Fail notifies Ginkgo that the current spec has failed. (Gomega will call Fail for you automatically when an assertion fails.)220func Fail(message string, callerSkip ...int) {221 skip := 0222 if len(callerSkip) > 0 {223 skip = callerSkip[0]224 }225 globalFailer.Fail(message, codelocation.New(skip+1))226 panic(GINKGO_PANIC)227}228//GinkgoRecover should be deferred at the top of any spawned goroutine that (may) call `Fail`229//Since Gomega assertions call fail, you should throw a `defer GinkgoRecover()` at the top of any goroutine that230//calls out to Gomega231//232//Here's why: Ginkgo's `Fail` method records the failure and then panics to prevent233//further assertions from running. This panic must be recovered. Ginkgo does this for you234//if the panic originates in a Ginkgo node (an It, BeforeEach, etc...)235//236//Unfortunately, if a panic originates on a goroutine *launched* from one of these nodes there's no237//way for Ginkgo to rescue the panic. To do this, you must remember to `defer GinkgoRecover()` at the top of such a goroutine.238func GinkgoRecover() {239 e := recover()240 if e != nil {241 globalFailer.Panic(codelocation.New(1), e)242 }243}244//Describe blocks allow you to organize your specs. A Describe block can contain any number of245//BeforeEach, AfterEach, JustBeforeEach, It, and Measurement blocks.246//247//In addition you can nest Describe, Context and When blocks. Describe, Context and When blocks are functionally248//equivalent. The difference is purely semantic -- you typical Describe the behavior of an object249//or method and, within that Describe, outline a number of Contexts and Whens.250func Describe(text string, body func()) bool {251 globalSuite.PushContainerNode(text, body, types.FlagTypeNone, codelocation.New(1))252 return true253}254//You can focus the tests within a describe block using FDescribe255func FDescribe(text string, body func()) bool {256 globalSuite.PushContainerNode(text, body, types.FlagTypeFocused, codelocation.New(1))257 return true258}259//You can mark the tests within a describe block as pending using PDescribe260func PDescribe(text string, body func()) bool {261 globalSuite.PushContainerNode(text, body, types.FlagTypePending, codelocation.New(1))262 return true263}264//You can mark the tests within a describe block as pending using XDescribe265func XDescribe(text string, body func()) bool {266 globalSuite.PushContainerNode(text, body, types.FlagTypePending, codelocation.New(1))267 return true268}269//Context blocks allow you to organize your specs. A Context block can contain any number of270//BeforeEach, AfterEach, JustBeforeEach, It, and Measurement blocks.271//272//In addition you can nest Describe, Context and When blocks. Describe, Context and When blocks are functionally273//equivalent. The difference is purely semantic -- you typical Describe the behavior of an object274//or method and, within that Describe, outline a number of Contexts and Whens.275func Context(text string, body func()) bool {276 globalSuite.PushContainerNode(text, body, types.FlagTypeNone, codelocation.New(1))277 return true278}279//You can focus the tests within a describe block using FContext280func FContext(text string, body func()) bool {281 globalSuite.PushContainerNode(text, body, types.FlagTypeFocused, codelocation.New(1))282 return true283}284//You can mark the tests within a describe block as pending using PContext285func PContext(text string, body func()) bool {286 globalSuite.PushContainerNode(text, body, types.FlagTypePending, codelocation.New(1))287 return true288}289//You can mark the tests within a describe block as pending using XContext290func XContext(text string, body func()) bool {291 globalSuite.PushContainerNode(text, body, types.FlagTypePending, codelocation.New(1))292 return true293}294//When blocks allow you to organize your specs. A When block can contain any number of295//BeforeEach, AfterEach, JustBeforeEach, It, and Measurement blocks.296//297//In addition you can nest Describe, Context and When blocks. Describe, Context and When blocks are functionally298//equivalent. The difference is purely semantic -- you typical Describe the behavior of an object299//or method and, within that Describe, outline a number of Contexts and Whens.300func When(text string, body func()) bool {301 globalSuite.PushContainerNode("when "+text, body, types.FlagTypeNone, codelocation.New(1))302 return true303}304//You can focus the tests within a describe block using FWhen305func FWhen(text string, body func()) bool {306 globalSuite.PushContainerNode("when "+text, body, types.FlagTypeFocused, codelocation.New(1))307 return true308}309//You can mark the tests within a describe block as pending using PWhen310func PWhen(text string, body func()) bool {311 globalSuite.PushContainerNode("when "+text, body, types.FlagTypePending, codelocation.New(1))312 return true313}314//You can mark the tests within a describe block as pending using XWhen315func XWhen(text string, body func()) bool {316 globalSuite.PushContainerNode("when "+text, body, types.FlagTypePending, codelocation.New(1))317 return true318}319//It blocks contain your test code and assertions. You cannot nest any other Ginkgo blocks320//within an It block.321//322//Ginkgo will normally run It blocks synchronously. To perform asynchronous tests, pass a323//function that accepts a Done channel. When you do this, you can also provide an optional timeout.324func It(text string, body interface{}, timeout ...float64) bool {325 globalSuite.PushItNode(text, body, types.FlagTypeNone, codelocation.New(1), parseTimeout(timeout...))326 return true327}328//You can focus individual Its using FIt329func FIt(text string, body interface{}, timeout ...float64) bool {330 globalSuite.PushItNode(text, body, types.FlagTypeFocused, codelocation.New(1), parseTimeout(timeout...))331 return true332}333//You can mark Its as pending using PIt334func PIt(text string, _ ...interface{}) bool {335 globalSuite.PushItNode(text, func() {}, types.FlagTypePending, codelocation.New(1), 0)336 return true337}338//You can mark Its as pending using XIt339func XIt(text string, _ ...interface{}) bool {340 globalSuite.PushItNode(text, func() {}, types.FlagTypePending, codelocation.New(1), 0)341 return true342}343//Specify blocks are aliases for It blocks and allow for more natural wording in situations344//which "It" does not fit into a natural sentence flow. All the same protocols apply for Specify blocks345//which apply to It blocks.346func Specify(text string, body interface{}, timeout ...float64) bool {347 globalSuite.PushItNode(text, body, types.FlagTypeNone, codelocation.New(1), parseTimeout(timeout...))348 return true349}350//You can focus individual Specifys using FSpecify351func FSpecify(text string, body interface{}, timeout ...float64) bool {352 globalSuite.PushItNode(text, body, types.FlagTypeFocused, codelocation.New(1), parseTimeout(timeout...))353 return true354}355//You can mark Specifys as pending using PSpecify356func PSpecify(text string, is ...interface{}) bool {357 globalSuite.PushItNode(text, func() {}, types.FlagTypePending, codelocation.New(1), 0)358 return true359}360//You can mark Specifys as pending using XSpecify361func XSpecify(text string, is ...interface{}) bool {362 globalSuite.PushItNode(text, func() {}, types.FlagTypePending, codelocation.New(1), 0)363 return true364}365//By allows you to better document large Its.366//367//Generally you should try to keep your Its short and to the point. This is not always possible, however,368//especially in the context of integration tests that capture a particular workflow.369//370//By allows you to document such flows. By must be called within a runnable node (It, BeforeEach, Measure, etc...)371//By will simply log the passed in text to the GinkgoWriter. If By is handed a function it will immediately run the function.372func By(text string, callbacks ...func()) {373 preamble := "\x1b[1mSTEP\x1b[0m"374 if config.DefaultReporterConfig.NoColor {375 preamble = "STEP"376 }377 fmt.Fprintln(GinkgoWriter, preamble+": "+text)378 if len(callbacks) == 1 {379 callbacks[0]()380 }381 if len(callbacks) > 1 {382 panic("just one callback per By, please")383 }384}385//Measure blocks run the passed in body function repeatedly (determined by the samples argument)386//and accumulate metrics provided to the Benchmarker by the body function.387//388//The body function must have the signature:389// func(b Benchmarker)390func Measure(text string, body interface{}, samples int) bool {391 globalSuite.PushMeasureNode(text, body, types.FlagTypeNone, codelocation.New(1), samples)392 return true393}394//You can focus individual Measures using FMeasure395func FMeasure(text string, body interface{}, samples int) bool {396 globalSuite.PushMeasureNode(text, body, types.FlagTypeFocused, codelocation.New(1), samples)397 return true398}399//You can mark Maeasurements as pending using PMeasure400func PMeasure(text string, _ ...interface{}) bool {401 globalSuite.PushMeasureNode(text, func(b Benchmarker) {}, types.FlagTypePending, codelocation.New(1), 0)402 return true403}404//You can mark Maeasurements as pending using XMeasure405func XMeasure(text string, _ ...interface{}) bool {406 globalSuite.PushMeasureNode(text, func(b Benchmarker) {}, types.FlagTypePending, codelocation.New(1), 0)407 return true408}409//BeforeSuite blocks are run just once before any specs are run. When running in parallel, each410//parallel node process will call BeforeSuite.411//412//BeforeSuite blocks can be made asynchronous by providing a body function that accepts a Done channel413//414//You may only register *one* BeforeSuite handler per test suite. You typically do so in your bootstrap file at the top level.415func BeforeSuite(body interface{}, timeout ...float64) bool {416 globalSuite.SetBeforeSuiteNode(body, codelocation.New(1), parseTimeout(timeout...))417 return true418}419//AfterSuite blocks are *always* run after all the specs regardless of whether specs have passed or failed.420//Moreover, if Ginkgo receives an interrupt signal (^C) it will attempt to run the AfterSuite before exiting.421//422//When running in parallel, each parallel node process will call AfterSuite.423//424//AfterSuite blocks can be made asynchronous by providing a body function that accepts a Done channel425//426//You may only register *one* AfterSuite handler per test suite. You typically do so in your bootstrap file at the top level.427func AfterSuite(body interface{}, timeout ...float64) bool {428 globalSuite.SetAfterSuiteNode(body, codelocation.New(1), parseTimeout(timeout...))429 return true430}431//SynchronizedBeforeSuite blocks are primarily meant to solve the problem of setting up singleton external resources shared across432//nodes when running tests in parallel. For example, say you have a shared database that you can only start one instance of that433//must be used in your tests. When running in parallel, only one node should set up the database and all other nodes should wait434//until that node is done before running.435//436//SynchronizedBeforeSuite accomplishes this by taking *two* function arguments. The first is only run on parallel node #1. The second is437//run on all nodes, but *only* after the first function completes succesfully. Ginkgo also makes it possible to send data from the first function (on Node 1)438//to the second function (on all the other nodes).439//440//The functions have the following signatures. The first function (which only runs on node 1) has the signature:441//442// func() []byte443//444//or, to run asynchronously:445//446// func(done Done) []byte447//448//The byte array returned by the first function is then passed to the second function, which has the signature:449//450// func(data []byte)451//452//or, to run asynchronously:453//454// func(data []byte, done Done)455//456//Here's a simple pseudo-code example that starts a shared database on Node 1 and shares the database's address with the other nodes:457//458// var dbClient db.Client459// var dbRunner db.Runner460//461// var _ = SynchronizedBeforeSuite(func() []byte {462// dbRunner = db.NewRunner()463// err := dbRunner.Start()464// Ω(err).ShouldNot(HaveOccurred())465// return []byte(dbRunner.URL)466// }, func(data []byte) {467// dbClient = db.NewClient()468// err := dbClient.Connect(string(data))469// Ω(err).ShouldNot(HaveOccurred())470// })471func SynchronizedBeforeSuite(node1Body interface{}, allNodesBody interface{}, timeout ...float64) bool {472 globalSuite.SetSynchronizedBeforeSuiteNode(473 node1Body,474 allNodesBody,475 codelocation.New(1),476 parseTimeout(timeout...),477 )478 return true479}480//SynchronizedAfterSuite blocks complement the SynchronizedBeforeSuite blocks in solving the problem of setting up481//external singleton resources shared across nodes when running tests in parallel.482//483//SynchronizedAfterSuite accomplishes this by taking *two* function arguments. The first runs on all nodes. The second runs only on parallel node #1484//and *only* after all other nodes have finished and exited. This ensures that node 1, and any resources it is running, remain alive until485//all other nodes are finished.486//487//Both functions have the same signature: either func() or func(done Done) to run asynchronously.488//489//Here's a pseudo-code example that complements that given in SynchronizedBeforeSuite. Here, SynchronizedAfterSuite is used to tear down the shared database490//only after all nodes have finished:491//492// var _ = SynchronizedAfterSuite(func() {493// dbClient.Cleanup()494// }, func() {495// dbRunner.Stop()496// })497func SynchronizedAfterSuite(allNodesBody interface{}, node1Body interface{}, timeout ...float64) bool {498 globalSuite.SetSynchronizedAfterSuiteNode(499 allNodesBody,500 node1Body,501 codelocation.New(1),502 parseTimeout(timeout...),503 )504 return true505}506//BeforeEach blocks are run before It blocks. When multiple BeforeEach blocks are defined in nested507//Describe and Context blocks the outermost BeforeEach blocks are run first.508//509//Like It blocks, BeforeEach blocks can be made asynchronous by providing a body function that accepts510//a Done channel511func BeforeEach(body interface{}, timeout ...float64) bool {512 globalSuite.PushBeforeEachNode(body, codelocation.New(1), parseTimeout(timeout...))513 return true514}515//JustBeforeEach blocks are run before It blocks but *after* all BeforeEach blocks. For more details,516//read the [documentation](http://onsi.github.io/ginkgo/#separating_creation_and_configuration_)517//518//Like It blocks, BeforeEach blocks can be made asynchronous by providing a body function that accepts519//a Done channel520func JustBeforeEach(body interface{}, timeout ...float64) bool {521 globalSuite.PushJustBeforeEachNode(body, codelocation.New(1), parseTimeout(timeout...))522 return true523}524//JustAfterEach blocks are run after It blocks but *before* all AfterEach blocks. For more details,525//read the [documentation](http://onsi.github.io/ginkgo/#separating_creation_and_configuration_)526//527//Like It blocks, JustAfterEach blocks can be made asynchronous by providing a body function that accepts528//a Done channel529func JustAfterEach(body interface{}, timeout ...float64) bool {530 globalSuite.PushJustAfterEachNode(body, codelocation.New(1), parseTimeout(timeout...))531 return true532}533//AfterEach blocks are run after It blocks. When multiple AfterEach blocks are defined in nested534//Describe and Context blocks the innermost AfterEach blocks are run first.535//536//Like It blocks, AfterEach blocks can be made asynchronous by providing a body function that accepts537//a Done channel538func AfterEach(body interface{}, timeout ...float64) bool {539 globalSuite.PushAfterEachNode(body, codelocation.New(1), parseTimeout(timeout...))540 return true541}542func parseTimeout(timeout ...float64) time.Duration {543 if len(timeout) == 0 {544 return time.Duration(defaultTimeout * int64(time.Second))545 } else {546 return time.Duration(timeout[0] * float64(time.Second))547 }548}...

Full Screen

Full Screen

run_test.go

Source:run_test.go Github

copy

Full Screen

...23 BeforeEach(func() {24 pathToTest = tmpPath("ginkgo")25 copyIn(fixturePath("passing_ginkgo_tests"), pathToTest, false)26 })27 It("should run the tests in the working directory", func() {28 session := startGinkgo(pathToTest, "--noColor")29 Eventually(session).Should(gexec.Exit(0))30 output := string(session.Out.Contents())31 Ω(output).Should(ContainSubstring("Running Suite: Passing_ginkgo_tests Suite"))32 Ω(output).Should(ContainSubstring(strings.Repeat(denoter, 4)))33 Ω(output).Should(ContainSubstring("SUCCESS! -- 4 Passed"))34 Ω(output).Should(ContainSubstring("Test Suite Passed"))35 })36 })37 Context("when passed an explicit package to run", func() {38 BeforeEach(func() {39 pathToTest = tmpPath("ginkgo")40 copyIn(fixturePath("passing_ginkgo_tests"), pathToTest, false)41 })42 It("should run the ginkgo style tests", func() {43 session := startGinkgo(tmpDir, "--noColor", pathToTest)44 Eventually(session).Should(gexec.Exit(0))45 output := string(session.Out.Contents())46 Ω(output).Should(ContainSubstring("Running Suite: Passing_ginkgo_tests Suite"))47 Ω(output).Should(ContainSubstring(strings.Repeat(denoter, 4)))48 Ω(output).Should(ContainSubstring("SUCCESS! -- 4 Passed"))49 Ω(output).Should(ContainSubstring("Test Suite Passed"))50 })51 })52 Context("when passed a number of packages to run", func() {53 BeforeEach(func() {54 pathToTest = tmpPath("ginkgo")55 otherPathToTest := tmpPath("other")56 copyIn(fixturePath("passing_ginkgo_tests"), pathToTest, false)57 copyIn(fixturePath("more_ginkgo_tests"), otherPathToTest, false)58 })59 It("should run the ginkgo style tests", func() {60 session := startGinkgo(tmpDir, "--noColor", "--succinct=false", "ginkgo", "./other")61 Eventually(session).Should(gexec.Exit(0))62 output := string(session.Out.Contents())63 Ω(output).Should(ContainSubstring("Running Suite: Passing_ginkgo_tests Suite"))64 Ω(output).Should(ContainSubstring("Running Suite: More_ginkgo_tests Suite"))65 Ω(output).Should(ContainSubstring("Test Suite Passed"))66 })67 })68 Context("when passed a number of packages to run, some of which have focused tests", func() {69 BeforeEach(func() {70 pathToTest = tmpPath("ginkgo")71 otherPathToTest := tmpPath("other")72 focusedPathToTest := tmpPath("focused")73 copyIn(fixturePath("passing_ginkgo_tests"), pathToTest, false)74 copyIn(fixturePath("more_ginkgo_tests"), otherPathToTest, false)75 copyIn(fixturePath("focused_fixture"), focusedPathToTest, false)76 })77 It("should exit with a status code of 2 and explain why", func() {78 session := startGinkgo(tmpDir, "--noColor", "--succinct=false", "-r")79 Eventually(session).Should(gexec.Exit(types.GINKGO_FOCUS_EXIT_CODE))80 output := string(session.Out.Contents())81 Ω(output).Should(ContainSubstring("Running Suite: Passing_ginkgo_tests Suite"))82 Ω(output).Should(ContainSubstring("Running Suite: More_ginkgo_tests Suite"))83 Ω(output).Should(ContainSubstring("Test Suite Passed"))84 Ω(output).Should(ContainSubstring("Detected Programmatic Focus - setting exit status to %d", types.GINKGO_FOCUS_EXIT_CODE))85 })86 Context("when the GINKGO_EDITOR_INTEGRATION environment variable is set", func() {87 BeforeEach(func() {88 os.Setenv("GINKGO_EDITOR_INTEGRATION", "true")89 })90 AfterEach(func() {91 os.Setenv("GINKGO_EDITOR_INTEGRATION", "")92 })93 It("should exit with a status code of 0 to allow a coverage file to be generated", func() {94 session := startGinkgo(tmpDir, "--noColor", "--succinct=false", "-r")95 Eventually(session).Should(gexec.Exit(0))96 output := string(session.Out.Contents())97 Ω(output).Should(ContainSubstring("Running Suite: Passing_ginkgo_tests Suite"))98 Ω(output).Should(ContainSubstring("Running Suite: More_ginkgo_tests Suite"))99 Ω(output).Should(ContainSubstring("Test Suite Passed"))100 })101 })102 })103 Context("when told to skipPackages", func() {104 BeforeEach(func() {105 pathToTest = tmpPath("ginkgo")106 otherPathToTest := tmpPath("other")107 focusedPathToTest := tmpPath("focused")108 copyIn(fixturePath("passing_ginkgo_tests"), pathToTest, false)109 copyIn(fixturePath("more_ginkgo_tests"), otherPathToTest, false)110 copyIn(fixturePath("focused_fixture"), focusedPathToTest, false)111 })112 It("should skip packages that match the list", func() {113 session := startGinkgo(tmpDir, "--noColor", "--skipPackage=other,focused", "-r")114 Eventually(session).Should(gexec.Exit(0))115 output := string(session.Out.Contents())116 Ω(output).Should(ContainSubstring("Passing_ginkgo_tests Suite"))117 Ω(output).ShouldNot(ContainSubstring("More_ginkgo_tests Suite"))118 Ω(output).ShouldNot(ContainSubstring("Focused_fixture Suite"))119 Ω(output).Should(ContainSubstring("Test Suite Passed"))120 })121 Context("when all packages are skipped", func() {122 It("should not run anything, but still exit 0", func() {123 session := startGinkgo(tmpDir, "--noColor", "--skipPackage=other,focused,ginkgo", "-r")124 Eventually(session).Should(gexec.Exit(0))125 output := string(session.Out.Contents())126 Ω(output).Should(ContainSubstring("All tests skipped!"))127 Ω(output).ShouldNot(ContainSubstring("Passing_ginkgo_tests Suite"))128 Ω(output).ShouldNot(ContainSubstring("More_ginkgo_tests Suite"))129 Ω(output).ShouldNot(ContainSubstring("Focused_fixture Suite"))130 Ω(output).ShouldNot(ContainSubstring("Test Suite Passed"))131 })132 })133 })134 Context("when there are no tests to run", func() {135 It("should exit 1", func() {136 session := startGinkgo(tmpDir, "--noColor", "--skipPackage=other,focused", "-r")137 Eventually(session).Should(gexec.Exit(1))138 output := string(session.Err.Contents())139 Ω(output).Should(ContainSubstring("Found no test suites"))140 })141 })142 Context("when there are test files but `go test` reports there are no tests to run", func() {143 BeforeEach(func() {144 pathToTest = tmpPath("ginkgo")145 copyIn(fixturePath("no_test_fn"), pathToTest, false)146 })147 It("suggests running ginkgo bootstrap", func() {148 session := startGinkgo(tmpDir, "--noColor", "--skipPackage=other,focused", "-r")149 Eventually(session).Should(gexec.Exit(0))150 output := string(session.Err.Contents())151 Ω(output).Should(ContainSubstring(`Found no test suites, did you forget to run "ginkgo bootstrap"?`))152 })153 It("fails if told to requireSuite", func() {154 session := startGinkgo(tmpDir, "--noColor", "--skipPackage=other,focused", "-r", "-requireSuite")155 Eventually(session).Should(gexec.Exit(1))156 output := string(session.Err.Contents())157 Ω(output).Should(ContainSubstring(`Found no test suites, did you forget to run "ginkgo bootstrap"?`))158 })159 })160 Context("when told to randomizeSuites", func() {161 BeforeEach(func() {162 pathToTest = tmpPath("ginkgo")163 otherPathToTest := tmpPath("other")164 copyIn(fixturePath("passing_ginkgo_tests"), pathToTest, false)165 copyIn(fixturePath("more_ginkgo_tests"), otherPathToTest, false)166 })167 It("should skip packages that match the regexp", func() {168 session := startGinkgo(tmpDir, "--noColor", "--randomizeSuites", "-r", "--seed=2")169 Eventually(session).Should(gexec.Exit(0))170 Ω(session).Should(gbytes.Say("More_ginkgo_tests Suite"))171 Ω(session).Should(gbytes.Say("Passing_ginkgo_tests Suite"))172 session = startGinkgo(tmpDir, "--noColor", "--randomizeSuites", "-r", "--seed=3")173 Eventually(session).Should(gexec.Exit(0))174 Ω(session).Should(gbytes.Say("Passing_ginkgo_tests Suite"))175 Ω(session).Should(gbytes.Say("More_ginkgo_tests Suite"))176 })177 })178 Context("when pointed at a package with xunit style tests", func() {179 BeforeEach(func() {180 pathToTest = tmpPath("xunit")181 copyIn(fixturePath("xunit_tests"), pathToTest, false)182 })183 It("should run the xunit style tests", func() {184 session := startGinkgo(pathToTest)185 Eventually(session).Should(gexec.Exit(0))186 output := string(session.Out.Contents())187 Ω(output).Should(ContainSubstring("--- PASS: TestAlwaysTrue"))188 Ω(output).Should(ContainSubstring("Test Suite Passed"))189 })190 })191 Context("when pointed at a package with no tests", func() {192 BeforeEach(func() {193 pathToTest = tmpPath("no_tests")194 copyIn(fixturePath("no_tests"), pathToTest, false)195 })196 It("should fail", func() {197 session := startGinkgo(pathToTest, "--noColor")198 Eventually(session).Should(gexec.Exit(1))199 Ω(session.Err.Contents()).Should(ContainSubstring("Found no test suites"))200 })201 })202 Context("when pointed at a package that fails to compile", func() {203 BeforeEach(func() {204 pathToTest = tmpPath("does_not_compile")205 copyIn(fixturePath("does_not_compile"), pathToTest, false)206 })207 It("should fail", func() {208 session := startGinkgo(pathToTest, "--noColor")209 Eventually(session).Should(gexec.Exit(1))210 output := string(session.Out.Contents())211 Ω(output).Should(ContainSubstring("Failed to compile"))212 })213 })214 Context("when running in parallel", func() {215 BeforeEach(func() {216 pathToTest = tmpPath("ginkgo")217 copyIn(fixturePath("passing_ginkgo_tests"), pathToTest, false)218 })219 Context("with a specific number of -nodes", func() {220 It("should use the specified number of nodes", func() {221 session := startGinkgo(pathToTest, "--noColor", "-succinct", "-nodes=2")222 Eventually(session).Should(gexec.Exit(0))223 output := string(session.Out.Contents())224 Ω(output).Should(MatchRegexp(`\[\d+\] Passing_ginkgo_tests Suite - 4 specs - 2 nodes [%s]{4} SUCCESS! \d+(\.\d+)?[muµ]s`, regexp.QuoteMeta(denoter)))225 Ω(output).Should(ContainSubstring("Test Suite Passed"))226 })227 })228 Context("with -p", func() {229 It("it should autocompute the number of nodes", func() {230 session := startGinkgo(pathToTest, "--noColor", "-succinct", "-p")231 Eventually(session).Should(gexec.Exit(0))232 output := string(session.Out.Contents())233 nodes := runtime.NumCPU()234 if nodes == 1 {235 Skip("Can't test parallel testings with 1 CPU")236 }237 if nodes > 4 {238 nodes = nodes - 1239 }240 Ω(output).Should(MatchRegexp(`\[\d+\] Passing_ginkgo_tests Suite - 4 specs - %d nodes [%s]{4} SUCCESS! \d+(\.\d+)?[muµ]?s`, nodes, regexp.QuoteMeta(denoter)))241 Ω(output).Should(ContainSubstring("Test Suite Passed"))242 })243 })244 })245 Context("when running in parallel with -debug", func() {246 BeforeEach(func() {247 pathToTest = tmpPath("ginkgo")248 copyIn(fixturePath("debug_parallel_fixture"), pathToTest, false)249 })250 Context("without -v", func() {251 It("should emit node output to files on disk", func() {252 session := startGinkgo(pathToTest, "--nodes=2", "--debug")253 Eventually(session).Should(gexec.Exit(0))254 f0, err := ioutil.ReadFile(pathToTest + "/ginkgo-node-1.log")255 Ω(err).ShouldNot(HaveOccurred())256 f1, err := ioutil.ReadFile(pathToTest + "/ginkgo-node-2.log")257 Ω(err).ShouldNot(HaveOccurred())258 content := string(append(f0, f1...))259 for i := 0; i < 10; i += 1 {260 Ω(content).Should(ContainSubstring("StdOut %d\n", i))261 Ω(content).Should(ContainSubstring("GinkgoWriter %d\n", i))262 }263 })264 })265 Context("without -v", func() {266 It("should emit node output to files on disk, without duplicating the GinkgoWriter output", func() {267 session := startGinkgo(pathToTest, "--nodes=2", "--debug", "-v")268 Eventually(session).Should(gexec.Exit(0))269 f0, err := ioutil.ReadFile(pathToTest + "/ginkgo-node-1.log")270 Ω(err).ShouldNot(HaveOccurred())271 f1, err := ioutil.ReadFile(pathToTest + "/ginkgo-node-2.log")272 Ω(err).ShouldNot(HaveOccurred())273 content := string(append(f0, f1...))274 out := strings.Split(content, "GinkgoWriter 2")275 Ω(out).Should(HaveLen(2))276 })277 })278 })279 Context("when streaming in parallel", func() {280 BeforeEach(func() {281 pathToTest = tmpPath("ginkgo")282 copyIn(fixturePath("passing_ginkgo_tests"), pathToTest, false)283 })284 It("should print output in realtime", func() {285 session := startGinkgo(pathToTest, "--noColor", "-stream", "-nodes=2")286 Eventually(session).Should(gexec.Exit(0))287 output := string(session.Out.Contents())288 Ω(output).Should(ContainSubstring(`[1] Parallel test node 1/2.`))289 Ω(output).Should(ContainSubstring(`[2] Parallel test node 2/2.`))290 Ω(output).Should(ContainSubstring(`[1] SUCCESS!`))291 Ω(output).Should(ContainSubstring(`[2] SUCCESS!`))292 Ω(output).Should(ContainSubstring("Test Suite Passed"))293 })294 })295 Context("when running recursively", func() {296 BeforeEach(func() {297 passingTest := tmpPath("A")298 otherPassingTest := tmpPath("E")299 copyIn(fixturePath("passing_ginkgo_tests"), passingTest, false)300 copyIn(fixturePath("more_ginkgo_tests"), otherPassingTest, false)301 })302 Context("when all the tests pass", func() {303 Context("with the -r flag", func() {304 It("should run all the tests (in succinct mode) and succeed", func() {305 session := startGinkgo(tmpDir, "--noColor", "-r", ".")306 Eventually(session).Should(gexec.Exit(0))307 output := string(session.Out.Contents())308 outputLines := strings.Split(output, "\n")309 Ω(outputLines[0]).Should(MatchRegexp(`\[\d+\] Passing_ginkgo_tests Suite - 4/4 specs [%s]{4} SUCCESS! \d+(\.\d+)?[muµ]s PASS`, regexp.QuoteMeta(denoter)))310 Ω(outputLines[1]).Should(MatchRegexp(`\[\d+\] More_ginkgo_tests Suite - 2/2 specs [%s]{2} SUCCESS! \d+(\.\d+)?[muµ]s PASS`, regexp.QuoteMeta(denoter)))311 Ω(output).Should(ContainSubstring("Test Suite Passed"))312 })313 })314 Context("with a trailing /...", func() {315 It("should run all the tests (in succinct mode) and succeed", func() {316 session := startGinkgo(tmpDir, "--noColor", "./...")317 Eventually(session).Should(gexec.Exit(0))318 output := string(session.Out.Contents())319 outputLines := strings.Split(output, "\n")320 Ω(outputLines[0]).Should(MatchRegexp(`\[\d+\] Passing_ginkgo_tests Suite - 4/4 specs [%s]{4} SUCCESS! \d+(\.\d+)?[muµ]s PASS`, regexp.QuoteMeta(denoter)))321 Ω(outputLines[1]).Should(MatchRegexp(`\[\d+\] More_ginkgo_tests Suite - 2/2 specs [%s]{2} SUCCESS! \d+(\.\d+)?[muµ]s PASS`, regexp.QuoteMeta(denoter)))322 Ω(output).Should(ContainSubstring("Test Suite Passed"))323 })324 })325 })326 Context("when one of the packages has a failing tests", func() {327 BeforeEach(func() {328 failingTest := tmpPath("C")329 copyIn(fixturePath("failing_ginkgo_tests"), failingTest, false)330 })331 It("should fail and stop running tests", func() {332 session := startGinkgo(tmpDir, "--noColor", "-r")333 Eventually(session).Should(gexec.Exit(1))334 output := string(session.Out.Contents())335 outputLines := strings.Split(output, "\n")336 Ω(outputLines[0]).Should(MatchRegexp(`\[\d+\] Passing_ginkgo_tests Suite - 4/4 specs [%s]{4} SUCCESS! \d+(\.\d+)?[muµ]s PASS`, regexp.QuoteMeta(denoter)))337 Ω(outputLines[1]).Should(MatchRegexp(`\[\d+\] Failing_ginkgo_tests Suite - 2/2 specs`))338 Ω(output).Should(ContainSubstring(fmt.Sprintf("%s Failure", denoter)))339 Ω(output).ShouldNot(ContainSubstring("More_ginkgo_tests Suite"))340 Ω(output).Should(ContainSubstring("Test Suite Failed"))341 Ω(output).Should(ContainSubstring("Summarizing 1 Failure:"))342 Ω(output).Should(ContainSubstring("[Fail] FailingGinkgoTests [It] should fail"))343 })344 })345 Context("when one of the packages fails to compile", func() {346 BeforeEach(func() {347 doesNotCompileTest := tmpPath("C")348 copyIn(fixturePath("does_not_compile"), doesNotCompileTest, false)349 })350 It("should fail and stop running tests", func() {351 session := startGinkgo(tmpDir, "--noColor", "-r")352 Eventually(session).Should(gexec.Exit(1))353 output := string(session.Out.Contents())354 outputLines := strings.Split(output, "\n")355 Ω(outputLines[0]).Should(MatchRegexp(`\[\d+\] Passing_ginkgo_tests Suite - 4/4 specs [%s]{4} SUCCESS! \d+(\.\d+)?[muµ]s PASS`, regexp.QuoteMeta(denoter)))356 Ω(outputLines[1]).Should(ContainSubstring("Failed to compile C:"))357 Ω(output).ShouldNot(ContainSubstring("More_ginkgo_tests Suite"))358 Ω(output).Should(ContainSubstring("Test Suite Failed"))359 })360 })361 Context("when either is the case, but the keepGoing flag is set", func() {362 BeforeEach(func() {363 doesNotCompileTest := tmpPath("B")364 copyIn(fixturePath("does_not_compile"), doesNotCompileTest, false)365 failingTest := tmpPath("C")366 copyIn(fixturePath("failing_ginkgo_tests"), failingTest, false)367 })368 It("should soldier on", func() {369 session := startGinkgo(tmpDir, "--noColor", "-r", "-keepGoing")370 Eventually(session).Should(gexec.Exit(1))371 output := string(session.Out.Contents())372 outputLines := strings.Split(output, "\n")373 Ω(outputLines[0]).Should(MatchRegexp(`\[\d+\] Passing_ginkgo_tests Suite - 4/4 specs [%s]{4} SUCCESS! \d+(\.\d+)?[muµ]s PASS`, regexp.QuoteMeta(denoter)))374 Ω(outputLines[1]).Should(ContainSubstring("Failed to compile B:"))375 Ω(output).Should(MatchRegexp(`\[\d+\] Failing_ginkgo_tests Suite - 2/2 specs`))376 Ω(output).Should(ContainSubstring(fmt.Sprintf("%s Failure", denoter)))377 Ω(output).Should(MatchRegexp(`\[\d+\] More_ginkgo_tests Suite - 2/2 specs [%s]{2} SUCCESS! \d+(\.\d+)?[muµ]s PASS`, regexp.QuoteMeta(denoter)))378 Ω(output).Should(ContainSubstring("Test Suite Failed"))379 })380 })381 })382 Context("when told to keep going --untilItFails", func() {383 BeforeEach(func() {384 copyIn(fixturePath("eventually_failing"), tmpDir, false)385 })386 It("should keep rerunning the tests, until a failure occurs", func() {387 session := startGinkgo(tmpDir, "--untilItFails", "--noColor")388 Eventually(session).Should(gexec.Exit(1))389 Ω(session).Should(gbytes.Say("This was attempt #1"))390 Ω(session).Should(gbytes.Say("This was attempt #2"))391 Ω(session).Should(gbytes.Say("Tests failed on attempt #3"))392 //it should change the random seed between each test393 lines := strings.Split(string(session.Out.Contents()), "\n")394 randomSeeds := []string{}395 for _, line := range lines {396 if strings.Contains(line, "Random Seed:") {397 randomSeeds = append(randomSeeds, strings.Split(line, ": ")[1])398 }399 }400 Ω(randomSeeds[0]).ShouldNot(Equal(randomSeeds[1]))401 Ω(randomSeeds[1]).ShouldNot(Equal(randomSeeds[2]))...

Full Screen

Full Screen

session_test.go

Source:session_test.go Github

copy

Full Screen

...22 session, err = Start(command, outWriter, errWriter)23 Ω(err).ShouldNot(HaveOccurred())24 })25 Context("running a command", func() {26 It("should start the process", func() {27 Ω(command.Process).ShouldNot(BeNil())28 })29 It("should wrap the process's stdout and stderr with gbytes buffers", func(done Done) {30 Eventually(session.Out).Should(Say("We've done the impossible, and that makes us mighty"))31 Eventually(session.Err).Should(Say("Ah, curse your sudden but inevitable betrayal!"))32 defer session.Out.CancelDetects()33 select {34 case <-session.Out.Detect("Can we maybe vote on the whole murdering people issue"):35 Eventually(session).Should(Exit(0))36 case <-session.Out.Detect("I swear by my pretty floral bonnet, I will end you."):37 Eventually(session).Should(Exit(1))38 case <-session.Out.Detect("My work's illegal, but at least it's honest."):39 Eventually(session).Should(Exit(2))40 }41 close(done)42 })43 It("should satisfy the gbytes.BufferProvider interface, passing Stdout", func() {44 Eventually(session).Should(Say("We've done the impossible, and that makes us mighty"))45 Eventually(session).Should(Exit())46 })47 })48 Describe("providing the exit code", func() {49 It("should provide the app's exit code", func() {50 Ω(session.ExitCode()).Should(Equal(-1))51 Eventually(session).Should(Exit())52 Ω(session.ExitCode()).Should(BeNumerically(">=", 0))53 Ω(session.ExitCode()).Should(BeNumerically("<", 3))54 })55 })56 Describe("wait", func() {57 It("should wait till the command exits", func() {58 Ω(session.ExitCode()).Should(Equal(-1))59 Ω(session.Wait().ExitCode()).Should(BeNumerically(">=", 0))60 Ω(session.Wait().ExitCode()).Should(BeNumerically("<", 3))61 })62 })63 Describe("exited", func() {64 It("should close when the command exits", func() {65 Eventually(session.Exited).Should(BeClosed())66 Ω(session.ExitCode()).ShouldNot(Equal(-1))67 })68 })69 Describe("kill", func() {70 It("should kill the command and don't wait for it to exit", func() {71 session, err := Start(exec.Command("sleep", "10000000"), GinkgoWriter, GinkgoWriter)72 Ω(err).ShouldNot(HaveOccurred())73 session.Kill()74 Ω(session).ShouldNot(Exit(), "Should not exit immediately...")75 Eventually(session).Should(Exit(128 + 9))76 })77 })78 Describe("interrupt", func() {79 It("should interrupt the command", func() {80 session, err := Start(exec.Command("sleep", "10000000"), GinkgoWriter, GinkgoWriter)81 Ω(err).ShouldNot(HaveOccurred())82 session.Interrupt()83 Ω(session).ShouldNot(Exit(), "Should not exit immediately...")84 Eventually(session).Should(Exit(128 + 2))85 })86 })87 Describe("terminate", func() {88 It("should terminate the command", func() {89 session, err := Start(exec.Command("sleep", "10000000"), GinkgoWriter, GinkgoWriter)90 Ω(err).ShouldNot(HaveOccurred())91 session.Terminate()92 Ω(session).ShouldNot(Exit(), "Should not exit immediately...")93 Eventually(session).Should(Exit(128 + 15))94 })95 })96 Describe("signal", func() {97 It("should send the signal to the command", func() {98 session, err := Start(exec.Command("sleep", "10000000"), GinkgoWriter, GinkgoWriter)99 Ω(err).ShouldNot(HaveOccurred())100 session.Signal(syscall.SIGABRT)101 Ω(session).ShouldNot(Exit(), "Should not exit immediately...")102 Eventually(session).Should(Exit(128 + 6))103 })104 })105 Context("tracking sessions", func() {106 BeforeEach(func() {107 KillAndWait()108 })109 Describe("kill", func() {110 It("should kill all the started sessions", func() {111 session1, err := Start(exec.Command("sleep", "10000000"), GinkgoWriter, GinkgoWriter)112 Ω(err).ShouldNot(HaveOccurred())113 session2, err := Start(exec.Command("sleep", "10000000"), GinkgoWriter, GinkgoWriter)114 Ω(err).ShouldNot(HaveOccurred())115 session3, err := Start(exec.Command("sleep", "10000000"), GinkgoWriter, GinkgoWriter)116 Ω(err).ShouldNot(HaveOccurred())117 Kill()118 Eventually(session1).Should(Exit(128 + 9))119 Eventually(session2).Should(Exit(128 + 9))120 Eventually(session3).Should(Exit(128 + 9))121 })122 It("should not wait for exit", func() {123 session1, err := Start(exec.Command("sleep", "10000000"), GinkgoWriter, GinkgoWriter)124 Ω(err).ShouldNot(HaveOccurred())125 Kill()126 Ω(session1).ShouldNot(Exit(), "Should not exit immediately...")127 Eventually(session1).Should(Exit(128 + 9))128 })129 It("should not track unstarted sessions", func() {130 _, err := Start(exec.Command("does not exist", "10000000"), GinkgoWriter, GinkgoWriter)131 Ω(err).Should(HaveOccurred())132 session2, err := Start(exec.Command("sleep", "10000000"), GinkgoWriter, GinkgoWriter)133 Ω(err).ShouldNot(HaveOccurred())134 session3, err := Start(exec.Command("sleep", "10000000"), GinkgoWriter, GinkgoWriter)135 Ω(err).ShouldNot(HaveOccurred())136 Kill()137 Eventually(session2).Should(Exit(128 + 9))138 Eventually(session3).Should(Exit(128 + 9))139 })140 })141 Describe("killAndWait", func() {142 It("should kill all the started sessions and wait for them to finish", func() {143 session1, err := Start(exec.Command("sleep", "10000000"), GinkgoWriter, GinkgoWriter)144 Ω(err).ShouldNot(HaveOccurred())145 session2, err := Start(exec.Command("sleep", "10000000"), GinkgoWriter, GinkgoWriter)146 Ω(err).ShouldNot(HaveOccurred())147 session3, err := Start(exec.Command("sleep", "10000000"), GinkgoWriter, GinkgoWriter)148 Ω(err).ShouldNot(HaveOccurred())149 KillAndWait()150 Ω(session1).Should(Exit(128+9), "Should have exited")151 Ω(session2).Should(Exit(128+9), "Should have exited")152 Ω(session3).Should(Exit(128+9), "Should have exited")153 })154 })155 Describe("terminate", func() {156 It("should terminate all the started sessions", func() {157 session1, err := Start(exec.Command("sleep", "10000000"), GinkgoWriter, GinkgoWriter)158 Ω(err).ShouldNot(HaveOccurred())159 session2, err := Start(exec.Command("sleep", "10000000"), GinkgoWriter, GinkgoWriter)160 Ω(err).ShouldNot(HaveOccurred())161 session3, err := Start(exec.Command("sleep", "10000000"), GinkgoWriter, GinkgoWriter)162 Ω(err).ShouldNot(HaveOccurred())163 Terminate()164 Eventually(session1).Should(Exit(128 + 15))165 Eventually(session2).Should(Exit(128 + 15))166 Eventually(session3).Should(Exit(128 + 15))167 })168 It("should not wait for exit", func() {169 session1, err := Start(exec.Command("sleep", "10000000"), GinkgoWriter, GinkgoWriter)170 Ω(err).ShouldNot(HaveOccurred())171 Terminate()172 Ω(session1).ShouldNot(Exit(), "Should not exit immediately...")173 })174 })175 Describe("terminateAndWait", func() {176 It("should terminate all the started sessions, and wait for them to exit", func() {177 session1, err := Start(exec.Command("sleep", "10000000"), GinkgoWriter, GinkgoWriter)178 Ω(err).ShouldNot(HaveOccurred())179 session2, err := Start(exec.Command("sleep", "10000000"), GinkgoWriter, GinkgoWriter)180 Ω(err).ShouldNot(HaveOccurred())181 session3, err := Start(exec.Command("sleep", "10000000"), GinkgoWriter, GinkgoWriter)182 Ω(err).ShouldNot(HaveOccurred())183 TerminateAndWait()184 Ω(session1).Should(Exit(128+15), "Should have exited")185 Ω(session2).Should(Exit(128+15), "Should have exited")186 Ω(session3).Should(Exit(128+15), "Should have exited")187 })188 })189 Describe("signal", func() {190 It("should signal all the started sessions", func() {191 session1, err := Start(exec.Command("sleep", "10000000"), GinkgoWriter, GinkgoWriter)192 Ω(err).ShouldNot(HaveOccurred())193 session2, err := Start(exec.Command("sleep", "10000000"), GinkgoWriter, GinkgoWriter)194 Ω(err).ShouldNot(HaveOccurred())195 session3, err := Start(exec.Command("sleep", "10000000"), GinkgoWriter, GinkgoWriter)196 Ω(err).ShouldNot(HaveOccurred())197 Signal(syscall.SIGABRT)198 Eventually(session1).Should(Exit(128 + 6))199 Eventually(session2).Should(Exit(128 + 6))200 Eventually(session3).Should(Exit(128 + 6))201 })202 It("should not wait", func() {203 session1, err := Start(exec.Command("sleep", "10000000"), GinkgoWriter, GinkgoWriter)204 Ω(err).ShouldNot(HaveOccurred())205 Signal(syscall.SIGABRT)206 Ω(session1).ShouldNot(Exit(), "Should not exit immediately...")207 })208 })209 Describe("interrupt", func() {210 It("should interrupt all the started sessions, and not wait", func() {211 session1, err := Start(exec.Command("sleep", "10000000"), GinkgoWriter, GinkgoWriter)212 Ω(err).ShouldNot(HaveOccurred())213 session2, err := Start(exec.Command("sleep", "10000000"), GinkgoWriter, GinkgoWriter)214 Ω(err).ShouldNot(HaveOccurred())215 session3, err := Start(exec.Command("sleep", "10000000"), GinkgoWriter, GinkgoWriter)216 Ω(err).ShouldNot(HaveOccurred())217 Interrupt()218 Eventually(session1).Should(Exit(128 + 2))219 Eventually(session2).Should(Exit(128 + 2))220 Eventually(session3).Should(Exit(128 + 2))221 })222 It("should not wait", func() {223 session1, err := Start(exec.Command("sleep", "10000000"), GinkgoWriter, GinkgoWriter)224 Ω(err).ShouldNot(HaveOccurred())225 Interrupt()226 Ω(session1).ShouldNot(Exit(), "Should not exit immediately...")227 })228 })229 })230 Context("when the command exits", func() {231 It("should close the buffers", func() {232 Eventually(session).Should(Exit())233 Ω(session.Out.Closed()).Should(BeTrue())234 Ω(session.Err.Closed()).Should(BeTrue())235 Ω(session.Out).Should(Say("We've done the impossible, and that makes us mighty"))236 })237 var So = It238 So("this means that eventually should short circuit", func() {239 t := time.Now()240 failures := InterceptGomegaFailures(func() {241 Eventually(session).Should(Say("blah blah blah blah blah"))242 })243 Ω(time.Since(t)).Should(BeNumerically("<=", 500*time.Millisecond))244 Ω(failures).Should(HaveLen(1))245 })246 })247 Context("when wrapping out and err", func() {248 BeforeEach(func() {249 outWriter = NewBuffer()250 errWriter = NewBuffer()251 })252 It("should route to both the provided writers and the gbytes buffers", func() {253 Eventually(session.Out).Should(Say("We've done the impossible, and that makes us mighty"))254 Eventually(session.Err).Should(Say("Ah, curse your sudden but inevitable betrayal!"))255 Ω(outWriter.Contents()).Should(ContainSubstring("We've done the impossible, and that makes us mighty"))256 Ω(errWriter.Contents()).Should(ContainSubstring("Ah, curse your sudden but inevitable betrayal!"))257 Eventually(session).Should(Exit())258 Ω(outWriter.Contents()).Should(Equal(session.Out.Contents()))259 Ω(errWriter.Contents()).Should(Equal(session.Err.Contents()))260 })261 })262 Describe("when the command fails to start", func() {263 It("should return an error", func() {264 _, err := Start(exec.Command("agklsjdfas"), nil, nil)265 Ω(err).Should(HaveOccurred())266 })267 })268})...

Full Screen

Full Screen

It

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 gomega.NewGomegaWithT(ginkgo.GinkgoT()).Expect(1).To(gomega.Equal(1))4 fmt.Println("Hello World!")5}6import (7func main() {8 gomega.NewGomegaWithT(ginkgo.GinkgoT()).Expect(1).To(gomega.Equal(1))9 fmt.Println("Hello World!")10}11import (12func main() {13 gomega.NewGomegaWithT(ginkgo.GinkgoT()).Expect(1).To(gomega.Equal(1))14 fmt.Println("Hello World!")15}16import (17func main() {18 gomega.NewGomegaWithT(ginkgo.GinkgoT()).Expect(1).To(gomega.Equal(1))19 fmt.Println("Hello World!")20}21import (22func main() {23 gomega.NewGomegaWithT(ginkgo.GinkgoT()).Expect(1).To(gomega.Equal(1))24 fmt.Println("Hello World!")25}26import (27func main() {28 gomega.NewGomegaWithT(ginkgo.GinkgoT()).Expect(1).To(gomega.Equal(1))29 fmt.Println("Hello World!")30}

Full Screen

Full Screen

It

Using AI Code Generation

copy

Full Screen

1import (2func TestGinkgo(t *testing.T) {3 gomega.RegisterFailHandler(ginkgo.Fail)4 ginkgo.RunSpecs(t, "Ginkgo Suite")5}6var _ = ginkgo.Describe("Ginkgo", func() {7 ginkgo.It("should be able to use ginkgo", func() {8 fmt.Println("Hello World")9 })10})11import (12func TestGomega(t *testing.T) {13 gomega.RegisterFailHandler(ginkgo.Fail)14 ginkgo.RunSpecs(t, "Gomega Suite")15}16var _ = ginkgo.Describe("Gomega", func() {17 gomega.It("should be able to use gomega", func() {18 fmt.Println("Hello World")19 })20})21import (22func TestGomega(t *testing.T) {23 gomega.RegisterFailHandler(ginkgo.Fail)24 ginkgo.RunSpecs(t, "Gomega Suite")25}26var _ = ginkgo.Describe("Gomega", func() {27 gomega.It("should be able to use gomega", func() {28 fmt.Println("Hello World")29 })30})31import (32func TestGomega(t *testing.T) {33 gomega.RegisterFailHandler(ginkgo.Fail)34 ginkgo.RunSpecs(t, "Gomega Suite")35}36var _ = ginkgo.Describe("Gomega", func() {37 gomega.It("should be able to use gomega", func() {

Full Screen

Full Screen

It

Using AI Code Generation

copy

Full Screen

1import (2func Test(t *testing.T) {3 gomega.RegisterFailHandler(ginkgo.Fail)4 ginkgo.RunSpecs(t, "My Suite")5}6var _ = ginkgo.Describe("My Suite", func() {7 ginkgo.It("should work", func() {8 fmt.Println("Hello World")9 })10})11import (12func Test(t *testing.T) {13 gomega.RegisterFailHandler(ginkgo.Fail)14 ginkgo.RunSpecs(t, "My Suite")15}16var _ = ginkgo.Describe("My Suite", func() {17 ginkgo.It("should work", func() {18 fmt.Println("Hello World")19 })20})21import (22func Test(t *testing.T) {23 gomega.RegisterFailHandler(ginkgo.Fail)24 ginkgo.RunSpecs(t, "My Suite")25}26var _ = ginkgo.Describe("My Suite", func() {27 ginkgo.It("should work", func() {28 fmt.Println("Hello World")29 })30})31import (32func Test(t *testing.T) {33 gomega.RegisterFailHandler(ginkgo.Fail)34 ginkgo.RunSpecs(t, "My Suite")35}36var _ = ginkgo.Describe("My Suite", func() {37 ginkgo.It("should work", func() {38 fmt.Println("Hello World")39 })40})

Full Screen

Full Screen

It

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello World")4 gomega.NewGomegaWithT(ginkgo.GinkgoT()).Expect(1).To(gomega.Equal(1))5}6import (7func main() {8 fmt.Println("Hello World")9 gomega.NewGomegaWithT(ginkgo.GinkgoT()).Expect(1).To(gomega.Equal(1))10}

Full Screen

Full Screen

It

Using AI Code Generation

copy

Full Screen

1import (2func Test1(t *testing.T) {3 gomega.RegisterFailHandler(ginkgo.Fail)4 ginkgo.RunSpecs(t, "Test1")5}6var _ = ginkgo.Describe("Test1", func() {7 ginkgo.It("Test1", func() {8 fmt.Println("Test1")9 })10})11var _ = ginkgo.Describe("Test2", func() {12 ginkgo.It("Test2", func() {13 fmt.Println("Test2")14 })15})16var _ = ginkgo.Describe("Test3", func() {17 ginkgo.It("Test3", func() {18 fmt.Println("Test3")19 })20})21import (22func Test2(t *testing.T) {23 gomega.RegisterFailHandler(ginkgo.Fail)24 ginkgo.RunSpecs(t, "Test2")25}26var _ = ginkgo.Describe("Test4", func() {27 ginkgo.It("Test4", func() {28 fmt.Println("Test4")29 })30})31var _ = ginkgo.Describe("Test5", func() {32 ginkgo.It("Test5", func() {33 fmt.Println("Test5")34 })35})36var _ = ginkgo.Describe("Test6", func() {37 ginkgo.It("Test6", func() {38 fmt.Println("Test6")39 })40})41import (42func Test3(t *testing.T) {43 gomega.RegisterFailHandler(ginkgo.Fail)44 ginkgo.RunSpecs(t, "Test3")45}46var _ = ginkgo.Describe("Test7", func() {47 ginkgo.It("Test7

Full Screen

Full Screen

It

Using AI Code Generation

copy

Full Screen

1ginkgo.It("should pass", func() {2 gomega.Expect(true).To(gomega.BeTrue())3})4ginkgo.It("should pass", func() {5 gomega.Expect(true).To(gomega.BeTrue())6})7ginkgo.It("should pass", func() {8 gomega.Expect(true).To(gomega.BeTrue())9})10ginkgo.It("should pass", func() {11 gomega.Expect(true).To(gomega.BeTrue())12})13ginkgo.It("should pass", func() {14 gomega.Expect(true).To(gomega.BeTrue())15})16ginkgo.It("should pass", func() {17 gomega.Expect(true).To(gomega.BeTrue())18})19ginkgo.It("should pass", func() {20 gomega.Expect(true).To(gomega.BeTrue())21})22ginkgo.It("should pass", func() {23 gomega.Expect(true).To(gomega.BeTrue())24})25ginkgo.It("should pass", func() {26 gomega.Expect(true).To(gomega.BeTrue())27})28ginkgo.It("should pass", func() {29 gomega.Expect(true).To(gomega.BeTrue())30})31ginkgo.It("should pass", func() {32 gomega.Expect(true).To(gomega.BeTrue())33})34ginkgo.It("should pass", func() {35 gomega.Expect(true).To(gomega.BeTrue())36})

Full Screen

Full Screen

It

Using AI Code Generation

copy

Full Screen

1var _ = Describe("1", func() {2 Context("1", func() {3 It("1", func() {4 Expect(1).To(Equal(1))5 })6 })7})8var _ = Describe("2", func() {9 Context("2", func() {10 It("2", func() {11 Expect(2).To(Equal(2))12 })13 })14})15var _ = Describe("3", func() {16 Context("3", func() {17 It("3", func() {18 Expect(3).To(Equal(3))19 })20 })21})22var _ = Describe("4", func() {23 Context("4", func() {24 It("4", func() {25 Expect(4).To(Equal(4))26 })27 })28})29var _ = Describe("5", func() {30 Context("5", func() {31 It("5", func() {32 Expect(5).To(Equal(5))33 })34 })35})36var _ = Describe("6", func() {37 Context("6", func() {38 It("6", func() {39 Expect(6).To(Equal(6))40 })41 })42})43var _ = Describe("7", func() {44 Context("7", func() {45 It("7", func() {46 Expect(7).To(Equal(7))47 })48 })49})50var _ = Describe("8", func() {51 Context("8", func() {52 It("8", func() {53 Expect(8).To(Equal(8))54 })55 })56})57var _ = Describe("9", func() {58 Context("9", func() {

Full Screen

Full Screen

It

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello, playground")4 ginkgo.It("should be true", func() {5 gomega.Expect(true).To(gomega.BeTrue())6 })7}8import (9func main() {10 fmt.Println("Hello, playground")11 ginkgo.It("should be true", func() {12 gomega.Expect(true).To(gomega.BeTrue())13 })14}15import (16func main() {17 fmt.Println("Hello, playground")18 ginkgo.It("should be true", func() {19 gomega.Expect(true).To(gomega.BeTrue())20 })21}22import (23func main() {24 fmt.Println("Hello, playground")25 ginkgo.It("should be true", func() {26 gomega.Expect(true).To(gomega.BeTrue())27 })28}29import (30func main() {31 fmt.Println("Hello, playground")32 ginkgo.It("should be true", func() {33 gomega.Expect(true).To(gomega.BeTrue())34 })35}36import (37func main() {38 fmt.Println("Hello, playground")39 ginkgo.It("should be true", func() {40 gomega.Expect(true).To(gomega.BeTrue())41 })42}

Full Screen

Full Screen

It

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 g := ginkgo.NewGinkgo()4 g.It("should be able to add two numbers", func() {5 g.Expect(1 + 1).ToEqual(2)6 })7}8import (9type Ginkgo struct {10}11func NewGinkgo() *Ginkgo {12 return &Ginkgo{}13}14func (g *Ginkgo) It(description string, test func()) {15 fmt.Println("It", description)16 test()17}18func (g *Ginkgo) Expect(actual interface{}) *Expectation {19 return &Expectation{actual}20}21import (22type Expectation struct {23 actual interface{}24}25func (e *Expectation) ToEqual(expected interface{}) {26 if reflect.DeepEqual(e.actual, expected) {27 fmt.Println("Passed")28 } else {29 fmt.Println("Failed")30 }31}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful