diff --git a/pkg/webservice/handlers_test.go b/pkg/webservice/handlers_test.go index bbff8b79c..c2c6ece01 100644 --- a/pkg/webservice/handlers_test.go +++ b/pkg/webservice/handlers_test.go @@ -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 = ` @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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)