Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display error when --path is invalid #161

Merged
merged 1 commit into from Apr 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions build.go
Expand Up @@ -123,6 +123,16 @@ func (bf *BuildFactory) BuildConfigFromFlags(ctx context.Context, f *BuildFlags)
if err != nil {
return nil, err
}
stat, err := os.Stat(appDir)
if err != nil {
if os.IsNotExist(err) {
return nil, errors.Errorf("app directory %s does not exist", style.Symbol(appDir))
} else {
return nil, err
}
} else if !stat.IsDir() {
return nil, errors.Errorf("provided app directory %s is not a directory", style.Symbol(appDir))
}

f.RepoName = calculateRepositoryName(appDir, f)

Expand Down
36 changes: 36 additions & 0 deletions build_test.go
Expand Up @@ -7,6 +7,7 @@ import (
"io/ioutil"
"math/rand"
"os"
"path/filepath"
"testing"
"time"

Expand Down Expand Up @@ -368,5 +369,40 @@ PATH
})
h.AssertNotEq(t, os.Getenv("PATH"), "")
})

when("app path is invalid", func() {
when("app directory does not exist", func() {
it("return error", func() {
appDir := filepath.Join("testdata", "does-not-exist")

config, err := factory.BuildConfigFromFlags(context.TODO(), &pack.BuildFlags{
RepoName: "some/app",
Builder: "some/builder",
AppDir: appDir,
})

h.AssertNil(t, config)
h.AssertNotNil(t, err)
h.AssertContainsMatch(t, err.Error(), "^app directory .*does-not-exist.* does not exist$")
})
})

when("app directory is a file", func() {
it("return error", func() {
appDir := filepath.Join("testdata", "just-a-file.txt")

config, err := factory.BuildConfigFromFlags(context.TODO(), &pack.BuildFlags{
RepoName: "some/app",
Builder: "some/builder",
AppDir: appDir,
})

h.AssertNil(t, config)
h.AssertNotNil(t, err)

h.AssertContainsMatch(t, err.Error(), "^provided app directory .*just-a-file.txt.* is not a directory$")
})
})
})
}, spec.Parallel())
}
4 changes: 2 additions & 2 deletions run_test.go
Expand Up @@ -81,15 +81,15 @@ func testRun(t *testing.T, when spec.G, it spec.S) {

run, err := factory.RunConfigFromFlags(context.TODO(), &pack.RunFlags{
BuildFlags: pack.BuildFlags{
AppDir: "acceptance/testdata/node_app",
AppDir: "testdata/some-app",
Builder: "some/builder",
RunImage: "some/run",
},
Ports: []string{"1370"},
})
h.AssertNil(t, err)

absAppDir, _ := filepath.Abs("acceptance/testdata/node_app")
absAppDir, _ := filepath.Abs("testdata/some-app")
absAppDirMd5 := fmt.Sprintf("pack.local/run/%x", md5.Sum([]byte(absAppDir)))
h.AssertEq(t, run.RepoName, absAppDirMd5)
h.AssertEq(t, run.Ports, []string{"1370"})
Expand Down
Empty file added testdata/just-a-file.txt
Empty file.
1 change: 1 addition & 0 deletions testdata/some-app/.gitignore
@@ -0,0 +1 @@
!.gitignore