From 7066e525f3cad9bbde4a3f837505b245e548e986 Mon Sep 17 00:00:00 2001 From: Hiroshi Hayakawa Date: Thu, 5 Sep 2024 20:08:52 +0900 Subject: [PATCH] Add a test case for when the 'pack build' is called with the '--path' flag. Signed-off-by: Hiroshi Hayakawa --- internal/commands/build_test.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/internal/commands/build_test.go b/internal/commands/build_test.go index 06cf50a06..ca0e3fb63 100644 --- a/internal/commands/build_test.go +++ b/internal/commands/build_test.go @@ -931,6 +931,19 @@ builder = "my-builder" }) }) + when("path to app dir or zip-formatted file is provided", func() { + it("builds with the specified path"+ + "and doesn't warn that the positional argument will not be treated as the source path", func() { + mockClient.EXPECT(). + Build(gomock.Any(), EqBuildOptionsWithPath("my-source")). + Return(nil) + + command.SetArgs([]string{"image", "--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 --path ([^']+)'`) + }) + }) + when("export to OCI layout is expected but experimental isn't set in the config", func() { it("errors with a descriptive message", func() { command.SetArgs([]string{"oci:image", "--builder", "my-builder"}) @@ -1178,6 +1191,15 @@ func EqBuildOptionsWithDateTime(t *time.Time) interface{} { } } +func EqBuildOptionsWithPath(path string) interface{} { + return buildOptionsMatcher{ + description: fmt.Sprintf("AppPath=%s", path), + equals: func(o client.BuildOptions) bool { + return o.AppPath == path + }, + } +} + func EqBuildOptionsWithLayoutConfig(image, previousImage string, sparse bool, layoutDir string) interface{} { return buildOptionsMatcher{ description: fmt.Sprintf("image=%s, previous-image=%s, sparse=%t, layout-dir=%s", image, previousImage, sparse, layoutDir),