예제 #1
0
			BeforeEach(func() {
				task1 = &fakeTask{TaskName: "task1"}
				task2 = &fakeTask{TaskName: "task2"}

				pipeline := task.NewPipeline("some-name", logger, task1, task2)

				finalArtifact, runErr = pipeline.Run(originalArtifact)
			})

			It("executes all tasks with given artifact", func() {
				Expect(task1.Artifact).To(Equal(originalArtifact))
				Expect(task2.Artifact.Path()).To(Equal("task1"))
			})

			It("returns the artifact of the last task", func() {
				Expect(finalArtifact.Path()).To(Equal("task2"))
			})

			It("logs each step", func() {
				Expect(log).To(ContainSequence(
					Info(Data("event", "starting", "pipeline", "some-name", "task", "task1")),
					Info(Data("event", "done", "pipeline", "some-name", "task", "task1")),
					Info(Data("event", "starting", "pipeline", "some-name", "task", "task2")),
					Info(Data("event", "done", "pipeline", "some-name", "task", "task2")),
				))
			})

			It("does not return an error", func() {
				Expect(runErr).ToNot(HaveOccurred())
			})
		})
예제 #2
0
			renameTask := task.NewRename(finalPath, logger)
			renamedArtifact, runErr = renameTask.Run(artifact)
		})

		AfterEach(func() {
			os.Remove(tmpDirPath)
		})

		It("renames the artifact on disk", func() {
			Expect(originalPath).ToNot(BeAnExistingFile())
			Expect(finalPath).To(BeAnExistingFile())
		})

		It("returns artifact with the new path", func() {
			Expect(renamedArtifact.Path()).To(Equal(finalPath))
		})

		It("does not return error", func() {
			Expect(runErr).ToNot(HaveOccurred())
		})

		It("provides logging", func() {
			Expect(log).To(gbytes.Say(fmt.Sprintf(`{"event":"starting","source":"%s","target":"%s","task":"rename"}`, originalPath, finalPath)))
			Expect(log).To(gbytes.Say(fmt.Sprintf(`{"event":"done","source":"%s","target":"%s","task":"rename"}`, originalPath, finalPath)))
		})

		Context("when an error occurs", func() {
			BeforeEach(func() {
				originalPath = "path/to/nowhere"
				artifact := task.NewArtifact(originalPath)
			fakeRedisClient = &fakes.Client{
				ExpectedRDBPath: expectedArtifactPath,
			}
			timeout = 123 * time.Second
			logger = lager.NewLogger("logger")
			log = gbytes.NewBuffer()
			logger.RegisterSink(lager.NewWriterSink(log, lager.INFO))
			snapshotter = backup.NewSnapshotter(fakeRedisClient, timeout, logger)
		})

		JustBeforeEach(func() {
			artifact, err = snapshotter.Snapshot()
		})

		It("creates an artifact with the right path", func() {
			Expect(artifact.Path()).To(Equal(expectedArtifactPath))
		})

		It("does not return an error", func() {
			Expect(err).ToNot(HaveOccurred())
		})

		It("runs bgsave on client and waits for completion of save", func() {
			Expect(fakeRedisClient.RunBGSaveCallCount).To(Equal(1))
			Expect(fakeRedisClient.WaitForNewSaveSinceCallCount).To(Equal(1))
		})

		It("provides logging", func() {
			Expect(log).To(gbytes.Say(fmt.Sprintf(`{"event":"starting","task":"create-snapshot","timeout":"%s"}`, timeout.String())))
			Expect(log).To(gbytes.Say(fmt.Sprintf(`{"event":"done","task":"create-snapshot","timeout":"%s"}`, timeout.String())))
			Expect(log).To(gbytes.Say(`{"event":"starting","task":"get-rdb-path"}`))
예제 #4
0
			_, actualTimeout, _ := providerFactory.SnapshotterProviderArgsForCall(0)
			Expect(actualTimeout).To(Equal(expectedTimeout))
		})

		It("creates the snapshotter with the correct logger", func() {
			_, _, actualLogger := providerFactory.SnapshotterProviderArgsForCall(0)
			Expect(actualLogger).To(Equal(logger))
		})

		It("takes a snapshot", func() {
			Expect(snapshotter.SnapshotCallCount()).To(Equal(1))
		})

		It("creates the rename task with a new path that is different from the initial artifact", func() {
			newPath, _ := providerFactory.RenameTaskProviderArgsForCall(0)
			Expect(newPath).ToNot(Equal(initialArtifact.Path()))
		})

		It("creates the rename task with the correct logger", func() {
			_, actualLogger := providerFactory.RenameTaskProviderArgsForCall(0)
			Expect(actualLogger).To(Equal(logger))
		})

		It("creates the s3 upload task with the correct bucket name", func() {
			actualBucketName, _, _, _, _, _, _ := providerFactory.S3UploadTaskProviderArgsForCall(0)
			Expect(actualBucketName).To(Equal(expectedBucketName))
		})

		It("creates the s3 upload task with the correct target path", func() {
			_, actualTargetPath, _, _, _, _, _ := providerFactory.S3UploadTaskProviderArgsForCall(0)
			Expect(actualTargetPath).To(Equal(expectedTargetPath))