Skip to content

Commit

Permalink
Merge pull request #32 from isibeni/fix-check-resource
Browse files Browse the repository at this point in the history
Fix check run in case no version was provided
  • Loading branch information
HeavyWombat authored Aug 25, 2023
2 parents f80246c + cfa744f commit 6c4b9f9
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
9 changes: 7 additions & 2 deletions internal/dtr/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,13 @@ func Check(in io.Reader) (CheckResult, error) {
}

if len(result) == 0 {
// Only return the incoming version to signal concourse that there is nothing new
result = append(result, config.Version)
if config.Version != nil {
// Only return the incoming version to signal concourse that there is nothing new
result = append(result, config.Version)
} else {
// Return empty result as we don't have anything
result = CheckResult{}
}
}

return result, nil
Expand Down
23 changes: 23 additions & 0 deletions internal/dtr/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,17 @@ var _ = Describe("Check", func() {
Expect(result).To(Equal(CheckResult{versionIn}))
})

It("should return empty result when no version is provided", func() {
result, err := Check(feed(Config{
Source: Source{
Check: Custom{Run: "true"},
},
}))

Expect(err).ToNot(HaveOccurred())
Expect(result).To(Equal(CheckResult{}))
})

It("should return two versions when two lines are returned", func() {
result, err := Check(feed(Config{
Source: Source{
Expand All @@ -73,6 +84,18 @@ var _ = Describe("Check", func() {
}))
})

It("should just fail nicely if the run command was not provided", func() {
_, err := Check(feed(Config{
Source: Source{
Check: Custom{
Run: "",
},
},
}))

Expect(err).To(HaveOccurred())
})

It("should run before commands before returning a version", func() {
result, err := Check(feed(Config{
Source: Source{
Expand Down
8 changes: 4 additions & 4 deletions internal/dtr/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,17 +104,17 @@ func execute(entry Custom) ([]string, error) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

if entry.Run == "" {
return nil, fmt.Errorf("run command not specified. Bailing out")
}

if entry.Before != "" {
before := command(ctx, entry.Env, entry.Before, os.Stderr)
if err := before.Run(); err != nil {
return nil, fmt.Errorf("failure while running before command: %w", err)
}
}

if entry.Run == "" {
return nil, fmt.Errorf("run command not specified. Bailing out")
}

var outStream bytes.Buffer
run := command(ctx, entry.Env, entry.Run, &outStream)
if err := run.Run(); err != nil {
Expand Down

0 comments on commit 6c4b9f9

Please sign in to comment.