implement check command
This commit is contained in:
@@ -1,7 +1,34 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
|
||||
"github.com/concourse/github-release-resource"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fmt.Println("[]")
|
||||
var request resource.CheckRequest
|
||||
inputRequest(&request)
|
||||
|
||||
github := resource.NewGitHubClient(request.Source)
|
||||
command := resource.NewCheckCommand(github)
|
||||
response, err := command.Run(request)
|
||||
if err != nil {
|
||||
resource.Fatal("running command", err)
|
||||
}
|
||||
|
||||
outputResponse(response)
|
||||
}
|
||||
|
||||
func inputRequest(request *resource.CheckRequest) {
|
||||
if err := json.NewDecoder(os.Stdin).Decode(request); err != nil {
|
||||
resource.Fatal("reading request from stdin", err)
|
||||
}
|
||||
}
|
||||
|
||||
func outputResponse(response []resource.Version) {
|
||||
if err := json.NewEncoder(os.Stdout).Encode(response); err != nil {
|
||||
resource.Fatal("writing response to stdout", err)
|
||||
}
|
||||
}
|
||||
|
@@ -1,27 +0,0 @@
|
||||
package main_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
|
||||
"github.com/onsi/gomega/gexec"
|
||||
)
|
||||
|
||||
var checkPath string
|
||||
|
||||
func TestCheck(t *testing.T) {
|
||||
RegisterFailHandler(Fail)
|
||||
RunSpecs(t, "Check Suite")
|
||||
}
|
||||
|
||||
var _ = BeforeSuite(func() {
|
||||
var err error
|
||||
checkPath, err = gexec.Build("github.com/concourse/github-release-resource/cmd/check")
|
||||
Ω(err).ShouldNot(HaveOccurred())
|
||||
})
|
||||
|
||||
var _ = AfterSuite(func() {
|
||||
gexec.CleanupBuildArtifacts()
|
||||
})
|
@@ -1,23 +0,0 @@
|
||||
package main_test
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
|
||||
"github.com/onsi/gomega/gbytes"
|
||||
"github.com/onsi/gomega/gexec"
|
||||
)
|
||||
|
||||
var _ = Describe("Check", func() {
|
||||
It("outputs an empty JSON array", func() {
|
||||
command := exec.Command(checkPath)
|
||||
|
||||
check, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
|
||||
Ω(err).ShouldNot(HaveOccurred())
|
||||
|
||||
Eventually(check).Should(gbytes.Say(`\[\]`))
|
||||
Eventually(check).Should(gexec.Exit(0))
|
||||
})
|
||||
})
|
Reference in New Issue
Block a user