From 31f31fcecebe5e402ce0c220f0be4cdf556ad9ab Mon Sep 17 00:00:00 2001 From: Lou Knauer Date: Mon, 21 Mar 2022 14:21:44 +0100 Subject: [PATCH] Add test: starting the same job twice is bad --- test/api_test.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/api_test.go b/test/api_test.go index b4427f7..3f63bd4 100644 --- a/test/api_test.go +++ b/test/api_test.go @@ -11,6 +11,7 @@ import ( "path/filepath" "reflect" "strconv" + "strings" "testing" "github.com/ClusterCockpit/cc-backend/api" @@ -295,4 +296,18 @@ func TestRestApi(t *testing.T) { t.Fatal("unexpected data fetched from archive") } }) + + t.Run("CheckDoubleStart", func(t *testing.T) { + // Starting a job with the same jobId and cluster should only be allowed if the startTime is far appart! + body := strings.Replace(startJobBody, `"startTime": 123456789`, `"startTime": 123456790`, -1) + + req := httptest.NewRequest(http.MethodPost, "/api/jobs/start_job/", bytes.NewBuffer([]byte(body))) + recorder := httptest.NewRecorder() + + r.ServeHTTP(recorder, req) + response := recorder.Result() + if response.StatusCode != http.StatusUnprocessableEntity { + t.Fatal(response.Status, recorder.Body.String()) + } + }) }