Skip to content

Commit

Permalink
test(HMS-4622): align to error response
Browse files Browse the repository at this point in the history
This change align the smoke tests to properly process
the error response body.

https://issues.redhat.com/browse/HMS-4622

Signed-off-by: Alejandro Visiedo <[email protected]>
  • Loading branch information
avisiedo committed Sep 19, 2024
1 parent a02d96d commit 89f7c98
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
16 changes: 12 additions & 4 deletions internal/test/smoke/domain_update_system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,12 @@ func (s *SuiteDomainUpdateAgent) TestUpdateDomain() {
},
Expected: TestCaseExpect{
StatusCode: http.StatusBadRequest,
BodyFunc: WrapBodyFuncErrorResponse(func(t *testing.T, body *ErrorResponse) error {
assert.Equal(t, "'domain_name' may not be changed", body.Message)
BodyFunc: WrapBodyFuncErrorResponse(func(t *testing.T, body *public.ErrorResponse) error {
assert.Equal(t, builder_api.NewErrorResponse().
Add(*builder_api.NewErrorInfo(http.StatusBadRequest).
WithTitle("'domain_name' may not be changed").
Build()).
Build(), body)
return nil
}),
},
Expand All @@ -119,8 +123,12 @@ func (s *SuiteDomainUpdateAgent) TestUpdateDomain() {
},
Expected: TestCaseExpect{
StatusCode: http.StatusBadRequest,
BodyFunc: WrapBodyFuncErrorResponse(func(t *testing.T, body *ErrorResponse) error {
assert.Equal(t, "'realm_name' may not be changed", body.Message)
BodyFunc: WrapBodyFuncErrorResponse(func(t *testing.T, body *public.ErrorResponse) error {
assert.Equal(t, builder_api.NewErrorResponse().
Add(*builder_api.NewErrorInfo(http.StatusBadRequest).
WithTitle("'realm_name' may not be changed").
Build()).
Build(), body)
return nil
}),
},
Expand Down
13 changes: 2 additions & 11 deletions internal/test/smoke/suite_base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -870,16 +870,7 @@ func TestSuite(t *testing.T) {
suite.Run(t, new(SuiteSystemEndpoints))
}

// ErrorResponse represents the error response from the API
//
// Note: the structure is different than the public.ErrorResponse
// as the API doesn't actually return a public.ErrorResponse which it should.
type ErrorResponse struct {
Error string `json:"error"`
Message string `json:"message"`
}

type BodyFuncErrorResponse func(t *testing.T, body *ErrorResponse) error
type BodyFuncErrorResponse func(t *testing.T, body *public.ErrorResponse) error

func WrapBodyFuncErrorResponse(predicate BodyFuncErrorResponse) BodyFunc {
if predicate == nil {
Expand All @@ -888,7 +879,7 @@ func WrapBodyFuncErrorResponse(predicate BodyFuncErrorResponse) BodyFunc {
}
}
return func(t *testing.T, body []byte) bool {
var data ErrorResponse
var data public.ErrorResponse
if err := json.Unmarshal(body, &data); err != nil {
require.Fail(t, fmt.Errorf("Error unmarshalling body: %w", err).Error())
return false
Expand Down

0 comments on commit 89f7c98

Please sign in to comment.