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

Enable ArtifactResolver to provide additional help instructions if it cannot find an artifact #47

Merged
merged 2 commits into from
Apr 28, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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