Skip to content

Commit

Permalink
Use an existing directory instead of creating and deleting directorie…
Browse files Browse the repository at this point in the history
…s for each '--path' flag case to ensure no temp directories are left behind in case of a test failure.

Signed-off-by: Hiroshi Hayakawa <[email protected]>
  • Loading branch information
hhiroshell committed Oct 4, 2024
1 parent 98c32ed commit 3aee96e
Showing 1 changed file with 5 additions and 18 deletions.
23 changes: 5 additions & 18 deletions internal/commands/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -942,26 +942,13 @@ builder = "my-builder"
})

when("a local path with the same string as the specified image name exists", func() {
var dir string

it.Before(func() {
// avoid using paths generated by os.MkdirTemp() as they cause test failures on macOS.
dir = "my-app-dir" + h.RandString(8)
err := os.Mkdir(dir, 0700)
h.AssertNil(t, err)
})

it.After(func() {
h.AssertNil(t, os.RemoveAll(dir))
})

when("an app path is specified", func() {
it("doesn't warn that the positional argument will not be treated as the source path", func() {
mockClient.EXPECT().
Build(gomock.Any(), EqBuildOptionsWithImage("my-builder", dir)).
Build(gomock.Any(), EqBuildOptionsWithImage("my-builder", "testdata")).
Return(nil)

command.SetArgs([]string{dir, "--builder", "my-builder", "--path", "my-source"})
command.SetArgs([]string{"testdata", "--builder", "my-builder", "--path", "my-source"})
h.AssertNil(t, command.Execute())
h.AssertNotContainsMatch(t, outBuf.String(), `Warning: You are building an image named '([^']+)'\. If you mean it as an app directory path, run 'pack build <args> --path ([^']+)'`)
})
Expand All @@ -970,12 +957,12 @@ builder = "my-builder"
when("no app path is specified", func() {
it("warns that the positional argument will not be treated as the source path", func() {
mockClient.EXPECT().
Build(gomock.Any(), EqBuildOptionsWithImage("my-builder", dir)).
Build(gomock.Any(), EqBuildOptionsWithImage("my-builder", "testdata")).
Return(nil)

command.SetArgs([]string{dir, "--builder", "my-builder"})
command.SetArgs([]string{"testdata", "--builder", "my-builder"})
h.AssertNil(t, command.Execute())
h.AssertContains(t, outBuf.String(), "Warning: You are building an image named '"+dir+"'. If you mean it as an app directory path, run 'pack build <args> --path "+dir+"'")
h.AssertContains(t, outBuf.String(), "Warning: You are building an image named 'testdata'. If you mean it as an app directory path, run 'pack build <args> --path testdata'")
})
})
})
Expand Down

0 comments on commit 3aee96e

Please sign in to comment.