Skip to content

Commit

Permalink
fly: add --team flag to hide-pipeline
Browse files Browse the repository at this point in the history
concourse#5215

Signed-off-by: Owen Farrell <[email protected]>
  • Loading branch information
owenfarrell committed Jul 28, 2020
1 parent cbdc7e0 commit 0c5d929
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 3 deletions.
16 changes: 14 additions & 2 deletions fly/commands/hide_pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import (
"github.com/concourse/concourse/fly/commands/internal/displayhelpers"
"github.com/concourse/concourse/fly/commands/internal/flaghelpers"
"github.com/concourse/concourse/fly/rc"
"github.com/concourse/concourse/go-concourse/concourse"
)

type HidePipelineCommand struct {
Pipeline flaghelpers.PipelineFlag `short:"p" long:"pipeline" required:"true" description:"Pipeline to hide"`
Pipeline flaghelpers.PipelineFlag `short:"p" long:"pipeline" required:"true" description:"Pipeline to hide"`
Team string `long:"team" description:"Name of the team to which the pipeline belongs, if different from the target default"`
}

func (command *HidePipelineCommand) Validate() error {
Expand All @@ -35,7 +37,17 @@ func (command *HidePipelineCommand) Execute(args []string) error {
return err
}

found, err := target.Team().HidePipeline(pipelineName)
var team concourse.Team
if command.Team != "" {
team, err = target.FindTeam(command.Team)
if err != nil {
return err
}
} else {
team = target.Team()
}

found, err := team.HidePipeline(pipelineName)
if err != nil {
return err
}
Expand Down
4 changes: 4 additions & 0 deletions fly/integration/error_handling_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ var _ = Describe("Fly CLI", func() {
},
Entry("trigger-job command returns an error",
exec.Command(flyPath, "-t", targetName, "trigger-job", "-j", "pipeline/job", "--team", "doesnotexist")),
Entry("hide-pipeline command returns an error",
exec.Command(flyPath, "-t", targetName, "hide-pipeline", "-p", "pipeline", "--team", "doesnotexist")),
Entry("hijack command returns an error",
exec.Command(flyPath, "-t", targetName, "hijack", "--handle", "container-id", "--team", "doesnotexist")),
Entry("jobs command returns an error",
Expand Down Expand Up @@ -138,6 +140,8 @@ var _ = Describe("Fly CLI", func() {
},
Entry("trigger-job command returns an error",
exec.Command(flyPath, "-t", targetName, "trigger-job", "-j", "pipeline/job", "--team", "other-team")),
Entry("hide-pipeline command returns an error",
exec.Command(flyPath, "-t", targetName, "hide-pipeline", "-p", "pipeline", "--team", "other-team")),
Entry("hijack command returns an error",
exec.Command(flyPath, "-t", targetName, "hijack", "--handle", "container-id", "--team", "other-team")),
Entry("jobs command returns an error",
Expand Down
80 changes: 79 additions & 1 deletion fly/integration/hide_pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var _ = Describe("Fly CLI", func() {
err error
)
BeforeEach(func() {
path, err = atc.Routes.CreatePathForRoute(atc.HidePipeline, rata.Params{"pipeline_name": "awesome-pipeline", "team_name": "main"})
path, err = atc.Routes.CreatePathForRoute(atc.HidePipeline, rata.Params{"pipeline_name": "awesome-pipeline", "team_name": teamName})
Expect(err).NotTo(HaveOccurred())
})

Expand Down Expand Up @@ -81,6 +81,84 @@ var _ = Describe("Fly CLI", func() {
})
})

Context("when both the team and pipeline name are specified", func() {
teamName := "other-team"
var (
path string
err error
)
BeforeEach(func() {
path, err = atc.Routes.CreatePathForRoute(atc.HidePipeline, rata.Params{"pipeline_name": "awesome-pipeline", "team_name": teamName})
Expect(err).NotTo(HaveOccurred())
})

Context("when the pipeline exists", func() {
BeforeEach(func() {
atcServer.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/api/v1/teams/"+teamName),
ghttp.RespondWithJSONEncoded(http.StatusOK, atc.Team{
Name: teamName,
}),
),
ghttp.CombineHandlers(
ghttp.VerifyRequest("PUT", path),
ghttp.RespondWith(http.StatusOK, nil),
),
)
})

It("hides the pipeline", func() {
Expect(func() {
flyCmd := exec.Command(flyPath, "-t", targetName, "hide-pipeline", "--team", teamName, "-p", "awesome-pipeline")

sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter)
Expect(err).NotTo(HaveOccurred())

Eventually(sess).Should(gbytes.Say(`hid 'awesome-pipeline'`))

<-sess.Exited
Expect(sess.ExitCode()).To(Equal(0))
}).To(Change(func() int {
return len(atcServer.ReceivedRequests())
}).By(3))
})
})

Context("when the pipeline doesn't exist", func() {
BeforeEach(func() {
atcServer.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/api/v1/teams/"+teamName),
ghttp.RespondWithJSONEncoded(http.StatusOK, atc.Team{
Name: teamName,
}),
),
ghttp.CombineHandlers(
ghttp.VerifyRequest("PUT", path),
ghttp.RespondWith(http.StatusNotFound, nil),
),
)
})

It("prints helpful message", func() {
Expect(func() {
flyCmd := exec.Command(flyPath, "-t", targetName, "hide-pipeline", "--team", teamName, "-p", "awesome-pipeline")

sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter)
Expect(err).NotTo(HaveOccurred())

Eventually(sess.Err).Should(gbytes.Say(`pipeline 'awesome-pipeline' not found`))

<-sess.Exited
Expect(sess.ExitCode()).To(Equal(1))
}).To(Change(func() int {
return len(atcServer.ReceivedRequests())
}).By(3))
})
})
})

Context("when the pipline name is not specified", func() {
It("errors", func() {
Expect(func() {
Expand Down

0 comments on commit 0c5d929

Please sign in to comment.