From 3b3d22d91e69003fbcea6aaf2e0e7e223211d05c Mon Sep 17 00:00:00 2001 From: Martin Sehnoutka Date: Mon, 9 Mar 2020 12:32:33 +0100 Subject: [PATCH] rcm tests: add get status test This is a very basic test to get the status of a single compose. It will evolve as the API gains support for Koji builds. --- cmd/osbuild-rcm-tests/main.go | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/cmd/osbuild-rcm-tests/main.go b/cmd/osbuild-rcm-tests/main.go index 335108802..5aedfc249 100644 --- a/cmd/osbuild-rcm-tests/main.go +++ b/cmd/osbuild-rcm-tests/main.go @@ -29,16 +29,16 @@ func main() { // Case 1: POST request resp, err := http.Post(socket + endpoint, "application/json", strings.NewReader(submit_body)) + var reply struct { + UUID uuid.UUID `json:"compose_id"` + } if err != nil { - log.Fatal("Failed to submit a compose") + log.Fatal("Failed to submit a compose: ", err.Error()) } if resp.StatusCode != 200 { log.Print("Error: the ", endpoint, " returned non 200 status. Full response: ", resp) failed = true } else { - var reply struct { - UUID uuid.UUID `json:"compose_id"` - } err = json.NewDecoder(resp.Body).Decode(&reply) if err != nil { log.Fatal("Failed to decode JSON response from ", endpoint) @@ -46,6 +46,26 @@ func main() { log.Print("Success: the ", endpoint, " returned compose UUID: ", reply.UUID) } + // Case 2: GET status + + statusEndpoint := endpoint + "/" + reply.UUID.String() + resp, err = http.Get(socket + statusEndpoint) + var status struct { + Status string `json:"status"` + } + if err != nil { + log.Fatal("Failed to get a status: ", err.Error()) + } + if resp.StatusCode != 200 { + log.Print("Error: the ", endpoint, " returned non 200 status. Full response: ", resp) + failed = true + } else { + err = json.NewDecoder(resp.Body).Decode(&status) + if err != nil { + log.Fatal("Failed to decode JSON response from ", endpoint) + } + log.Print("Success: the ", statusEndpoint, " returned status: ", status.Status) + } if failed { os.Exit(1)