Skip to content

Commit

Permalink
Merge pull request #47 from paketo-buildpacks/additional-help-msg
Browse files Browse the repository at this point in the history
Enable ArtifactResolver to provide additional help instructions if it cannot find an artifact
  • Loading branch information
Daniel Mikusa authored Apr 28, 2021
2 parents 2b17f16 + dc62018 commit 5f7b22a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
9 changes: 8 additions & 1 deletion resolvers.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ type ArtifactResolver struct {

// InterestingFileDetector is used to determine if a file is a candidate for artifact resolution.
InterestingFileDetector InterestingFileDetector

// AdditionalHelpMessage can be used to supply context specific instructions if no matching artifact is found
AdditionalHelpMessage string
}

// Pattern returns the glob that ArtifactResolver will use for resolution.
Expand Down Expand Up @@ -153,7 +156,11 @@ func (a *ArtifactResolver) Resolve(applicationPath string) (string, error) {
}

sort.Strings(artifacts)
return "", fmt.Errorf("unable to find single built artifact in %s, candidates: %s", pattern, candidates)
helpMsg := fmt.Sprintf("unable to find single built artifact in %s, candidates: %s", pattern, candidates)
if len(a.AdditionalHelpMessage) > 0 {
helpMsg = fmt.Sprintf("%s. %s", helpMsg, a.AdditionalHelpMessage)
}
return "", fmt.Errorf(helpMsg)
}

// ResolveArguments resolves the arguments that should be passed to a build system.
Expand Down
13 changes: 13 additions & 0 deletions resolvers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,19 @@ func testResolvers(t *testing.T, context spec.G, it spec.S) {
filepath.Join(path, "test-file-1"), filepath.Join(path, "test-file-2"))))
})

it("fails with multiple candidates and provides extra help", func() {
Expect(ioutil.WriteFile(filepath.Join(path, "test-file-1"), []byte{}, 0644)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(path, "test-file-2"), []byte{}, 0644)).To(Succeed())
detector.On("Interesting", mock.Anything).Return(true, nil)

resolver.AdditionalHelpMessage = "Some more help."

_, err := resolver.Resolve(path)

Expect(err).To(MatchError(fmt.Sprintf("unable to find single built artifact in test-*, candidates: [%s %s]. Some more help.",
filepath.Join(path, "test-file-1"), filepath.Join(path, "test-file-2"))))
})

context("$TEST_ARTIFACT_CONFIGURATION_KEY", func() {
it.Before(func() {
Expect(os.Setenv("TEST_ARTIFACT_CONFIGURATION_KEY", "another-file")).To(Succeed())
Expand Down

0 comments on commit 5f7b22a

Please sign in to comment.