Skip to content

Commit

Permalink
[YUNIKORN-2125] Remove literals from handlers_test.go (#699)
Browse files Browse the repository at this point in the history
Some functions error message use string literals while others use constant variables available in the
webservice pacakge. I replaced the hard coded messages with the corresponding constants.

Closes: #699

Signed-off-by: Manikandan R <[email protected]>
  • Loading branch information
makinyemi authored and manirajv06 committed Nov 7, 2023
1 parent ca73344 commit 37e7cd3
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions pkg/webservice/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1228,7 +1228,7 @@ func assertApplicationExists(t *testing.T, resp *MockResponseWriter) {
err := json.Unmarshal(resp.outputBytes, &errInfo)
assert.NilError(t, err, "failed to unmarshal applications dao response from response body")
assert.Equal(t, http.StatusBadRequest, resp.statusCode, "Incorrect Status code")
assert.Equal(t, errInfo.Message, "Application not found", "JSON error message is incorrect")
assert.Equal(t, errInfo.Message, ApplicationDoesNotExists, "JSON error message is incorrect")
assert.Equal(t, errInfo.StatusCode, http.StatusBadRequest)
}

Expand All @@ -1237,7 +1237,7 @@ func assertUserExists(t *testing.T, resp *MockResponseWriter) {
err := json.Unmarshal(resp.outputBytes, &errInfo)
assert.NilError(t, err, "failed to unmarshal applications dao response from response body")
assert.Equal(t, http.StatusBadRequest, resp.statusCode, "Incorrect Status code")
assert.Equal(t, errInfo.Message, "User not found", "JSON error message is incorrect")
assert.Equal(t, errInfo.Message, UserDoesNotExists, "JSON error message is incorrect")
assert.Equal(t, errInfo.StatusCode, http.StatusBadRequest)
}

Expand All @@ -1246,7 +1246,7 @@ func assertUserNameExists(t *testing.T, resp *MockResponseWriter) {
err := json.Unmarshal(resp.outputBytes, &errInfo)
assert.NilError(t, err, "failed to unmarshal applications dao response from response body")
assert.Equal(t, http.StatusBadRequest, resp.statusCode, "Incorrect Status code")
assert.Equal(t, errInfo.Message, "User name is missing", "JSON error message is incorrect")
assert.Equal(t, errInfo.Message, UserNameMissing, "JSON error message is incorrect")
assert.Equal(t, errInfo.StatusCode, http.StatusBadRequest)
}

Expand All @@ -1255,7 +1255,7 @@ func assertGroupExists(t *testing.T, resp *MockResponseWriter) {
err := json.Unmarshal(resp.outputBytes, &errInfo)
assert.NilError(t, err, "failed to unmarshal applications dao response from response body")
assert.Equal(t, http.StatusBadRequest, resp.statusCode, "Incorrect Status code")
assert.Equal(t, errInfo.Message, "Group not found", "JSON error message is incorrect")
assert.Equal(t, errInfo.Message, GroupDoesNotExists, "JSON error message is incorrect")
assert.Equal(t, errInfo.StatusCode, http.StatusBadRequest)
}

Expand All @@ -1264,7 +1264,7 @@ func assertGroupNameExists(t *testing.T, resp *MockResponseWriter) {
err := json.Unmarshal(resp.outputBytes, &errInfo)
assert.NilError(t, err, "failed to unmarshal applications dao response from response body")
assert.Equal(t, http.StatusBadRequest, resp.statusCode, "Incorrect Status code")
assert.Equal(t, errInfo.Message, "Group name is missing", "JSON error message is incorrect")
assert.Equal(t, errInfo.Message, GroupNameMissing, "JSON error message is incorrect")
assert.Equal(t, errInfo.StatusCode, http.StatusBadRequest)
}

Expand All @@ -1273,7 +1273,7 @@ func assertNodeIDExists(t *testing.T, resp *MockResponseWriter) {
err := json.Unmarshal(resp.outputBytes, &errInfo)
assert.NilError(t, err, "failed to unmarshal node dao response from response body")
assert.Equal(t, http.StatusBadRequest, resp.statusCode, "Incorrect Status code")
assert.Equal(t, errInfo.Message, "Node not found", "JSON error message is incorrect")
assert.Equal(t, errInfo.Message, NodeDoesNotExists, "JSON error message is incorrect")
assert.Equal(t, errInfo.StatusCode, http.StatusBadRequest)
}

Expand Down

0 comments on commit 37e7cd3

Please sign in to comment.