예제 #1
0
			Context("when configuring succeeds", func() {
				BeforeEach(func() {
					newGroup := changedConfig.Groups[1]
					newGroup.Name = "some-new-group"
					changedConfig.Groups[0].Jobs = append(changedConfig.Groups[0].Jobs, "some-new-job")
					changedConfig.Groups = append(changedConfig.Groups[:1], newGroup)

					newResource := changedConfig.Resources[1]
					newResource.Name = "some-new-resource"
					changedConfig.Resources[0].Type = "some-new-type"
					changedConfig.Resources = append(changedConfig.Resources[:1], newResource)

					newJob := changedConfig.Jobs[1]
					newJob.Name = "some-new-job"
					changedConfig.Jobs[0].Serial = false
					changedConfig.Jobs = append(changedConfig.Jobs[:1], newJob)

					path, err := atc.Routes.CreatePathForRoute(atc.SaveConfig, rata.Params{"pipeline_name": "awesome-pipeline"})
					Ω(err).ShouldNot(HaveOccurred())

					atcServer.RouteToHandler("PUT", path,
						ghttp.CombineHandlers(
							ghttp.VerifyHeaderKV(atc.ConfigVersionHeader, "42"),
							func(w http.ResponseWriter, r *http.Request) {
								config, state := getConfigAndPausedState(r)
								Ω(config).Should(Equal(payload))
								Ω(*state).Should(BeTrue(), "paused was not set in the request")
							},
							ghttp.RespondWith(200, ""),
						),
					)
예제 #2
0
		})
	})

	Describe("validating a job", func() {
		var job atc.JobConfig

		BeforeEach(func() {
			job = atc.JobConfig{
				Name: "some-other-job",
			}
		})

		Context("when a job has no name", func() {
			BeforeEach(func() {
				job.Name = ""
				config.Jobs = append(config.Jobs, job)
			})

			It("returns an error", func() {
				Expect(validateErr).To(HaveOccurred())
				Expect(validateErr.Error()).To(ContainSubstring(
					"jobs[2] has no name",
				))
			})
		})

		Describe("plans", func() {
			Context("when multiple actions are specified in the same plan", func() {
				Context("when it's not just Get and Put", func() {
					BeforeEach(func() {
						job.Plan = append(job.Plan, atc.PlanConfig{
예제 #3
0
func (db PlanConvertingConfigDB) convertJobsToPlan(config atc.Config) atc.Config {
	convertedJobs := make([]atc.JobConfig, len(config.Jobs))
	copy(convertedJobs, config.Jobs)

	for ji, job := range convertedJobs {
		if len(job.Plan) > 0 { // skip jobs already converted to plans
			continue
		}

		convertedSequence := atc.PlanSequence{}

		inputAggregates := make(atc.PlanSequence, len(job.InputConfigs))
		for ii, input := range job.InputConfigs {
			name := input.RawName
			resource := input.Resource
			if name == "" {
				name = input.Resource
				resource = ""
			}

			inputAggregates[ii] = atc.PlanConfig{
				Get:      name,
				Resource: resource,
				Trigger:  input.Trigger,
				Passed:   input.Passed,
				Params:   input.Params,
			}
		}

		if len(inputAggregates) > 0 {
			convertedSequence = append(convertedSequence, atc.PlanConfig{
				Aggregate: &inputAggregates,
			})
		}

		if job.TaskConfig != nil || job.TaskConfigPath != "" {
			convertedSequence = append(convertedSequence, atc.PlanConfig{
				Task:           "build", // default name
				TaskConfigPath: job.TaskConfigPath,
				TaskConfig:     job.TaskConfig,
				Privileged:     job.Privileged,
			})
		}

		outputAggregates := make(atc.PlanSequence, len(job.OutputConfigs))
		for oi, output := range job.OutputConfigs {
			var conditions *atc.Conditions
			if output.RawPerformOn != nil { // NOT len(0)
				conditionsCasted := atc.Conditions(output.RawPerformOn)
				conditions = &conditionsCasted
			}

			outputAggregates[oi] = atc.PlanConfig{
				Put:        output.Resource,
				Conditions: conditions,
				Params:     output.Params,
			}
		}

		if len(outputAggregates) > 0 {
			convertedSequence = append(convertedSequence, atc.PlanConfig{
				Aggregate: &outputAggregates,
			})
		}

		// zero-out old-style config so they're omitted from new payload
		convertedJobs[ji].InputConfigs = nil
		convertedJobs[ji].OutputConfigs = nil
		convertedJobs[ji].TaskConfigPath = ""
		convertedJobs[ji].TaskConfig = nil
		convertedJobs[ji].Privileged = false

		convertedJobs[ji].Plan = convertedSequence
	}

	config.Jobs = convertedJobs

	return config
}