1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
|
package integration_test
import (
"strings"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gexec"
)
var _ = Describe("SuiteSetup", func() {
var pathToTest string
Context("when the BeforeSuite and AfterSuite pass", func() {
BeforeEach(func() {
pathToTest = tmpPath("suite_setup")
copyIn("passing_suite_setup", pathToTest)
})
It("should run the BeforeSuite once, then run all the tests", func() {
session := startGinkgo(pathToTest, "--noColor")
Eventually(session).Should(gexec.Exit(0))
output := string(session.Out.Contents())
Ω(strings.Count(output, "BEFORE SUITE")).Should(Equal(1))
Ω(strings.Count(output, "AFTER SUITE")).Should(Equal(1))
})
It("should run the BeforeSuite once per parallel node, then run all the tests", func() {
session := startGinkgo(pathToTest, "--noColor", "--nodes=2")
Eventually(session).Should(gexec.Exit(0))
output := string(session.Out.Contents())
Ω(strings.Count(output, "BEFORE SUITE")).Should(Equal(2))
Ω(strings.Count(output, "AFTER SUITE")).Should(Equal(2))
})
})
Context("when the BeforeSuite fails", func() {
BeforeEach(func() {
pathToTest = tmpPath("suite_setup")
copyIn("failing_before_suite", pathToTest)
})
It("should run the BeforeSuite once, none of the tests, but it should run the AfterSuite", func() {
session := startGinkgo(pathToTest, "--noColor")
Eventually(session).Should(gexec.Exit(1))
output := string(session.Out.Contents())
Ω(strings.Count(output, "BEFORE SUITE")).Should(Equal(1))
Ω(strings.Count(output, "Test Panicked")).Should(Equal(1))
Ω(strings.Count(output, "AFTER SUITE")).Should(Equal(1))
Ω(output).ShouldNot(ContainSubstring("NEVER SEE THIS"))
})
It("should run the BeforeSuite once per parallel node, none of the tests, but it should run the AfterSuite for each node", func() {
session := startGinkgo(pathToTest, "--noColor", "--nodes=2")
Eventually(session).Should(gexec.Exit(1))
output := string(session.Out.Contents())
Ω(strings.Count(output, "BEFORE SUITE")).Should(Equal(2))
Ω(strings.Count(output, "Test Panicked")).Should(Equal(2))
Ω(strings.Count(output, "AFTER SUITE")).Should(Equal(2))
Ω(output).ShouldNot(ContainSubstring("NEVER SEE THIS"))
})
})
Context("when the AfterSuite fails", func() {
BeforeEach(func() {
pathToTest = tmpPath("suite_setup")
copyIn("failing_after_suite", pathToTest)
})
It("should run the BeforeSuite once, none of the tests, but it should run the AfterSuite", func() {
session := startGinkgo(pathToTest, "--noColor")
Eventually(session).Should(gexec.Exit(1))
output := string(session.Out.Contents())
Ω(strings.Count(output, "BEFORE SUITE")).Should(Equal(1))
Ω(strings.Count(output, "AFTER SUITE")).Should(Equal(1))
Ω(strings.Count(output, "Test Panicked")).Should(Equal(1))
Ω(strings.Count(output, "A TEST")).Should(Equal(2))
})
It("should run the BeforeSuite once per parallel node, none of the tests, but it should run the AfterSuite for each node", func() {
session := startGinkgo(pathToTest, "--noColor", "--nodes=2")
Eventually(session).Should(gexec.Exit(1))
output := string(session.Out.Contents())
Ω(strings.Count(output, "BEFORE SUITE")).Should(Equal(2))
Ω(strings.Count(output, "AFTER SUITE")).Should(Equal(2))
Ω(strings.Count(output, "Test Panicked")).Should(Equal(2))
Ω(strings.Count(output, "A TEST")).Should(Equal(2))
})
})
Context("With passing synchronized before and after suites", func() {
BeforeEach(func() {
pathToTest = tmpPath("suite_setup")
copyIn("synchronized_setup_tests", pathToTest)
})
Context("when run with one node", func() {
It("should do all the work on that one node", func() {
session := startGinkgo(pathToTest, "--noColor")
Eventually(session).Should(gexec.Exit(0))
output := string(session.Out.Contents())
Ω(output).Should(ContainSubstring("BEFORE_A_1\nBEFORE_B_1: DATA"))
Ω(output).Should(ContainSubstring("AFTER_A_1\nAFTER_B_1"))
})
})
Context("when run across multiple nodes", func() {
It("should run the first BeforeSuite function (BEFORE_A) on node 1, the second (BEFORE_B) on all the nodes, the first AfterSuite (AFTER_A) on all the nodes, and then the second (AFTER_B) on Node 1 *after* everything else is finished", func() {
session := startGinkgo(pathToTest, "--noColor", "--nodes=3")
Eventually(session).Should(gexec.Exit(0))
output := string(session.Out.Contents())
Ω(output).Should(ContainSubstring("BEFORE_A_1"))
Ω(output).Should(ContainSubstring("BEFORE_B_1: DATA"))
Ω(output).Should(ContainSubstring("BEFORE_B_2: DATA"))
Ω(output).Should(ContainSubstring("BEFORE_B_3: DATA"))
Ω(output).ShouldNot(ContainSubstring("BEFORE_A_2"))
Ω(output).ShouldNot(ContainSubstring("BEFORE_A_3"))
Ω(output).Should(ContainSubstring("AFTER_A_1"))
Ω(output).Should(ContainSubstring("AFTER_A_2"))
Ω(output).Should(ContainSubstring("AFTER_A_3"))
Ω(output).Should(ContainSubstring("AFTER_B_1"))
Ω(output).ShouldNot(ContainSubstring("AFTER_B_2"))
Ω(output).ShouldNot(ContainSubstring("AFTER_B_3"))
})
})
Context("when streaming across multiple nodes", func() {
It("should run the first BeforeSuite function (BEFORE_A) on node 1, the second (BEFORE_B) on all the nodes, the first AfterSuite (AFTER_A) on all the nodes, and then the second (AFTER_B) on Node 1 *after* everything else is finished", func() {
session := startGinkgo(pathToTest, "--noColor", "--nodes=3", "--stream")
Eventually(session).Should(gexec.Exit(0))
output := string(session.Out.Contents())
Ω(output).Should(ContainSubstring("[1] BEFORE_A_1"))
Ω(output).Should(ContainSubstring("[1] BEFORE_B_1: DATA"))
Ω(output).Should(ContainSubstring("[2] BEFORE_B_2: DATA"))
Ω(output).Should(ContainSubstring("[3] BEFORE_B_3: DATA"))
Ω(output).ShouldNot(ContainSubstring("BEFORE_A_2"))
Ω(output).ShouldNot(ContainSubstring("BEFORE_A_3"))
Ω(output).Should(ContainSubstring("[1] AFTER_A_1"))
Ω(output).Should(ContainSubstring("[2] AFTER_A_2"))
Ω(output).Should(ContainSubstring("[3] AFTER_A_3"))
Ω(output).Should(ContainSubstring("[1] AFTER_B_1"))
Ω(output).ShouldNot(ContainSubstring("AFTER_B_2"))
Ω(output).ShouldNot(ContainSubstring("AFTER_B_3"))
})
})
})
Context("With a failing synchronized before suite", func() {
BeforeEach(func() {
pathToTest = tmpPath("suite_setup")
copyIn("exiting_synchronized_setup_tests", pathToTest)
})
It("should fail and let the user know that node 1 disappeared prematurely", func() {
session := startGinkgo(pathToTest, "--noColor", "--nodes=3")
Eventually(session).Should(gexec.Exit(1))
output := string(session.Out.Contents())
Ω(output).Should(ContainSubstring("Node 1 disappeared before completing BeforeSuite"))
Ω(output).Should(ContainSubstring("Ginkgo timed out waiting for all parallel nodes to report back!"))
})
})
})
|