From c99a5943aace7448d243f809368c7f4043d1690a Mon Sep 17 00:00:00 2001 From: Alvie Rahman Date: Thu, 29 Jul 2021 07:30:50 +0100 Subject: [PATCH] Only execute if all tests are successful --- main.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 10c13f1..0afef6b 100644 --- a/main.go +++ b/main.go @@ -71,6 +71,16 @@ func webhook(w http.ResponseWriter, r *http.Request) { return } + // Run tests, immediately stop if one fails + for _, test := range service.Tests { + if _, err := exec.Command(test[0], test[1:]...).Output(); err != nil { + writeResponse(w, 409, + fmt.Sprintf("409 Conflict: Test failed: %v", err.Error()), + ) + return + } + } + if stdout, err := exec.Command(service.Script, payload).Output(); err != nil { writeResponse(w, 500, err.Error()) return @@ -96,7 +106,7 @@ type Service struct { Script string Secret string SignatureHeader string - Tests []string + Tests [][]string } type Config struct {