From 1004607a015028f4622b5691ab5966f54e3409c5 Mon Sep 17 00:00:00 2001 From: Lifosmin Simon Date: Thu, 19 Oct 2023 16:26:37 +0700 Subject: [PATCH] fix: response createdlqjob --- internal/server/v1/dlq/handler.go | 2 +- internal/server/v1/dlq/handler_test.go | 42 +++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/internal/server/v1/dlq/handler.go b/internal/server/v1/dlq/handler.go index 884da97..e6f1dbb 100644 --- a/internal/server/v1/dlq/handler.go +++ b/internal/server/v1/dlq/handler.go @@ -96,7 +96,7 @@ func (h *Handler) createDlqJob(w http.ResponseWriter, r *http.Request) { } // return utils.WriteJSON(w, http.StatusOK, map[string]interface{}{ - "dlq_list": dlqJob.Urn, + "dlq_job": dlqJob, }) } diff --git a/internal/server/v1/dlq/handler_test.go b/internal/server/v1/dlq/handler_test.go index 8fc9f55..7ca586c 100644 --- a/internal/server/v1/dlq/handler_test.go +++ b/internal/server/v1/dlq/handler_test.go @@ -11,6 +11,7 @@ import ( entropyv1beta1 "buf.build/gen/go/gotocompany/proton/protocolbuffers/go/gotocompany/entropy/v1beta1" "github.com/go-chi/chi/v5" + "github.com/go-openapi/strfmt" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" @@ -508,11 +509,50 @@ func TestCreateDlqJob(t *testing.T) { router := getRouter() dlq.Routes(entropyClient, nil, config)(router) router.ServeHTTP(response, request) + // assertions + expectedDlqJob := models.DlqJob{ + // from input + BatchSize: int64(batchSize), + ResourceID: resourceId, + ResourceType: resourceType, + Topic: topic, + Name: fmt.Sprintf( + "%s-%s-%s-%s", + firehoseResource.Name, // firehose title + "firehose", // firehose / dagger + topic, // + date, // + ), + NumThreads: int64(numThreads), + Date: date, + ErrorTypes: errorTypes, + + // firehose resource + ContainerImage: config.DlqJobImage, + DlqGcsCredentialPath: envVars["DLQ_GCS_CREDENTIAL_PATH"], + EnvVars: expectedEnvVars, + Group: "", // + KubeCluster: kubeCluster, + Namespace: namespace, + Project: firehoseResource.Project, + PrometheusHost: config.PrometheusHost, + + // hardcoded + Replicas: 0, + + // job resource + Urn: jobResource.Urn, + Status: jobResource.GetState().GetStatus().String(), + CreatedAt: strfmt.DateTime(jobResource.CreatedAt.AsTime()), + CreatedBy: jobResource.CreatedBy, + UpdatedAt: strfmt.DateTime(jobResource.UpdatedAt.AsTime()), + UpdatedBy: jobResource.UpdatedBy, + } assert.Equal(t, http.StatusOK, response.Code) resultJSON := response.Body.Bytes() expectedJSON, err := json.Marshal(map[string]interface{}{ - "dlq_urn": "test-urn", + "dlq_job": expectedDlqJob, }) require.NoError(t, err) assert.JSONEq(t, string(expectedJSON), string(resultJSON))