From fd33ea1cc70fca32bcae6be7132fe03579c57339 Mon Sep 17 00:00:00 2001 From: Tom Gundersen Date: Thu, 24 Oct 2019 14:57:56 +0200 Subject: [PATCH] weldr/tests: add first version of a compose/queue test This can serve as a starting point, but it shows there are a few problems to solve: we need to verify json that depends on the setup, in particular, the json the queue contains will contain UUID's that are generated out of our control. Moreover, the setup for this test only makes sense for internal test, so I think we may want to change the logic for whether or not a test sholud be supported to be run externally to be per test-function, rather than per call to sendHTTP(). Signed-off-by: Tom Gundersen --- internal/weldr/api_test.go | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/internal/weldr/api_test.go b/internal/weldr/api_test.go index 240740eb0..783a736b8 100644 --- a/internal/weldr/api_test.go +++ b/internal/weldr/api_test.go @@ -285,3 +285,40 @@ func TestCompose(t *testing.T) { sendHTTP(api, c.External, "DELETE", "/api/v0/blueprints/delete/test", ``) } } + +func TestComposeQueue(t *testing.T) { + var cases = []struct { + Method string + Path string + Body string + ExpectedStatus int + ExpectedJSON string + }{ + {"GET", "/api/v0/compose/queue", ``, http.StatusOK, `*`}, // TODO: we need a way to verify we actually get the expected json here + } + + if len(os.Getenv("OSBUILD_COMPOSER_TEST_EXTERNAL")) > 0 { + t.Skip("This test is for internal testing only") + } + + for _, c := range cases { + s := store.New(nil) + api := weldr.New(repo, packages, nil, s) + sendHTTP(api, false, "POST", "/api/v0/blueprints/new", `{"name":"test","description":"Test","packages":[{"name":"httpd","version":"2.4.*"}],"version":"0.0.0"}`) + // create job and leave it waiting + sendHTTP(api, false, "POST", "/api/v0/compose", `{"blueprint_name": "test","compose_type": "tar","branch": "master"}`) + // create job and leave it running + sendHTTP(api, false, "POST", "/api/v0/compose", `{"blueprint_name": "test","compose_type": "tar","branch": "master"}`) + s.PopCompose() + // create job and mark it as finished + sendHTTP(api, false, "POST", "/api/v0/compose", `{"blueprint_name": "test","compose_type": "tar","branch": "master"}`) + job := s.PopCompose() + s.UpdateCompose(job.ComposeID, "FINISHED") + // create job and mark it as failed + sendHTTP(api, false, "POST", "/api/v0/compose", `{"blueprint_name": "test","compose_type": "tar","branch": "master"}`) + job = s.PopCompose() + s.UpdateCompose(job.ComposeID, "FAILED") + testRoute(t, api, false, c.Method, c.Path, c.Body, c.ExpectedStatus, c.ExpectedJSON) + sendHTTP(api, false, "DELETE", "/api/v0/blueprints/delete/test", ``) + } +}