Skip to content

Commit

Permalink
[YUNIKORN-2123] Modify json.Unmarshal error message
Browse files Browse the repository at this point in the history
Added a const variable for Unmarshal failure message for the error handling test and substitued occurences of literal strings.
  • Loading branch information
makinyemi committed Nov 7, 2023
1 parent f156917 commit 96a26e9
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions pkg/webservice/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ import (
"github.com/apache/yunikorn-scheduler-interface/lib/go/si"
)

const UnmarshalError = "Failed to unmarshal error response from response body"

const partitionNameWithoutClusterID = "default"
const normalizedPartitionName = "[rm-123]default"
const startConf = `
Expand Down Expand Up @@ -1199,7 +1201,7 @@ func TestGetApplicationHandler(t *testing.T) {
func assertParamsMissing(t *testing.T, resp *MockResponseWriter) {
var errInfo dao.YAPIError
err := json.Unmarshal(resp.outputBytes, &errInfo)
assert.NilError(t, err, "failed to unmarshal DAOInfo response from response body")
assert.NilError(t, err, UnmarshalError)
assert.Equal(t, http.StatusBadRequest, resp.statusCode, "Incorrect Status code")
assert.Equal(t, errInfo.Message, MissingParamsName, "JSON error message is incorrect")
assert.Equal(t, errInfo.StatusCode, http.StatusBadRequest)
Expand All @@ -1208,7 +1210,7 @@ func assertParamsMissing(t *testing.T, resp *MockResponseWriter) {
func assertPartitionExists(t *testing.T, resp *MockResponseWriter) {
var errInfo dao.YAPIError
err := json.Unmarshal(resp.outputBytes, &errInfo)
assert.NilError(t, err, "failed to unmarshal PartitionQueueDAOInfo response from response body")
assert.NilError(t, err, UnmarshalError)
assert.Equal(t, http.StatusBadRequest, resp.statusCode, "Incorrect Status code")
assert.Equal(t, errInfo.Message, PartitionDoesNotExists, "JSON error message is incorrect")
assert.Equal(t, errInfo.StatusCode, http.StatusBadRequest)
Expand All @@ -1217,7 +1219,7 @@ func assertPartitionExists(t *testing.T, resp *MockResponseWriter) {
func assertQueueExists(t *testing.T, resp *MockResponseWriter) {
var errInfo dao.YAPIError
err := json.Unmarshal(resp.outputBytes, &errInfo)
assert.NilError(t, err, "failed to unmarshal ApplicationDAOInfo response from response body")
assert.NilError(t, err, UnmarshalError)
assert.Equal(t, http.StatusBadRequest, resp.statusCode, "Incorrect Status code")
assert.Equal(t, errInfo.Message, QueueDoesNotExists, "JSON error message is incorrect")
assert.Equal(t, errInfo.StatusCode, http.StatusBadRequest)
Expand All @@ -1226,7 +1228,7 @@ func assertQueueExists(t *testing.T, resp *MockResponseWriter) {
func assertApplicationExists(t *testing.T, resp *MockResponseWriter) {
var errInfo dao.YAPIError
err := json.Unmarshal(resp.outputBytes, &errInfo)
assert.NilError(t, err, "failed to unmarshal ApplicationDAOInfo response from response body")
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.StatusCode, http.StatusBadRequest)
Expand All @@ -1235,7 +1237,7 @@ func assertApplicationExists(t *testing.T, resp *MockResponseWriter) {
func assertUserExists(t *testing.T, resp *MockResponseWriter) {
var errInfo dao.YAPIError
err := json.Unmarshal(resp.outputBytes, &errInfo)
assert.NilError(t, err, "failed to unmarshal UserResourceUsageDAOInfo response from response body")
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.StatusCode, http.StatusBadRequest)
Expand All @@ -1244,7 +1246,7 @@ func assertUserExists(t *testing.T, resp *MockResponseWriter) {
func assertUserNameExists(t *testing.T, resp *MockResponseWriter) {
var errInfo dao.YAPIError
err := json.Unmarshal(resp.outputBytes, &errInfo)
assert.NilError(t, err, "failed to unmarshal UserResourceUsageDAOInfo response from response body")
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.StatusCode, http.StatusBadRequest)
Expand All @@ -1253,7 +1255,7 @@ func assertUserNameExists(t *testing.T, resp *MockResponseWriter) {
func assertGroupExists(t *testing.T, resp *MockResponseWriter) {
var errInfo dao.YAPIError
err := json.Unmarshal(resp.outputBytes, &errInfo)
assert.NilError(t, err, "failed to unmarshal GroupResourceUsageDAOInfo response from response body")
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.StatusCode, http.StatusBadRequest)
Expand All @@ -1262,7 +1264,7 @@ func assertGroupExists(t *testing.T, resp *MockResponseWriter) {
func assertGroupNameExists(t *testing.T, resp *MockResponseWriter) {
var errInfo dao.YAPIError
err := json.Unmarshal(resp.outputBytes, &errInfo)
assert.NilError(t, err, "failed to unmarshal GroupResourceUsageDAOInfo response from response body")
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.StatusCode, http.StatusBadRequest)
Expand All @@ -1271,7 +1273,7 @@ func assertGroupNameExists(t *testing.T, resp *MockResponseWriter) {
func assertNodeIDExists(t *testing.T, resp *MockResponseWriter) {
var errInfo dao.YAPIError
err := json.Unmarshal(resp.outputBytes, &errInfo)
assert.NilError(t, err, "failed to unmarshal NodesDAOInfo response from response body")
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.StatusCode, http.StatusBadRequest)
Expand Down

0 comments on commit 96a26e9

Please sign in to comment.