fullMsg   string
	shortMsgs []string
}

func (e testShortError) Error() string { return e.fullMsg }

func (e *testShortError) ShortError() string {
	msg := e.shortMsgs[0]
	e.shortMsgs = e.shortMsgs[1:]
	return msg
}

var _ = Describe("NewValueResponse", func() {
	It("can be serialized to JSON", func() {
		resp := NewValueResponse("fake-value")
		boshassert.MatchesJSONString(GinkgoT(), resp, `{"value":"fake-value"}`)
	})

	It("shortening does not change the response", func() {
		resp := NewValueResponse("fake-value")
		boshassert.MatchesJSONString(GinkgoT(), resp.Shorten(), `{"value":"fake-value"}`)
	})
})

var _ = Describe("NewExceptionResponse", func() {
	Context("with error that can be shortened", func() {
		var err error

		BeforeEach(func() {
			err = &testShortError{
				fullMsg:   "fake-full-msg",
					jobSupervisor.StatusStatus = "running"

					specService.Spec = boshas.V1ApplySpec{
						Deployment: "fake-deployment",
					}

					expectedVitals := boshvitals.Vitals{
						Load: []string{"foo", "bar", "baz"},
					}
					vitalsService.GetVitals = expectedVitals
					expectedVM := map[string]interface{}{"name": "vm-abc-def"}

					state, err := action.Run("full")
					Expect(err).ToNot(HaveOccurred())

					boshassert.MatchesJSONString(GinkgoT(), state.AgentID, `"my-agent-id"`)
					boshassert.MatchesJSONString(GinkgoT(), state.JobState, `"running"`)
					boshassert.MatchesJSONString(GinkgoT(), state.Deployment, `"fake-deployment"`)
					Expect(*state.Vitals).To(Equal(expectedVitals))
					boshassert.MatchesJSONMap(GinkgoT(), state.VM, expectedVM)
				})

				Describe("non-populated field formatting", func() {
					It("returns network as empty hash if not set", func() {
						specService.Spec = boshas.V1ApplySpec{NetworkSpecs: nil}
						state, err := action.Run("full")
						Expect(err).ToNot(HaveOccurred())
						boshassert.MatchesJSONString(GinkgoT(), state.NetworkSpecs, `{}`)

						// Non-empty NetworkSpecs
						specService.Spec = boshas.V1ApplySpec{
	It("is not persistent", func() {
		Expect(action.IsPersistent()).To(BeFalse())
	})

	It("returns a running task", func() {
		taskService.StartedTasks["fake-task-id"] = boshtask.Task{
			ID:    "fake-task-id",
			State: boshtask.TaskStateRunning,
		}

		taskValue, err := action.Run("fake-task-id")
		Expect(err).ToNot(HaveOccurred())

		// Check JSON key casing
		boshassert.MatchesJSONString(GinkgoT(), taskValue,
			`{"agent_task_id":"fake-task-id","state":"running"}`)
	})

	It("returns a failed task", func() {
		taskService.StartedTasks["fake-task-id"] = boshtask.Task{
			ID:    "fake-task-id",
			State: boshtask.TaskStateFailed,
			Error: errors.New("fake-task-error"),
		}

		taskValue, err := action.Run("fake-task-id")
		Expect(err).To(HaveOccurred())
		Expect(err.Error()).To(Equal("Task fake-task-id result: fake-task-error"))
		Expect(taskValue).To(BeNil())
	})
			switch logType {
			case "job":
				expectedPath = filepath.Join("/fake", "dir", "sys", "log")
			case "agent":
				expectedPath = filepath.Join("/fake", "dir", "bosh", "log")
			}

			Expect(copier.FilteredCopyToTempDir).To(Equal(expectedPath))
			Expect(copier.FilteredCopyToTempFilters).To(Equal(expectedFilters))

			Expect(copier.FilteredCopyToTempTempDir).To(Equal(compressor.CompressFilesInDirDir))
			Expect(copier.CleanUpTempDir).To(Equal(compressor.CompressFilesInDirDir))

			Expect(compressor.CompressFilesInDirTarballPath).To(Equal(blobstore.CreateFileName))

			boshassert.MatchesJSONString(GinkgoT(), logs, `{"blobstore_id":"my-blob-id"}`)
		}

		It("logs errs if given invalid log type", func() {
			_, err := action.Run("other-logs", []string{})
			Expect(err).To(HaveOccurred())
		})

		It("agent logs with filters", func() {
			filters := []string{"**/*.stdout.log", "**/*.stderr.log"}
			expectedFilters := []string{"**/*.stdout.log", "**/*.stderr.log"}
			testLogs("agent", filters, expectedFilters)
		})

		It("agent logs without filters", func() {
			filters := []string{}
	Describe("Validate", func() {
		It("external validate writes config file", func() {
			options := map[string]interface{}{"fake-key": "fake-value"}

			blobstore := NewExternalBlobstore("fake-provider", options, fs, runner, uuidGen, configPath)

			runner.CommandExistsValue = true

			err := blobstore.Validate()
			Expect(err).ToNot(HaveOccurred())

			s3CliConfig, err := fs.ReadFileString(configPath)
			Expect(err).ToNot(HaveOccurred())

			expectedJSON := map[string]string{"fake-key": "fake-value"}
			boshassert.MatchesJSONString(GinkgoT(), expectedJSON, s3CliConfig)
		})

		It("external validate errors when command not in path", func() {
			options := map[string]interface{}{}

			blobstore := NewExternalBlobstore("fake-provider", options, fs, runner, uuidGen, configPath)

			err := blobstore.Validate()
			Expect(err).To(HaveOccurred())
			Expect(err.Error()).To(ContainSubstring("not found in PATH"))
		})
	})

	Describe("Get", func() {
		It("external get", func() {