How to use InvalidParallelProcessConfiguration method of types Package

Best Ginkgo code snippet using types.InvalidParallelProcessConfiguration

Run Ginkgo automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

config_test.go

Source: config_test.go Github

copy
1package types_test
2
3import (
4	"flag"
5	"net/http"
6
7	. "github.com/onsi/ginkgo/v2"
8	"github.com/onsi/ginkgo/v2/types"
9	. "github.com/onsi/gomega"
10	"github.com/onsi/gomega/ghttp"
11)
12
13var _ = Describe("Config", func() {
14	It("has valid deprecation doc links", func() {
15		flags := types.SuiteConfigFlags
16		flags = flags.CopyAppend(types.ParallelConfigFlags...)
17		flags = flags.CopyAppend(types.ReporterConfigFlags...)
18		flags = flags.CopyAppend(types.GinkgoCLISharedFlags...)
19		flags = flags.CopyAppend(types.GinkgoCLIRunAndWatchFlags...)
20		flags = flags.CopyAppend(types.GinkgoCLIRunFlags...)
21		flags = flags.CopyAppend(types.GinkgoCLIWatchFlags...)
22		flags = flags.CopyAppend(types.GoBuildFlags...)
23		flags = flags.CopyAppend(types.GoRunFlags...)
24		for _, flag := range flags {
25			if flag.DeprecatedDocLink != "" {
26				Ω(anchors.DocAnchors["MIGRATING_TO_V2.md"]).Should(ContainElement(flag.DeprecatedDocLink))
27			}
28		}
29	})
30
31	Describe("ReporterConfig", func() {
32		Describe("WillGenerateReport", func() {
33			It("returns true if it will generate a report", func() {
34				repConf := types.ReporterConfig{}
35				Ω(repConf.WillGenerateReport()).Should(BeFalse())
36
37				repConf = types.ReporterConfig{JSONReport: "foo"}
38				Ω(repConf.WillGenerateReport()).Should(BeTrue())
39
40				repConf = types.ReporterConfig{JUnitReport: "foo"}
41				Ω(repConf.WillGenerateReport()).Should(BeTrue())
42
43				repConf = types.ReporterConfig{TeamcityReport: "foo"}
44				Ω(repConf.WillGenerateReport()).Should(BeTrue())
45			})
46		})
47
48		Describe("Verbosity", func() {
49			It("returns the appropriate verbosity level", func() {
50				repConf := types.ReporterConfig{}
51				Ω(repConf.Verbosity()).Should(Equal(types.VerbosityLevelNormal))
52
53				repConf = types.ReporterConfig{Succinct: true}
54				Ω(repConf.Verbosity()).Should(Equal(types.VerbosityLevelSuccinct))
55
56				repConf = types.ReporterConfig{Verbose: true}
57				Ω(repConf.Verbosity()).Should(Equal(types.VerbosityLevelVerbose))
58
59				repConf = types.ReporterConfig{VeryVerbose: true}
60				Ω(repConf.Verbosity()).Should(Equal(types.VerbosityLevelVeryVerbose))
61			})
62
63			It("can do verbosity math", func() {
64				Ω(types.VerbosityLevelNormal.LT(types.VerbosityLevelVeryVerbose)).Should(BeTrue())
65				Ω(types.VerbosityLevelNormal.LT(types.VerbosityLevelVerbose)).Should(BeTrue())
66				Ω(types.VerbosityLevelNormal.LT(types.VerbosityLevelNormal)).Should(BeFalse())
67				Ω(types.VerbosityLevelNormal.LT(types.VerbosityLevelSuccinct)).Should(BeFalse())
68
69				Ω(types.VerbosityLevelNormal.LTE(types.VerbosityLevelVeryVerbose)).Should(BeTrue())
70				Ω(types.VerbosityLevelNormal.LTE(types.VerbosityLevelVerbose)).Should(BeTrue())
71				Ω(types.VerbosityLevelNormal.LTE(types.VerbosityLevelNormal)).Should(BeTrue())
72				Ω(types.VerbosityLevelNormal.LTE(types.VerbosityLevelSuccinct)).Should(BeFalse())
73
74				Ω(types.VerbosityLevelNormal.GT(types.VerbosityLevelVeryVerbose)).Should(BeFalse())
75				Ω(types.VerbosityLevelNormal.GT(types.VerbosityLevelVerbose)).Should(BeFalse())
76				Ω(types.VerbosityLevelNormal.GT(types.VerbosityLevelNormal)).Should(BeFalse())
77				Ω(types.VerbosityLevelNormal.GT(types.VerbosityLevelSuccinct)).Should(BeTrue())
78
79				Ω(types.VerbosityLevelNormal.GTE(types.VerbosityLevelVeryVerbose)).Should(BeFalse())
80				Ω(types.VerbosityLevelNormal.GTE(types.VerbosityLevelVerbose)).Should(BeFalse())
81				Ω(types.VerbosityLevelNormal.GTE(types.VerbosityLevelNormal)).Should(BeTrue())
82				Ω(types.VerbosityLevelNormal.GTE(types.VerbosityLevelSuccinct)).Should(BeTrue())
83
84				Ω(types.VerbosityLevelNormal.Is(types.VerbosityLevelVeryVerbose)).Should(BeFalse())
85				Ω(types.VerbosityLevelNormal.Is(types.VerbosityLevelVerbose)).Should(BeFalse())
86				Ω(types.VerbosityLevelNormal.Is(types.VerbosityLevelNormal)).Should(BeTrue())
87				Ω(types.VerbosityLevelNormal.Is(types.VerbosityLevelSuccinct)).Should(BeFalse())
88			})
89		})
90	})
91
92	Describe("VetConfig", func() {
93		var suiteConf types.SuiteConfig
94		var repConf types.ReporterConfig
95		var flagSet types.GinkgoFlagSet
96		var goFlagSet *flag.FlagSet
97
98		BeforeEach(func() {
99			var err error
100			goFlagSet = flag.NewFlagSet("test", flag.ContinueOnError)
101			goFlagSet.Int("count", 1, "")
102			goFlagSet.Int("parallel", 0, "")
103			flagSet, err = types.NewAttachedGinkgoFlagSet(goFlagSet, types.GinkgoFlags{}, nil, types.GinkgoFlagSections{}, types.GinkgoFlagSection{})
104			Ω(err).ShouldNot(HaveOccurred())
105
106			suiteConf = types.NewDefaultSuiteConfig()
107			repConf = types.NewDefaultReporterConfig()
108		})
109
110		Context("when all is well", func() {
111			It("retuns no errors", func() {
112				errors := types.VetConfig(flagSet, suiteConf, repConf)
113				Ω(errors).Should(BeEmpty())
114			})
115		})
116
117		Context("when unsupported go flags are parsed", func() {
118			BeforeEach(func() {
119				goFlagSet.Parse([]string{"-count=2", "-parallel=2"})
120			})
121
122			It("returns errors when unsupported go flags are set", func() {
123				errors := types.VetConfig(flagSet, suiteConf, repConf)
124				Ω(errors).Should(ConsistOf(types.GinkgoErrors.InvalidGoFlagCount(), types.GinkgoErrors.InvalidGoFlagParallel()))
125			})
126		})
127
128		Describe("errors related to parallelism", func() {
129			Context("when parallel total is less than one", func() {
130				BeforeEach(func() {
131					suiteConf.ParallelTotal = 0
132				})
133
134				It("errors", func() {
135					errors := types.VetConfig(flagSet, suiteConf, repConf)
136					Ω(errors).Should(ContainElement(types.GinkgoErrors.InvalidParallelTotalConfiguration()))
137				})
138			})
139
140			Context("when parallel node is less than one", func() {
141				BeforeEach(func() {
142					suiteConf.ParallelProcess = 0
143				})
144
145				It("errors", func() {
146					errors := types.VetConfig(flagSet, suiteConf, repConf)
147					Ω(errors).Should(ConsistOf(types.GinkgoErrors.InvalidParallelProcessConfiguration()))
148				})
149			})
150
151			Context("when parallel node is greater than parallel total", func() {
152				BeforeEach(func() {
153					suiteConf.ParallelProcess = suiteConf.ParallelTotal + 1
154				})
155
156				It("errors", func() {
157					errors := types.VetConfig(flagSet, suiteConf, repConf)
158					Ω(errors).Should(ConsistOf(types.GinkgoErrors.InvalidParallelProcessConfiguration()))
159				})
160			})
161
162			Context("when running in parallel", func() {
163				var server *ghttp.Server
164				BeforeEach(func() {
165					server = ghttp.NewServer()
166					server.SetAllowUnhandledRequests(true)
167					server.SetUnhandledRequestStatusCode(http.StatusOK)
168
169					suiteConf.ParallelTotal = 2
170					suiteConf.ParallelHost = server.URL()
171				})
172
173				AfterEach(func() {
174					server.Close()
175				})
176
177				Context("and parallel host is not set", func() {
178					BeforeEach(func() {
179						suiteConf.ParallelHost = ""
180					})
181					It("errors", func() {
182						errors := types.VetConfig(flagSet, suiteConf, repConf)
183						Ω(errors).Should(ConsistOf(types.GinkgoErrors.MissingParallelHostConfiguration()))
184					})
185				})
186
187				Context("when trying to dry run in parallel", func() {
188					BeforeEach(func() {
189						suiteConf.DryRun = true
190					})
191					It("errors", func() {
192						errors := types.VetConfig(flagSet, suiteConf, repConf)
193						Ω(errors).Should(ConsistOf(types.GinkgoErrors.DryRunInParallelConfiguration()))
194					})
195				})
196			})
197		})
198
199		Describe("file filter errors", func() {
200			Context("with an invalid --focus-file and/or --skip-file", func() {
201				BeforeEach(func() {
202					suiteConf.FocusFiles = append(suiteConf.FocusFiles, "bloop:123a")
203					suiteConf.SkipFiles = append(suiteConf.SkipFiles, "bloop:123b")
204				})
205
206				It("errors", func() {
207					errors := types.VetConfig(flagSet, suiteConf, repConf)
208					Ω(errors).Should(ConsistOf(types.GinkgoErrors.InvalidFileFilter("bloop:123a"), types.GinkgoErrors.InvalidFileFilter("bloop:123b")))
209				})
210			})
211		})
212
213		Describe("validating --output-interceptor-mode", func() {
214			It("errors if an invalid output interceptor mode is specified", func() {
215				suiteConf.OutputInterceptorMode = "DURP"
216				errors := types.VetConfig(flagSet, suiteConf, repConf)
217				Ω(errors).Should(ConsistOf(types.GinkgoErrors.InvalidOutputInterceptorModeConfiguration("DURP")))
218
219				for _, value := range []string{"", "dup", "DUP", "swap", "SWAP", "none", "NONE"} {
220					suiteConf.OutputInterceptorMode = value
221					errors = types.VetConfig(flagSet, suiteConf, repConf)
222					Ω(errors).Should(BeEmpty())
223				}
224			})
225		})
226
227		Context("when more than one verbosity flag is set", func() {
228			It("errors", func() {
229				repConf.Succinct, repConf.Verbose, repConf.VeryVerbose = true, true, false
230				errors := types.VetConfig(flagSet, suiteConf, repConf)
231				Ω(errors).Should(ConsistOf(types.GinkgoErrors.ConflictingVerbosityConfiguration()))
232
233				repConf.Succinct, repConf.Verbose, repConf.VeryVerbose = true, false, true
234				errors = types.VetConfig(flagSet, suiteConf, repConf)
235				Ω(errors).Should(ConsistOf(types.GinkgoErrors.ConflictingVerbosityConfiguration()))
236
237				repConf.Succinct, repConf.Verbose, repConf.VeryVerbose = false, true, true
238				errors = types.VetConfig(flagSet, suiteConf, repConf)
239				Ω(errors).Should(ConsistOf(types.GinkgoErrors.ConflictingVerbosityConfiguration()))
240
241				repConf.Succinct, repConf.Verbose, repConf.VeryVerbose = true, true, true
242				errors = types.VetConfig(flagSet, suiteConf, repConf)
243				Ω(errors).Should(ConsistOf(types.GinkgoErrors.ConflictingVerbosityConfiguration()))
244			})
245		})
246	})
247})
248
Full Screen

errors.go

Source: errors.go Github

copy
1package types
2
3import (
4	"fmt"
5	"reflect"
6	"strings"
7
8	"github.com/onsi/ginkgo/v2/formatter"
9)
10
11type GinkgoError struct {
12	Heading      string
13	Message      string
14	DocLink      string
15	CodeLocation CodeLocation
16}
17
18func (g GinkgoError) Error() string {
19	out := formatter.F("{{bold}}{{red}}%s{{/}}\n", g.Heading)
20	if (g.CodeLocation != CodeLocation{}) {
21		contentsOfLine := strings.TrimLeft(g.CodeLocation.ContentsOfLine(), "\t ")
22		if contentsOfLine != "" {
23			out += formatter.F("{{light-gray}}%s{{/}}\n", contentsOfLine)
24		}
25		out += formatter.F("{{gray}}%s{{/}}\n", g.CodeLocation)
26	}
27	if g.Message != "" {
28		out += formatter.Fiw(1, formatter.COLS, g.Message)
29		out += "\n\n"
30	}
31	if g.DocLink != "" {
32		out += formatter.Fiw(1, formatter.COLS, "{{bold}}Learn more at:{{/}} {{cyan}}{{underline}}http://onsi.github.io/ginkgo/#%s{{/}}\n", g.DocLink)
33	}
34
35	return out
36}
37
38type ginkgoErrors struct{}
39
40var GinkgoErrors = ginkgoErrors{}
41
42func (g ginkgoErrors) UncaughtGinkgoPanic(cl CodeLocation) error {
43	return GinkgoError{
44		Heading: "Your Test Panicked",
45		Message: `When you, or your assertion library, calls Ginkgo's Fail(),
46Ginkgo panics to prevent subsequent assertions from running.
47
48Normally Ginkgo rescues this panic so you shouldn't see it.
49
50However, if you make an assertion in a goroutine, Ginkgo can't capture the panic.
51To circumvent this, you should call
52
53	defer GinkgoRecover()
54
55at the top of the goroutine that caused this panic.
56
57Alternatively, you may have made an assertion outside of a Ginkgo
58leaf node (e.g. in a container node or some out-of-band function) - please move your assertion to
59an appropriate Ginkgo node (e.g. a BeforeSuite, BeforeEach, It, etc...).`,
60		DocLink:      "mental-model-how-ginkgo-handles-failure",
61		CodeLocation: cl,
62	}
63}
64
65func (g ginkgoErrors) RerunningSuite() error {
66	return GinkgoError{
67		Heading: "Rerunning Suite",
68		Message: formatter.F(`It looks like you are calling RunSpecs more than once. Ginkgo does not support rerunning suites.  If you want to rerun a suite try {{bold}}ginkgo --repeat=N{{/}} or {{bold}}ginkgo --until-it-fails{{/}}`),
69		DocLink: "repeating-spec-runs-and-managing-flaky-specs",
70	}
71}
72
73/* Tree construction errors */
74
75func (g ginkgoErrors) PushingNodeInRunPhase(nodeType NodeType, cl CodeLocation) error {
76	return GinkgoError{
77		Heading: "Ginkgo detected an issue with your spec structure",
78		Message: formatter.F(
79			`It looks like you are trying to add a {{bold}}[%s]{{/}} node
80to the Ginkgo spec tree in a leaf node {{bold}}after{{/}} the specs started running.
81
82To enable randomization and parallelization Ginkgo requires the spec tree
83to be fully constructed up front.  In practice, this means that you can
84only create nodes like {{bold}}[%s]{{/}} at the top-level or within the
85body of a {{bold}}Describe{{/}}, {{bold}}Context{{/}}, or {{bold}}When{{/}}.`, nodeType, nodeType),
86		CodeLocation: cl,
87		DocLink:      "mental-model-how-ginkgo-traverses-the-spec-hierarchy",
88	}
89}
90
91func (g ginkgoErrors) CaughtPanicDuringABuildPhase(caughtPanic interface{}, cl CodeLocation) error {
92	return GinkgoError{
93		Heading: "Assertion or Panic detected during tree construction",
94		Message: formatter.F(
95			`Ginkgo detected a panic while constructing the spec tree.
96You may be trying to make an assertion in the body of a container node
97(i.e. {{bold}}Describe{{/}}, {{bold}}Context{{/}}, or {{bold}}When{{/}}).
98
99Please ensure all assertions are inside leaf nodes such as {{bold}}BeforeEach{{/}},
100{{bold}}It{{/}}, etc.
101
102{{bold}}Here's the content of the panic that was caught:{{/}}
103%v`, caughtPanic),
104		CodeLocation: cl,
105		DocLink:      "no-assertions-in-container-nodes",
106	}
107}
108
109func (g ginkgoErrors) SuiteNodeInNestedContext(nodeType NodeType, cl CodeLocation) error {
110	docLink := "suite-setup-and-cleanup-beforesuite-and-aftersuite"
111	if nodeType.Is(NodeTypeReportAfterSuite) {
112		docLink = "reporting-nodes---reportaftersuite"
113	}
114
115	return GinkgoError{
116		Heading: "Ginkgo detected an issue with your spec structure",
117		Message: formatter.F(
118			`It looks like you are trying to add a {{bold}}[%s]{{/}} node within a container node.
119
120{{bold}}%s{{/}} can only be called at the top level.`, nodeType, nodeType),
121		CodeLocation: cl,
122		DocLink:      docLink,
123	}
124}
125
126func (g ginkgoErrors) SuiteNodeDuringRunPhase(nodeType NodeType, cl CodeLocation) error {
127	docLink := "suite-setup-and-cleanup-beforesuite-and-aftersuite"
128	if nodeType.Is(NodeTypeReportAfterSuite) {
129		docLink = "reporting-nodes---reportaftersuite"
130	}
131
132	return GinkgoError{
133		Heading: "Ginkgo detected an issue with your spec structure",
134		Message: formatter.F(
135			`It looks like you are trying to add a {{bold}}[%s]{{/}} node within a leaf node after the spec started running.
136
137{{bold}}%s{{/}} can only be called at the top level.`, nodeType, nodeType),
138		CodeLocation: cl,
139		DocLink:      docLink,
140	}
141}
142
143func (g ginkgoErrors) MultipleBeforeSuiteNodes(nodeType NodeType, cl CodeLocation, earlierNodeType NodeType, earlierCodeLocation CodeLocation) error {
144	return ginkgoErrorMultipleSuiteNodes("setup", nodeType, cl, earlierNodeType, earlierCodeLocation)
145}
146
147func (g ginkgoErrors) MultipleAfterSuiteNodes(nodeType NodeType, cl CodeLocation, earlierNodeType NodeType, earlierCodeLocation CodeLocation) error {
148	return ginkgoErrorMultipleSuiteNodes("teardown", nodeType, cl, earlierNodeType, earlierCodeLocation)
149}
150
151func ginkgoErrorMultipleSuiteNodes(setupOrTeardown string, nodeType NodeType, cl CodeLocation, earlierNodeType NodeType, earlierCodeLocation CodeLocation) error {
152	return GinkgoError{
153		Heading: "Ginkgo detected an issue with your spec structure",
154		Message: formatter.F(
155			`It looks like you are trying to add a {{bold}}[%s]{{/}} node but
156you already have a {{bold}}[%s]{{/}} node defined at: {{gray}}%s{{/}}.
157
158Ginkgo only allows you to define one suite %s node.`, nodeType, earlierNodeType, earlierCodeLocation, setupOrTeardown),
159		CodeLocation: cl,
160		DocLink:      "suite-setup-and-cleanup-beforesuite-and-aftersuite",
161	}
162}
163
164/* Decorator errors */
165func (g ginkgoErrors) InvalidDecoratorForNodeType(cl CodeLocation, nodeType NodeType, decorator string) error {
166	return GinkgoError{
167		Heading:      "Invalid Decorator",
168		Message:      formatter.F(`[%s] node cannot be passed a(n) '%s' decorator`, nodeType, decorator),
169		CodeLocation: cl,
170		DocLink:      "node-decorators-overview",
171	}
172}
173
174func (g ginkgoErrors) InvalidDeclarationOfFocusedAndPending(cl CodeLocation, nodeType NodeType) error {
175	return GinkgoError{
176		Heading:      "Invalid Combination of Decorators: Focused and Pending",
177		Message:      formatter.F(`[%s] node was decorated with both Focus and Pending.  At most one is allowed.`, nodeType),
178		CodeLocation: cl,
179		DocLink:      "node-decorators-overview",
180	}
181}
182
183func (g ginkgoErrors) UnknownDecorator(cl CodeLocation, nodeType NodeType, decorator interface{}) error {
184	return GinkgoError{
185		Heading:      "Unknown Decorator",
186		Message:      formatter.F(`[%s] node was passed an unknown decorator: '%#v'`, nodeType, decorator),
187		CodeLocation: cl,
188		DocLink:      "node-decorators-overview",
189	}
190}
191
192func (g ginkgoErrors) InvalidBodyType(t reflect.Type, cl CodeLocation, nodeType NodeType) error {
193	return GinkgoError{
194		Heading: "Invalid Function",
195		Message: formatter.F(`[%s] node must be passed {{bold}}func(){{/}} - i.e. functions that take nothing and return nothing.
196You passed {{bold}}%s{{/}} instead.`, nodeType, t),
197		CodeLocation: cl,
198		DocLink:      "node-decorators-overview",
199	}
200}
201
202func (g ginkgoErrors) MultipleBodyFunctions(cl CodeLocation, nodeType NodeType) error {
203	return GinkgoError{
204		Heading:      "Multiple Functions",
205		Message:      formatter.F(`[%s] node must be passed a single {{bold}}func(){{/}} - but more than one was passed in.`, nodeType),
206		CodeLocation: cl,
207		DocLink:      "node-decorators-overview",
208	}
209}
210
211func (g ginkgoErrors) MissingBodyFunction(cl CodeLocation, nodeType NodeType) error {
212	return GinkgoError{
213		Heading:      "Missing Functions",
214		Message:      formatter.F(`[%s] node must be passed a single {{bold}}func(){{/}} - but none was passed in.`, nodeType),
215		CodeLocation: cl,
216		DocLink:      "node-decorators-overview",
217	}
218}
219
220/* Ordered Container errors */
221func (g ginkgoErrors) InvalidSerialNodeInNonSerialOrderedContainer(cl CodeLocation, nodeType NodeType) error {
222	return GinkgoError{
223		Heading:      "Invalid Serial Node in Non-Serial Ordered Container",
224		Message:      formatter.F(`[%s] node was decorated with Serial but occurs in an Ordered container that is not marked Serial.  Move the Serial decorator to the outer-most Ordered container to mark all ordered specs within the container as serial.`, nodeType),
225		CodeLocation: cl,
226		DocLink:      "node-decorators-overview",
227	}
228}
229
230func (g ginkgoErrors) SetupNodeNotInOrderedContainer(cl CodeLocation, nodeType NodeType) error {
231	return GinkgoError{
232		Heading:      "Setup Node not in Ordered Container",
233		Message:      fmt.Sprintf("[%s] setup nodes must appear inside an Ordered container.  They cannot be nested within other containers, even containers in an ordered container.", nodeType),
234		CodeLocation: cl,
235		DocLink:      "ordered-containers",
236	}
237}
238
239/* DeferCleanup errors */
240func (g ginkgoErrors) DeferCleanupInvalidFunction(cl CodeLocation) error {
241	return GinkgoError{
242		Heading:      "DeferCleanup requires a valid function",
243		Message:      "You must pass DeferCleanup a function to invoke.  This function must return zero or one values - if it does return, it must return an error.  The function can take arbitrarily many arguments and you should provide these to DeferCleanup to pass along to the function.",
244		CodeLocation: cl,
245		DocLink:      "cleaning-up-our-cleanup-code-defercleanup",
246	}
247}
248
249func (g ginkgoErrors) PushingCleanupNodeDuringTreeConstruction(cl CodeLocation) error {
250	return GinkgoError{
251		Heading:      "DeferCleanup must be called inside a setup or subject node",
252		Message:      "You must call DeferCleanup inside a setup node (e.g. BeforeEach, BeforeSuite, AfterAll...) or a subject node (i.e. It).  You can't call DeferCleanup at the top-level or in a container node - use the After* family of setup nodes instead.",
253		CodeLocation: cl,
254		DocLink:      "cleaning-up-our-cleanup-code-defercleanup",
255	}
256}
257
258func (g ginkgoErrors) PushingCleanupInReportingNode(cl CodeLocation, nodeType NodeType) error {
259	return GinkgoError{
260		Heading:      fmt.Sprintf("DeferCleanup cannot be called in %s", nodeType),
261		Message:      "Please inline your cleanup code - Ginkgo won't run cleanup code after a ReportAfterEach or ReportAfterSuite.",
262		CodeLocation: cl,
263		DocLink:      "cleaning-up-our-cleanup-code-defercleanup",
264	}
265}
266
267func (g ginkgoErrors) PushingCleanupInCleanupNode(cl CodeLocation) error {
268	return GinkgoError{
269		Heading:      "DeferCleanup cannot be called in a DeferCleanup callback",
270		Message:      "Please inline your cleanup code - Ginkgo doesn't let you call DeferCleanup from within DeferCleanup",
271		CodeLocation: cl,
272		DocLink:      "cleaning-up-our-cleanup-code-defercleanup",
273	}
274}
275
276/* ReportEntry errors */
277func (g ginkgoErrors) TooManyReportEntryValues(cl CodeLocation, arg interface{}) error {
278	return GinkgoError{
279		Heading:      "Too Many ReportEntry Values",
280		Message:      formatter.F(`{{bold}}AddGinkgoReport{{/}} can only be given one value. Got unexpected value: %#v`, arg),
281		CodeLocation: cl,
282		DocLink:      "attaching-data-to-reports",
283	}
284}
285
286func (g ginkgoErrors) AddReportEntryNotDuringRunPhase(cl CodeLocation) error {
287	return GinkgoError{
288		Heading:      "Ginkgo detected an issue with your spec structure",
289		Message:      formatter.F(`It looks like you are calling {{bold}}AddGinkgoReport{{/}} outside of a running spec.  Make sure you call {{bold}}AddGinkgoReport{{/}} inside a runnable node such as It or BeforeEach and not inside the body of a container such as Describe or Context.`),
290		CodeLocation: cl,
291		DocLink:      "attaching-data-to-reports",
292	}
293}
294
295/* By errors */
296func (g ginkgoErrors) ByNotDuringRunPhase(cl CodeLocation) error {
297	return GinkgoError{
298		Heading:      "Ginkgo detected an issue with your spec structure",
299		Message:      formatter.F(`It looks like you are calling {{bold}}By{{/}} outside of a running spec.  Make sure you call {{bold}}By{{/}} inside a runnable node such as It or BeforeEach and not inside the body of a container such as Describe or Context.`),
300		CodeLocation: cl,
301		DocLink:      "documenting-complex-specs-by",
302	}
303}
304
305/* FileFilter and SkipFilter errors */
306func (g ginkgoErrors) InvalidFileFilter(filter string) error {
307	return GinkgoError{
308		Heading: "Invalid File Filter",
309		Message: fmt.Sprintf(`The provided file filter: "%s" is invalid.  File filters must have the format "file", "file:lines" where "file" is a regular expression that will match against the file path and lines is a comma-separated list of integers (e.g. file:1,5,7) or line-ranges (e.g. file:1-3,5-9) or both (e.g. file:1,5-9)`, filter),
310		DocLink: "filtering-specs",
311	}
312}
313
314func (g ginkgoErrors) InvalidFileFilterRegularExpression(filter string, err error) error {
315	return GinkgoError{
316		Heading: "Invalid File Filter Regular Expression",
317		Message: fmt.Sprintf(`The provided file filter: "%s" included an invalid regular expression.  regexp.Compile error: %s`, filter, err),
318		DocLink: "filtering-specs",
319	}
320}
321
322/* Label Errors */
323func (g ginkgoErrors) SyntaxErrorParsingLabelFilter(input string, location int, error string) error {
324	var message string
325	if location >= 0 {
326		for i, r := range input {
327			if i == location {
328				message += "{{red}}{{bold}}{{underline}}"
329			}
330			message += string(r)
331			if i == location {
332				message += "{{/}}"
333			}
334		}
335	} else {
336		message = input
337	}
338	message += "\n" + error
339	return GinkgoError{
340		Heading: "Syntax Error Parsing Label Filter",
341		Message: message,
342		DocLink: "spec-labels",
343	}
344}
345
346func (g ginkgoErrors) InvalidLabel(label string, cl CodeLocation) error {
347	return GinkgoError{
348		Heading:      "Invalid Label",
349		Message:      fmt.Sprintf("'%s' is an invalid label.  Labels cannot contain of the following characters: '&|!,()/'", label),
350		CodeLocation: cl,
351		DocLink:      "spec-labels",
352	}
353}
354
355func (g ginkgoErrors) InvalidEmptyLabel(cl CodeLocation) error {
356	return GinkgoError{
357		Heading:      "Invalid Empty Label",
358		Message:      "Labels cannot be empty",
359		CodeLocation: cl,
360		DocLink:      "spec-labels",
361	}
362}
363
364/* Table errors */
365func (g ginkgoErrors) MultipleEntryBodyFunctionsForTable(cl CodeLocation) error {
366	return GinkgoError{
367		Heading:      "DescribeTable passed multiple functions",
368		Message:      "It looks like you are passing multiple functions into DescribeTable.  Only one function can be passed in.  This function will be called for each Entry in the table.",
369		CodeLocation: cl,
370		DocLink:      "table-specs",
371	}
372}
373
374func (g ginkgoErrors) InvalidEntryDescription(cl CodeLocation) error {
375	return GinkgoError{
376		Heading:      "Invalid Entry description",
377		Message:      "Entry description functions must be a string, a function that accepts the entry parameters and returns a string, or nil.",
378		CodeLocation: cl,
379		DocLink:      "table-specs",
380	}
381}
382
383func (g ginkgoErrors) IncorrectParameterTypeForTable(i int, name string, cl CodeLocation) error {
384	return GinkgoError{
385		Heading:      "DescribeTable passed incorrect parameter type",
386		Message:      fmt.Sprintf("Parameter #%d passed to DescribeTable is of incorrect type <%s>", i, name),
387		CodeLocation: cl,
388		DocLink:      "table-specs",
389	}
390}
391
392func (g ginkgoErrors) TooFewParametersToTableFunction(expected, actual int, kind string, cl CodeLocation) error {
393	return GinkgoError{
394		Heading:      fmt.Sprintf("Too few parameters passed in to %s", kind),
395		Message:      fmt.Sprintf("The %s expected %d parameters but you passed in %d", kind, expected, actual),
396		CodeLocation: cl,
397		DocLink:      "table-specs",
398	}
399}
400
401func (g ginkgoErrors) TooManyParametersToTableFunction(expected, actual int, kind string, cl CodeLocation) error {
402	return GinkgoError{
403		Heading:      fmt.Sprintf("Too many parameters passed in to %s", kind),
404		Message:      fmt.Sprintf("The %s expected %d parameters but you passed in %d", kind, expected, actual),
405		CodeLocation: cl,
406		DocLink:      "table-specs",
407	}
408}
409
410func (g ginkgoErrors) IncorrectParameterTypeToTableFunction(i int, expected, actual reflect.Type, kind string, cl CodeLocation) error {
411	return GinkgoError{
412		Heading:      fmt.Sprintf("Incorrect parameters type passed to %s", kind),
413		Message:      fmt.Sprintf("The %s expected parameter #%d to be of type <%s> but you passed in <%s>", kind, i, expected, actual),
414		CodeLocation: cl,
415		DocLink:      "table-specs",
416	}
417}
418
419func (g ginkgoErrors) IncorrectVariadicParameterTypeToTableFunction(expected, actual reflect.Type, kind string, cl CodeLocation) error {
420	return GinkgoError{
421		Heading:      fmt.Sprintf("Incorrect parameters type passed to %s", kind),
422		Message:      fmt.Sprintf("The %s expected its variadic parameters to be of type <%s> but you passed in <%s>", kind, expected, actual),
423		CodeLocation: cl,
424		DocLink:      "table-specs",
425	}
426}
427
428/* Parallel Synchronization errors */
429
430func (g ginkgoErrors) AggregatedReportUnavailableDueToNodeDisappearing() error {
431	return GinkgoError{
432		Heading: "Test Report unavailable because a Ginkgo parallel process disappeared",
433		Message: "The aggregated report could not be fetched for a ReportAfterSuite node.  A Ginkgo parallel process disappeared before it could finish reporting.",
434	}
435}
436
437func (g ginkgoErrors) SynchronizedBeforeSuiteFailedOnProc1() error {
438	return GinkgoError{
439		Heading: "SynchronizedBeforeSuite failed on Ginkgo parallel process #1",
440		Message: "The first SynchronizedBeforeSuite function running on Ginkgo parallel process #1 failed.  This suite will now abort.",
441	}
442}
443
444func (g ginkgoErrors) SynchronizedBeforeSuiteDisappearedOnProc1() error {
445	return GinkgoError{
446		Heading: "Process #1 disappeared before SynchronizedBeforeSuite could report back",
447		Message: "Ginkgo parallel process #1 disappeared before the first SynchronizedBeforeSuite function completed.  This suite will now abort.",
448	}
449}
450
451/* Configuration errors */
452
453func (g ginkgoErrors) UnknownTypePassedToRunSpecs(value interface{}) error {
454	return GinkgoError{
455		Heading: "Unknown Type passed to RunSpecs",
456		Message: fmt.Sprintf("RunSpecs() accepts labels, and configuration of type types.SuiteConfig and/or types.ReporterConfig.\n You passed in: %v", value),
457	}
458}
459
460var sharedParallelErrorMessage = "It looks like you are trying to run specs in parallel with go test.\nThis is unsupported and you should use the ginkgo CLI instead."
461
462func (g ginkgoErrors) InvalidParallelTotalConfiguration() error {
463	return GinkgoError{
464		Heading: "-ginkgo.parallel.total must be >= 1",
465		Message: sharedParallelErrorMessage,
466		DocLink: "spec-parallelization",
467	}
468}
469
470func (g ginkgoErrors) InvalidParallelProcessConfiguration() error {
471	return GinkgoError{
472		Heading: "-ginkgo.parallel.process is one-indexed and must be <= ginkgo.parallel.total",
473		Message: sharedParallelErrorMessage,
474		DocLink: "spec-parallelization",
475	}
476}
477
478func (g ginkgoErrors) MissingParallelHostConfiguration() error {
479	return GinkgoError{
480		Heading: "-ginkgo.parallel.host is missing",
481		Message: sharedParallelErrorMessage,
482		DocLink: "spec-parallelization",
483	}
484}
485
486func (g ginkgoErrors) UnreachableParallelHost(host string) error {
487	return GinkgoError{
488		Heading: "Could not reach ginkgo.parallel.host:" + host,
489		Message: sharedParallelErrorMessage,
490		DocLink: "spec-parallelization",
491	}
492}
493
494func (g ginkgoErrors) DryRunInParallelConfiguration() error {
495	return GinkgoError{
496		Heading: "Ginkgo only performs -dryRun in serial mode.",
497		Message: "Please try running ginkgo -dryRun again, but without -p or -procs to ensure the suite is running in series.",
498	}
499}
500
501func (g ginkgoErrors) ConflictingVerbosityConfiguration() error {
502	return GinkgoError{
503		Heading: "Conflicting reporter verbosity settings.",
504		Message: "You can't set more than one of -v, -vv and --succinct.  Please pick one!",
505	}
506}
507
508func (g ginkgoErrors) InvalidOutputInterceptorModeConfiguration(value string) error {
509	return GinkgoError{
510		Heading: fmt.Sprintf("Invalid value '%s' for --output-interceptor-mode.", value),
511		Message: "You must choose one of 'dup', 'swap', or 'none'.",
512	}
513}
514
515func (g ginkgoErrors) InvalidGoFlagCount() error {
516	return GinkgoError{
517		Heading: "Use of go test -count",
518		Message: "Ginkgo does not support using go test -count to rerun suites.  Only -count=1 is allowed.  To repeat suite runs, please use the ginkgo cli and `ginkgo -until-it-fails` or `ginkgo -repeat=N`.",
519	}
520}
521
522func (g ginkgoErrors) InvalidGoFlagParallel() error {
523	return GinkgoError{
524		Heading: "Use of go test -parallel",
525		Message: "Go test's implementation of parallelization does not actually parallelize Ginkgo specs.  Please use the ginkgo cli and `ginkgo -p` or `ginkgo -procs=N` instead.",
526	}
527}
528
529func (g ginkgoErrors) BothRepeatAndUntilItFails() error {
530	return GinkgoError{
531		Heading: "--repeat and --until-it-fails are both set",
532		Message: "--until-it-fails directs Ginkgo to rerun specs indefinitely until they fail.  --repeat directs Ginkgo to rerun specs a set number of times.  You can't set both... which would you like?",
533	}
534}
535
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Most used method in

Trigger InvalidParallelProcessConfiguration code on LambdaTest Cloud Grid

Execute automation tests with InvalidParallelProcessConfiguration on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)