Skip to content
This repository has been archived by the owner on Oct 25, 2023. It is now read-only.

Commit

Permalink
test: add error testing for create dlq job
Browse files Browse the repository at this point in the history
  • Loading branch information
Lifosmin Simon authored and Lifosmin Simon committed Oct 23, 2023
1 parent d8a0024 commit c599042
Showing 1 changed file with 63 additions and 5 deletions.
68 changes: 63 additions & 5 deletions internal/server/v1/dlq/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ func TestListDlqJob(t *testing.T) {
group = "test-group"
)
t.Run("Should return error firehose not found because labels", func(t *testing.T) {
// initt input
path := fmt.Sprintf("/jobs?resource_id=%s&resource_type=%s&date=%s", "test-resource-id2", resourceType, date)
expectedLabels := map[string]string{
"resource_id": "test-resource-id2",
Expand All @@ -247,7 +246,6 @@ func TestListDlqJob(t *testing.T) {
})

t.Run("Should return error in firehose mapping", func(t *testing.T) {
// initt input
path := fmt.Sprintf("/jobs?resource_id=")

Check failure on line 249 in internal/server/v1/dlq/handler_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

S1039: unnecessary use of fmt.Sprintf (gosimple)

Check failure on line 249 in internal/server/v1/dlq/handler_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

S1039: unnecessary use of fmt.Sprintf (gosimple)
expectedErr := status.Error(codes.Internal, "Not found")
expectedLabels := map[string]string{}
Expand Down Expand Up @@ -548,8 +546,70 @@ func TestCreateDlqJob(t *testing.T) {
}`, resourceID, resourceType, errorTypes, batchSize, numThreads, topic, date, group)
)

t.Run("Should return error user header is required", func(t *testing.T) {

Check failure on line 549 in internal/server/v1/dlq/handler_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

unnecessary leading newline (whitespace)

Check failure on line 549 in internal/server/v1/dlq/handler_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

unnecessary leading newline (whitespace)

requestBody := bytes.NewReader([]byte(jsonPayload))

response := httptest.NewRecorder()
request := httptest.NewRequest(method, path, requestBody)
router := getRouter()
dlq.Routes(nil, nil, dlq.DlqJobConfig{})(router)
router.ServeHTTP(response, request)

assert.Equal(t, http.StatusUnauthorized, response.Code)
})

t.Run("Should return error validation resource type not firehose", func(t *testing.T) {
jsonBody := `{
"resource_id": "test-resource-id",
"resource_type": "dlq",
"error_types": "test-error",
"batch_size": 1,
"num_threads": 2,
"topic": "test-topic",
"date": "2022-10-21",
"group": "test-group"
}`
userEmail := "[email protected]"

requestBody := bytes.NewReader([]byte(jsonBody))

response := httptest.NewRecorder()
request := httptest.NewRequest(method, path, requestBody)
request.Header.Set(emailHeaderKey, userEmail)
router := getRouter()
dlq.Routes(nil, nil, dlq.DlqJobConfig{})(router)
router.ServeHTTP(response, request)

assert.Equal(t, http.StatusBadRequest, response.Code)
})

t.Run("Should return error validation missing required fields", func(t *testing.T) {
jsonBody := `{
"resource_id": "",
"resource_type": "firehose",
"error_types": "test-error",
"batch_size": 1,
"num_threads": 2,
"topic": "test-topic",
"date": "2022-10-21",
"group": "test-group"
}`
userEmail := "[email protected]"

requestBody := bytes.NewReader([]byte(jsonBody))

response := httptest.NewRecorder()
request := httptest.NewRequest(method, path, requestBody)
request.Header.Set(emailHeaderKey, userEmail)
router := getRouter()
dlq.Routes(nil, nil, dlq.DlqJobConfig{})(router)
router.ServeHTTP(response, request)

assert.Equal(t, http.StatusBadRequest, response.Code)
})

t.Run("Should return error firehose not Found", func(t *testing.T) {
// initt input
expectedErr := status.Error(codes.NotFound, "Not found")
entropyClient := new(mocks.ResourceServiceClient)
entropyClient.On(
Expand All @@ -569,7 +629,6 @@ func TestCreateDlqJob(t *testing.T) {
})

t.Run("Should return error in firehose mapping", func(t *testing.T) {
// initt input
expectedErr := status.Error(codes.Internal, "Not found")
entropyClient := new(mocks.ResourceServiceClient)
entropyClient.On(
Expand All @@ -589,7 +648,6 @@ func TestCreateDlqJob(t *testing.T) {
})

t.Run("Should return resource urn", func(t *testing.T) {
// initt input
namespace := "test-namespace"
kubeCluster := "test-kube-cluster"
userEmail := "[email protected]"
Expand Down

0 comments on commit c599042

Please sign in to comment.