Ejemplo n.º 1
0
								if jobName == "foo" {
									return fooScript
								} else if jobName == "bar" {
									return barScript
								} else {
									panic("Non-matching update drain script created")
								}
							}

							parallelScript.RunReturns(nil)

							value, err := act()
							Expect(err).ToNot(HaveOccurred())
							Expect(value).To(Equal(0))

							Expect(parallelScript.RunCallCount()).To(Equal(1))
							Expect(jobScriptProvider.NewParallelScriptCallCount()).To(Equal(1))

							scriptName, scripts := jobScriptProvider.NewParallelScriptArgsForCall(0)
							Expect(scriptName).To(Equal("drain"))
							Expect(scripts).To(Equal([]boshscript.Script{fooScript, barScript}))
						})

						It("returns an error when parallel script fails", func() {
							parallelScript.RunReturns(errors.New("fake-error"))

							value, err := act()
							Expect(err).To(HaveOccurred())
							Expect(err.Error()).To(ContainSubstring("fake-error"))
							Expect(value).To(Equal(0))
						})
			BeforeEach(func() {
				existingScript = &fakescript.FakeScript{}
				existingScript.TagReturns("fake-job-1")
				existingScript.PathReturns("path/to/script1")
				existingScript.ExistsReturns(true)
				scripts = append(scripts, existingScript)
			})

			It("executes the script and succeeds", func() {
				existingScript.RunReturns(nil)

				err := parallelScript.Run()
				Expect(err).ToNot(HaveOccurred())

				Expect(existingScript.RunCallCount()).To(Equal(1))
			})

			It("gives an error when script fails", func() {
				existingScript.RunReturns(errors.New("fake-error"))

				err := parallelScript.Run()
				Expect(err).To(HaveOccurred())
				Expect(err.Error()).To(Equal("1 of 1 run-me scripts failed. Failed Jobs: fake-job-1."))

				Expect(existingScript.RunCallCount()).To(Equal(1))
			})
		})

		Context("when script does not exist", func() {
			var nonExistingScript *fakescript.FakeScript