Skip to content

Commit

Permalink
Fix check resource to allow empty results in check
Browse files Browse the repository at this point in the history
Signed-off-by: Benjamin Isinger <Benjamin.Isinger@ibm.com>
  • Loading branch information
HeavyWombat authored and isibeni committed Aug 25, 2023
1 parent e21da4d commit 1efcb98
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
4 changes: 2 additions & 2 deletions internal/dtr/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
package dtr

import (
"fmt"
"io"
)

Expand All @@ -42,7 +41,8 @@ func Check(in io.Reader) (CheckResult, error) {
}

if len(result) == 0 {
return nil, fmt.Errorf("run command returned no output")
// Only return the incoming version to signal concourse that there is nothing new
result = append(result, config.Version)
}

return result, nil
Expand Down
11 changes: 7 additions & 4 deletions internal/dtr/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (

var _ = Describe("Check", func() {
Context("invalid configuration", func() {
It("should fail if not run command is configured", func() {
It("should fail if no run command is configured", func() {
_, err := Check(feed(Config{}))
Expect(err).To(HaveOccurred())
})
Expand All @@ -46,14 +46,17 @@ var _ = Describe("Check", func() {
Expect(err).To(HaveOccurred())
})

It("should fail when no line is return by run", func() {
_, err := Check(feed(Config{
It("should return provided version when no line is return by run", func() {
versionIn := Version{"ref": "barfoo"}
result, err := Check(feed(Config{
Source: Source{
Check: Custom{Run: "true"},
},
Version: versionIn,
}))

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

It("should return two versions when two lines are returned", func() {
Expand Down
12 changes: 9 additions & 3 deletions internal/dtr/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,15 @@ func execute(entry Custom) ([]string, error) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

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.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
Expand Down

0 comments on commit 1efcb98

Please sign in to comment.