Skip to content

Commit

Permalink
[YUNIKORN-2125] Remove literals from handlers_test.go (apache#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: apache#699

Signed-off-by: Manikandan R <[email protected]>
  • Loading branch information
makinyemi committed Nov 8, 2023
1 parent 96a26e9 commit 9f9de13
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 @@ -1230,7 +1230,7 @@ func assertApplicationExists(t *testing.T, resp *MockResponseWriter) {
err := json.Unmarshal(resp.outputBytes, &errInfo)
assert.NilError(t, err, UnmarshalError)
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 @@ -1239,7 +1239,7 @@ func assertUserExists(t *testing.T, resp *MockResponseWriter) {
err := json.Unmarshal(resp.outputBytes, &errInfo)
assert.NilError(t, err, UnmarshalError)
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 @@ -1248,7 +1248,7 @@ func assertUserNameExists(t *testing.T, resp *MockResponseWriter) {
err := json.Unmarshal(resp.outputBytes, &errInfo)
assert.NilError(t, err, UnmarshalError)
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 @@ -1257,7 +1257,7 @@ func assertGroupExists(t *testing.T, resp *MockResponseWriter) {
err := json.Unmarshal(resp.outputBytes, &errInfo)
assert.NilError(t, err, UnmarshalError)
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 @@ -1266,7 +1266,7 @@ func assertGroupNameExists(t *testing.T, resp *MockResponseWriter) {
err := json.Unmarshal(resp.outputBytes, &errInfo)
assert.NilError(t, err, UnmarshalError)
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 @@ -1275,7 +1275,7 @@ func assertNodeIDExists(t *testing.T, resp *MockResponseWriter) {
err := json.Unmarshal(resp.outputBytes, &errInfo)
assert.NilError(t, err, UnmarshalError)
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 9f9de13

Please sign in to comment.