示例#1
0
func (backend *dockerBackend) BuildStagingResponse(taskResponse *models.TaskCallbackResponse) (cc_messages.StagingResponseForCC, error) {
	var response cc_messages.StagingResponseForCC

	var annotation cc_messages.StagingTaskAnnotation
	err := json.Unmarshal([]byte(taskResponse.Annotation), &annotation)
	if err != nil {
		return cc_messages.StagingResponseForCC{}, err
	}

	if taskResponse.Failed {
		response.Error = backend.config.Sanitizer(taskResponse.FailureReason)
	} else {
		var result docker_app_lifecycle.StagingDockerResult
		err := json.Unmarshal([]byte(taskResponse.Result), &result)
		if err != nil {
			return cc_messages.StagingResponseForCC{}, err
		}

		dockerLifecycleData, err := helpers.BuildDockerStagingData(result.DockerImage)
		if err != nil {
			return cc_messages.StagingResponseForCC{}, err
		}

		response.ExecutionMetadata = result.ExecutionMetadata
		response.DetectedStartCommand = result.DetectedStartCommand
		response.LifecycleData = dockerLifecycleData
	}

	return response, nil
}
示例#2
0
					Context("with a valid staging result", func() {
						const dockerImage = "cloudfoundry/diego-docker-app"
						var lifecycleData *json.RawMessage

						BeforeEach(func() {
							stagingResult := docker_app_lifecycle.StagingDockerResult{
								ExecutionMetadata:    "metadata",
								DetectedStartCommand: map[string]string{"a": "b"},
								DockerImage:          dockerImage,
							}
							var err error
							stagingResultJson, err = json.Marshal(stagingResult)
							Expect(err).NotTo(HaveOccurred())

							lifecycleData, err = helpers.BuildDockerStagingData(dockerImage)
							Expect(err).NotTo(HaveOccurred())
						})

						It("populates a staging response correctly", func() {
							Expect(buildError).NotTo(HaveOccurred())
							Expect(response).To(Equal(cc_messages.StagingResponseForCC{
								ExecutionMetadata:    "metadata",
								DetectedStartCommand: map[string]string{"a": "b"},
								LifecycleData:        lifecycleData,
							}))
						})
					})

					Context("with an invalid staging result", func() {
						BeforeEach(func() {
示例#3
0
package helpers_test

import (
	"github.com/cloudfoundry-incubator/stager/helpers"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Stager helpers", func() {

	Describe("BuildDockerStagingData", func() {

		It("builds the correct json", func() {
			lifecycleData, err := helpers.BuildDockerStagingData("cloudfoundry/diego-docker-app")
			Expect(err).NotTo(HaveOccurred())

			json := []byte(*lifecycleData)
			Expect(json).To(MatchJSON(`{"docker_image":"cloudfoundry/diego-docker-app"}`))
		})
	})

})