Merge pull request #4092 from joshzarrabi/master
This commit is contained in:
commit
92b9b8b6ac
|
@ -9,7 +9,8 @@ import (
|
|||
)
|
||||
|
||||
type PausePipelineCommand struct {
|
||||
Pipeline flaghelpers.PipelineFlag `short:"p" long:"pipeline" required:"true" description:"Pipeline to pause"`
|
||||
Pipeline flaghelpers.PipelineFlag `short:"p" long:"pipeline" description:"Pipeline to pause"`
|
||||
All bool `short:"a" long:"all" description:"Pause all pipelines"`
|
||||
}
|
||||
|
||||
func (command *PausePipelineCommand) Validate() error {
|
||||
|
@ -17,13 +18,19 @@ func (command *PausePipelineCommand) Validate() error {
|
|||
}
|
||||
|
||||
func (command *PausePipelineCommand) Execute(args []string) error {
|
||||
if string(command.Pipeline) == "" && !command.All {
|
||||
displayhelpers.Failf("Either a pipeline name or --all are required")
|
||||
}
|
||||
|
||||
if string(command.Pipeline) != "" && command.All {
|
||||
displayhelpers.Failf("A pipeline and --all can not both be specified")
|
||||
}
|
||||
|
||||
err := command.Validate()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
pipelineName := string(command.Pipeline)
|
||||
|
||||
target, err := rc.LoadTarget(Fly.Target, Fly.Verbose)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -34,15 +41,33 @@ func (command *PausePipelineCommand) Execute(args []string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
found, err := target.Team().PausePipeline(pipelineName)
|
||||
if err != nil {
|
||||
return err
|
||||
var pipelineNames []string
|
||||
if string(command.Pipeline) != "" {
|
||||
pipelineNames = []string{string(command.Pipeline)}
|
||||
}
|
||||
|
||||
if found {
|
||||
fmt.Printf("paused '%s'\n", pipelineName)
|
||||
} else {
|
||||
displayhelpers.Failf("pipeline '%s' not found\n", pipelineName)
|
||||
if command.All {
|
||||
pipelines, err := target.Team().ListPipelines()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, pipeline := range pipelines {
|
||||
pipelineNames = append(pipelineNames, pipeline.Name)
|
||||
}
|
||||
}
|
||||
|
||||
for _, pipelineName := range pipelineNames {
|
||||
found, err := target.Team().PausePipeline(pipelineName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if found {
|
||||
fmt.Printf("paused '%s'\n", pipelineName)
|
||||
} else {
|
||||
displayhelpers.Failf("pipeline '%s' not found\n", pipelineName)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -9,7 +9,8 @@ import (
|
|||
)
|
||||
|
||||
type UnpausePipelineCommand struct {
|
||||
Pipeline flaghelpers.PipelineFlag `short:"p" long:"pipeline" required:"true" description:"Pipeline to unpause"`
|
||||
Pipeline flaghelpers.PipelineFlag `short:"p" long:"pipeline" description:"Pipeline to unpause"`
|
||||
All bool `short:"a" long:"all" description:"Unpause all pipelines"`
|
||||
}
|
||||
|
||||
func (command *UnpausePipelineCommand) Validate() error {
|
||||
|
@ -17,13 +18,19 @@ func (command *UnpausePipelineCommand) Validate() error {
|
|||
}
|
||||
|
||||
func (command *UnpausePipelineCommand) Execute(args []string) error {
|
||||
if string(command.Pipeline) == "" && !command.All {
|
||||
displayhelpers.Failf("Either a pipeline name or --all are required")
|
||||
}
|
||||
|
||||
if string(command.Pipeline) != "" && command.All {
|
||||
displayhelpers.Failf("A pipeline and --all can not both be specified")
|
||||
}
|
||||
|
||||
err := command.Validate()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
pipelineName := string(command.Pipeline)
|
||||
|
||||
target, err := rc.LoadTarget(Fly.Target, Fly.Verbose)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -34,15 +41,33 @@ func (command *UnpausePipelineCommand) Execute(args []string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
found, err := target.Team().UnpausePipeline(pipelineName)
|
||||
if err != nil {
|
||||
return err
|
||||
var pipelineNames []string
|
||||
if string(command.Pipeline) != "" {
|
||||
pipelineNames = []string{string(command.Pipeline)}
|
||||
}
|
||||
|
||||
if found {
|
||||
fmt.Printf("unpaused '%s'\n", pipelineName)
|
||||
} else {
|
||||
displayhelpers.Failf("pipeline '%s' not found\n", pipelineName)
|
||||
if command.All {
|
||||
pipelines, err := target.Team().ListPipelines()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, pipeline := range pipelines {
|
||||
pipelineNames = append(pipelineNames, pipeline.Name)
|
||||
}
|
||||
}
|
||||
|
||||
for _, pipelineName := range pipelineNames {
|
||||
found, err := target.Team().UnpausePipeline(pipelineName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if found {
|
||||
fmt.Printf("unpaused '%s'\n", pipelineName)
|
||||
} else {
|
||||
displayhelpers.Failf("pipeline '%s' not found\n", pipelineName)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -81,7 +81,7 @@ var _ = Describe("Fly CLI", func() {
|
|||
})
|
||||
})
|
||||
|
||||
Context("when the pipline name is not specified", func() {
|
||||
Context("when the pipline name or --all is not specified", func() {
|
||||
It("errors", func() {
|
||||
Expect(func() {
|
||||
flyCmd := exec.Command(flyPath, "-t", targetName, "pause-pipeline")
|
||||
|
@ -89,6 +89,26 @@ var _ = Describe("Fly CLI", func() {
|
|||
sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
Eventually(sess.Err).Should(gbytes.Say(`Either a pipeline name or --all are required`))
|
||||
|
||||
<-sess.Exited
|
||||
Expect(sess.ExitCode()).To(Equal(1))
|
||||
}).To(Change(func() int {
|
||||
return len(atcServer.ReceivedRequests())
|
||||
}).By(0))
|
||||
})
|
||||
})
|
||||
|
||||
Context("when both the pipline name and --all are specified", func() {
|
||||
It("errors", func() {
|
||||
Expect(func() {
|
||||
flyCmd := exec.Command(flyPath, "-t", targetName, "pause-pipeline", "-p", "awesome-pipeline", "--all")
|
||||
|
||||
sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
Eventually(sess.Err).Should(gbytes.Say(`A pipeline and --all can not both be specified`))
|
||||
|
||||
<-sess.Exited
|
||||
Expect(sess.ExitCode()).To(Equal(1))
|
||||
}).To(Change(func() int {
|
||||
|
@ -112,4 +132,56 @@ var _ = Describe("Fly CLI", func() {
|
|||
})
|
||||
|
||||
})
|
||||
|
||||
Context("when the --all flag is passed", func() {
|
||||
var (
|
||||
somePath string
|
||||
someOtherPath string
|
||||
err error
|
||||
)
|
||||
|
||||
BeforeEach(func() {
|
||||
somePath, err = atc.Routes.CreatePathForRoute(atc.PausePipeline, rata.Params{"pipeline_name": "awesome-pipeline", "team_name": "main"})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
someOtherPath, err = atc.Routes.CreatePathForRoute(atc.PausePipeline, rata.Params{"pipeline_name": "more-awesome-pipeline", "team_name": "main"})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
atcServer.AppendHandlers(
|
||||
ghttp.CombineHandlers(
|
||||
ghttp.VerifyRequest("GET", "/api/v1/teams/main/pipelines"),
|
||||
ghttp.RespondWithJSONEncoded(200, []atc.Pipeline{
|
||||
{Name: "awesome-pipeline", Paused: false, Public: false},
|
||||
{Name: "more-awesome-pipeline", Paused: true, Public: false},
|
||||
}),
|
||||
),
|
||||
ghttp.CombineHandlers(
|
||||
ghttp.VerifyRequest("PUT", somePath),
|
||||
ghttp.RespondWith(http.StatusOK, nil),
|
||||
),
|
||||
ghttp.CombineHandlers(
|
||||
ghttp.VerifyRequest("PUT", someOtherPath),
|
||||
ghttp.RespondWith(http.StatusOK, nil),
|
||||
),
|
||||
)
|
||||
})
|
||||
|
||||
It("pauses every pipeline", func() {
|
||||
Expect(func() {
|
||||
flyCmd := exec.Command(flyPath, "-t", targetName, "pause-pipeline", "--all")
|
||||
|
||||
sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
Eventually(sess).Should(gbytes.Say(`paused 'awesome-pipeline'`))
|
||||
Eventually(sess).Should(gbytes.Say(`paused 'more-awesome-pipeline'`))
|
||||
|
||||
<-sess.Exited
|
||||
Expect(sess.ExitCode()).To(Equal(0))
|
||||
}).To(Change(func() int {
|
||||
return len(atcServer.ReceivedRequests())
|
||||
}).By(4))
|
||||
})
|
||||
|
||||
})
|
||||
})
|
||||
|
|
|
@ -81,7 +81,7 @@ var _ = Describe("Fly CLI", func() {
|
|||
})
|
||||
})
|
||||
|
||||
Context("when the pipline name is not specified", func() {
|
||||
Context("when the pipline name or --all is not specified", func() {
|
||||
It("errors", func() {
|
||||
Expect(func() {
|
||||
flyCmd := exec.Command(flyPath, "-t", targetName, "unpause-pipeline")
|
||||
|
@ -89,7 +89,25 @@ var _ = Describe("Fly CLI", func() {
|
|||
sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
Eventually(sess.Err).Should(gbytes.Say(`was not specified`))
|
||||
Eventually(sess.Err).Should(gbytes.Say(`Either a pipeline name or --all are required`))
|
||||
|
||||
<-sess.Exited
|
||||
Expect(sess.ExitCode()).To(Equal(1))
|
||||
}).To(Change(func() int {
|
||||
return len(atcServer.ReceivedRequests())
|
||||
}).By(0))
|
||||
})
|
||||
})
|
||||
|
||||
Context("when both the pipline name and --all are specified", func() {
|
||||
It("errors", func() {
|
||||
Expect(func() {
|
||||
flyCmd := exec.Command(flyPath, "-t", targetName, "unpause-pipeline", "-p", "awesome-pipeline", "--all")
|
||||
|
||||
sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
Eventually(sess.Err).Should(gbytes.Say(`A pipeline and --all can not both be specified`))
|
||||
|
||||
<-sess.Exited
|
||||
Expect(sess.ExitCode()).To(Equal(1))
|
||||
|
@ -114,4 +132,55 @@ var _ = Describe("Fly CLI", func() {
|
|||
})
|
||||
|
||||
})
|
||||
Context("when the --all flag is passed", func() {
|
||||
var (
|
||||
somePath string
|
||||
someOtherPath string
|
||||
err error
|
||||
)
|
||||
|
||||
BeforeEach(func() {
|
||||
somePath, err = atc.Routes.CreatePathForRoute(atc.UnpausePipeline, rata.Params{"pipeline_name": "awesome-pipeline", "team_name": "main"})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
someOtherPath, err = atc.Routes.CreatePathForRoute(atc.UnpausePipeline, rata.Params{"pipeline_name": "more-awesome-pipeline", "team_name": "main"})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
atcServer.AppendHandlers(
|
||||
ghttp.CombineHandlers(
|
||||
ghttp.VerifyRequest("GET", "/api/v1/teams/main/pipelines"),
|
||||
ghttp.RespondWithJSONEncoded(200, []atc.Pipeline{
|
||||
{Name: "awesome-pipeline", Paused: false, Public: false},
|
||||
{Name: "more-awesome-pipeline", Paused: true, Public: false},
|
||||
}),
|
||||
),
|
||||
ghttp.CombineHandlers(
|
||||
ghttp.VerifyRequest("PUT", somePath),
|
||||
ghttp.RespondWith(http.StatusOK, nil),
|
||||
),
|
||||
ghttp.CombineHandlers(
|
||||
ghttp.VerifyRequest("PUT", someOtherPath),
|
||||
ghttp.RespondWith(http.StatusOK, nil),
|
||||
),
|
||||
)
|
||||
})
|
||||
|
||||
It("unpauses every pipeline", func() {
|
||||
Expect(func() {
|
||||
flyCmd := exec.Command(flyPath, "-t", targetName, "unpause-pipeline", "--all")
|
||||
|
||||
sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
Eventually(sess).Should(gbytes.Say(`unpaused 'awesome-pipeline'`))
|
||||
Eventually(sess).Should(gbytes.Say(`unpaused 'more-awesome-pipeline'`))
|
||||
|
||||
<-sess.Exited
|
||||
Expect(sess.ExitCode()).To(Equal(0))
|
||||
}).To(Change(func() int {
|
||||
return len(atcServer.ReceivedRequests())
|
||||
}).By(4))
|
||||
})
|
||||
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue