Skip to content

Commit 52c0057

Browse files
emily.johnsonsophiewigmore
emily.johnson
authored andcommitted
Require output flag for pack
1 parent 6f288e8 commit 52c0057

File tree

3 files changed

+82
-10
lines changed

3 files changed

+82
-10
lines changed

cargo/jam/commands/pack.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ type packFlags struct {
2222
}
2323

2424
func pack() *cobra.Command {
25-
flags :=&packFlags{}
25+
flags := &packFlags{}
2626
cmd := &cobra.Command{
2727
Use: "pack",
2828
Short: "package buildpack",
@@ -40,6 +40,10 @@ func pack() *cobra.Command {
4040
if err != nil {
4141
fmt.Fprintf(os.Stderr, "Unable to mark buildpack flag as required")
4242
}
43+
err = cmd.MarkFlagRequired("output")
44+
if err != nil {
45+
fmt.Fprintf(os.Stderr, "Unable to mark output flag as required")
46+
}
4347
err = cmd.MarkFlagRequired("version")
4448
if err != nil {
4549
fmt.Fprintf(os.Stderr, "Unable to mark version flag as required")

cargo/jam/pack_test.go

+61-9
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ func testPack(t *testing.T, context spec.G, it spec.S) {
4646
Expect(os.RemoveAll(tmpDir)).To(Succeed())
4747
Expect(os.RemoveAll(buildpackDir)).To(Succeed())
4848
})
49+
4950
context("when packaging a language family buildpack", func() {
5051

5152
it.Before(func() {
@@ -331,17 +332,68 @@ func testPack(t *testing.T, context spec.G, it spec.S) {
331332
Expect(hdr.Mode).To(Equal(int64(0644)))
332333
})
333334
})
335+
})
336+
337+
context("failure cases", func() {
338+
context("when the all the required flags are not set", func() {
339+
it("prints an error message", func() {
340+
command := exec.Command(path, "pack")
341+
session, err := gexec.Start(command, buffer, buffer)
342+
Expect(err).NotTo(HaveOccurred())
343+
Eventually(session).Should(gexec.Exit(1), func() string { return buffer.String() })
344+
345+
Expect(session.Err.Contents()).To(ContainSubstring("Error: required flag(s) \"buildpack\", \"output\", \"version\" not set"))
346+
})
347+
})
348+
349+
context("when the required buildpack flag is not set", func() {
350+
it("prints an error message", func() {
351+
command := exec.Command(
352+
path, "pack",
353+
"--output", filepath.Join(tmpDir, "output.tgz"),
354+
"--version", "some-version",
355+
"--offline",
356+
"--stack", "io.buildpacks.stacks.bionic",
357+
)
358+
session, err := gexec.Start(command, buffer, buffer)
359+
Expect(err).NotTo(HaveOccurred())
360+
Eventually(session).Should(gexec.Exit(1), func() string { return buffer.String() })
361+
362+
Expect(session.Err.Contents()).To(ContainSubstring("Error: required flag(s) \"buildpack\" not set"))
363+
})
364+
})
334365

335-
context("failure cases", func() {
336-
context("when the --buildpack flag is empty", func() {
337-
it("prints an error message", func() {
338-
command := exec.Command(path, "pack")
339-
session, err := gexec.Start(command, buffer, buffer)
340-
Expect(err).NotTo(HaveOccurred())
341-
Eventually(session).Should(gexec.Exit(1), func() string { return buffer.String() })
366+
context("when the required output flag is not set", func() {
367+
it("prints an error message", func() {
368+
command := exec.Command(
369+
path, "pack",
370+
"--buildpack", filepath.Join(buildpackDir, "buildpack.toml"),
371+
"--version", "some-version",
372+
"--offline",
373+
"--stack", "io.buildpacks.stacks.bionic",
374+
)
375+
session, err := gexec.Start(command, buffer, buffer)
376+
Expect(err).NotTo(HaveOccurred())
377+
Eventually(session).Should(gexec.Exit(1), func() string { return buffer.String() })
378+
379+
Expect(session.Err.Contents()).To(ContainSubstring("Error: required flag(s) \"output\" not set"))
380+
})
381+
})
382+
383+
context("when the required version flag is not set", func() {
384+
it("prints an error message", func() {
385+
command := exec.Command(
386+
path, "pack",
387+
"--buildpack", filepath.Join(buildpackDir, "buildpack.toml"),
388+
"--output", filepath.Join(tmpDir, "output.tgz"),
389+
"--offline",
390+
"--stack", "io.buildpacks.stacks.bionic",
391+
)
392+
session, err := gexec.Start(command, buffer, buffer)
393+
Expect(err).NotTo(HaveOccurred())
394+
Eventually(session).Should(gexec.Exit(1), func() string { return buffer.String() })
342395

343-
Expect(session.Err.Contents()).To(ContainSubstring("Error: required flag(s) \"buildpack\", \"version\" not set"))
344-
})
396+
Expect(session.Err.Contents()).To(ContainSubstring("Error: required flag(s) \"version\" not set"))
345397
})
346398
})
347399
})

cargo/jam/summarize_test.go

+16
Original file line numberDiff line numberDiff line change
@@ -431,4 +431,20 @@ version = "3.4.5"
431431
}`))
432432
})
433433
})
434+
435+
context.Focus("failure cases", func() {
436+
context("when the required buildpack flag is not set", func() {
437+
it("prints an error message", func() {
438+
command := exec.Command(
439+
path, "summarize",
440+
"--format", "markdown",
441+
)
442+
session, err := gexec.Start(command, buffer, buffer)
443+
Expect(err).NotTo(HaveOccurred())
444+
Eventually(session).Should(gexec.Exit(1), func() string { return buffer.String() })
445+
446+
Expect(session.Err.Contents()).To(ContainSubstring("Error: required flag(s) \"buildpack\" not set"))
447+
})
448+
})
449+
})
434450
}

0 commit comments

Comments
 (0)