This is an automated email from the ASF dual-hosted git repository.
pbacsko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/yunikorn-core.git
The following commit(s) were added to refs/heads/master by this push:
new af917169 [YUNIKORN-2123] Modify json.Unmarshal error message (#698)
af917169 is described below
commit af9171694f802fbc03b9a02329adae82bb0aee06
Author: Michael Akinyemi <[email protected]>
AuthorDate: Mon Nov 13 17:15:17 2023 +0100
[YUNIKORN-2123] Modify json.Unmarshal error message (#698)
Closes: #698
Signed-off-by: Peter Bacsko <[email protected]>
---
pkg/webservice/handlers_test.go | 110 +++++++++++++++++++++-------------------
1 file changed, 57 insertions(+), 53 deletions(-)
diff --git a/pkg/webservice/handlers_test.go b/pkg/webservice/handlers_test.go
index b88117ff..91827442 100644
--- a/pkg/webservice/handlers_test.go
+++ b/pkg/webservice/handlers_test.go
@@ -48,6 +48,10 @@ import (
"github.com/apache/yunikorn-scheduler-interface/lib/go/si"
)
+const unmarshalError = "Failed to unmarshal error response from response body"
+const statusCodeError = "Incorrect Status code"
+const jsonMessageError = "JSON error message is incorrect"
+
const partitionNameWithoutClusterID = "default"
const normalizedPartitionName = "[rm-123]default"
const startConf = `
@@ -321,7 +325,7 @@ func TestValidateConf(t *testing.T) {
validateConf(resp, req)
var vcr dao.ValidateConfResponse
err := json.Unmarshal(resp.outputBytes, &vcr)
- assert.NilError(t, err, "failed to unmarshal
ValidateConfResponse from response body")
+ assert.NilError(t, err, unmarshalError)
assert.Equal(t, vcr.Allowed, test.expectedResponse.Allowed,
"allowed flag incorrect")
assert.Equal(t, vcr.Reason, test.expectedResponse.Reason,
"response text not as expected")
}
@@ -362,7 +366,7 @@ func TestUserGroupLimits(t *testing.T) {
validateConf(resp, req)
var vcr dao.ValidateConfResponse
err := json.Unmarshal(resp.outputBytes, &vcr)
- assert.NilError(t, err, "failed to unmarshal
ValidateConfResponse from response body")
+ assert.NilError(t, err, unmarshalError)
assert.Equal(t, vcr.Allowed, test.expectedResponse.Allowed,
"allowed flag incorrect")
assert.Equal(t, vcr.Reason, test.expectedResponse.Reason,
"response text not as expected")
}
@@ -380,9 +384,9 @@ func TestApplicationHistory(t *testing.T) {
var errInfo dao.YAPIError
err := json.Unmarshal(resp.outputBytes, &errInfo)
- assert.NilError(t, err, "failed to unmarshal app history response from
response body: %s", string(resp.outputBytes))
+ assert.NilError(t, err, unmarshalError)
assert.Equal(t, http.StatusNotImplemented, resp.statusCode, "app
history handler returned wrong status")
- assert.Equal(t, errInfo.Message, "Internal metrics collection is not
enabled.", "JSON error message is incorrect")
+ assert.Equal(t, errInfo.Message, "Internal metrics collection is not
enabled.", jsonMessageError)
assert.Equal(t, errInfo.StatusCode, http.StatusNotImplemented)
// init should return null and thus no records
@@ -391,7 +395,7 @@ func TestApplicationHistory(t *testing.T) {
getApplicationHistory(resp, req)
var appHist []dao.ApplicationHistoryDAOInfo
err = json.Unmarshal(resp.outputBytes, &appHist)
- assert.NilError(t, err, "failed to unmarshal app history response from
response body: %s", string(resp.outputBytes))
+ assert.NilError(t, err, unmarshalError)
assert.Equal(t, resp.statusCode, 0, "app response should have no
status")
assert.Equal(t, len(appHist), 0, "empty response must have no records")
@@ -402,7 +406,7 @@ func TestApplicationHistory(t *testing.T) {
resp = &MockResponseWriter{}
getApplicationHistory(resp, req)
err = json.Unmarshal(resp.outputBytes, &appHist)
- assert.NilError(t, err, "failed to unmarshal app history response from
response body: %s", string(resp.outputBytes))
+ assert.NilError(t, err, unmarshalError)
assert.Equal(t, resp.statusCode, 0, "app response should have no
status")
assert.Equal(t, len(appHist), 3, "incorrect number of records returned")
assert.Equal(t, appHist[0].TotalApplications, "1", "metric 1 should be
1 apps and was not")
@@ -416,7 +420,7 @@ func TestApplicationHistory(t *testing.T) {
resp = &MockResponseWriter{}
getApplicationHistory(resp, req)
err = json.Unmarshal(resp.outputBytes, &appHist)
- assert.NilError(t, err, "failed to unmarshal app history response from
response body: %s", string(resp.outputBytes))
+ assert.NilError(t, err, unmarshalError)
assert.Equal(t, resp.statusCode, 0, "app response should have no
status")
assert.Equal(t, len(appHist), 5, "incorrect number of records returned")
assert.Equal(t, appHist[0].TotalApplications, "2", "metric 1 should be
1 apps and was not")
@@ -435,9 +439,9 @@ func TestContainerHistory(t *testing.T) {
var errInfo dao.YAPIError
err := json.Unmarshal(resp.outputBytes, &errInfo)
- assert.NilError(t, err, "failed to unmarshal container history response
from response body: %s", string(resp.outputBytes))
+ assert.NilError(t, err, unmarshalError)
assert.Equal(t, http.StatusNotImplemented, resp.statusCode, "container
history handler returned wrong status")
- assert.Equal(t, errInfo.Message, "Internal metrics collection is not
enabled.", "JSON error message is incorrect")
+ assert.Equal(t, errInfo.Message, "Internal metrics collection is not
enabled.", jsonMessageError)
assert.Equal(t, errInfo.StatusCode, http.StatusNotImplemented)
// init should return null and thus no records
@@ -446,7 +450,7 @@ func TestContainerHistory(t *testing.T) {
getContainerHistory(resp, req)
var contHist []dao.ContainerHistoryDAOInfo
err = json.Unmarshal(resp.outputBytes, &contHist)
- assert.NilError(t, err, "failed to unmarshal container history response
from response body: %s", string(resp.outputBytes))
+ assert.NilError(t, err, unmarshalError)
assert.Equal(t, resp.statusCode, 0, "container response should have no
status")
assert.Equal(t, len(contHist), 0, "empty response must have no records")
@@ -457,7 +461,7 @@ func TestContainerHistory(t *testing.T) {
resp = &MockResponseWriter{}
getContainerHistory(resp, req)
err = json.Unmarshal(resp.outputBytes, &contHist)
- assert.NilError(t, err, "failed to unmarshal container history response
from response body: %s", string(resp.outputBytes))
+ assert.NilError(t, err, unmarshalError)
assert.Equal(t, resp.statusCode, 0, "container response should have no
status")
assert.Equal(t, len(contHist), 3, "incorrect number of records
returned")
assert.Equal(t, contHist[0].TotalContainers, "1", "metric 1 should be 1
apps and was not")
@@ -471,7 +475,7 @@ func TestContainerHistory(t *testing.T) {
resp = &MockResponseWriter{}
getContainerHistory(resp, req)
err = json.Unmarshal(resp.outputBytes, &contHist)
- assert.NilError(t, err, "failed to unmarshal container history response
from response body: %s", string(resp.outputBytes))
+ assert.NilError(t, err, unmarshalError)
assert.Equal(t, resp.statusCode, 0, "container response should have no
status")
assert.Equal(t, len(contHist), 5, "incorrect number of records
returned")
assert.Equal(t, contHist[0].TotalContainers, "2", "metric 1 should be 1
apps and was not")
@@ -490,7 +494,7 @@ func TestGetConfigYAML(t *testing.T) {
// yaml unmarshal handles the checksum add the end automatically in
this implementation
conf := &dao.ConfigDAOInfo{}
err = yaml.Unmarshal(resp.outputBytes, conf)
- assert.NilError(t, err, "failed to unmarshal config from response body")
+ assert.NilError(t, err, unmarshalError)
assert.Equal(t, conf.Partitions[0].NodeSortPolicy.Type, "fair", "node
sort policy set incorrectly, not fair")
startConfSum := conf.Checksum
@@ -505,7 +509,7 @@ func TestGetConfigYAML(t *testing.T) {
req.Header.Set("Accept", "unknown")
getClusterConfig(resp, req)
err = yaml.Unmarshal(resp.outputBytes, conf)
- assert.NilError(t, err, "failed to unmarshal config from response body
(updated config)")
+ assert.NilError(t, err, unmarshalError)
assert.Equal(t, conf.Partitions[0].NodeSortPolicy.Type, "binpacking",
"node sort policy not updated")
assert.Assert(t, startConfSum != conf.Checksum, "checksums did not
change in output")
assert.DeepEqual(t, conf.Extra, updatedExtraConf)
@@ -525,7 +529,7 @@ func TestGetConfigJSON(t *testing.T) {
conf := &dao.ConfigDAOInfo{}
err := json.Unmarshal(resp.outputBytes, conf)
- assert.NilError(t, err, "failed to unmarshal config from response body
(json)")
+ assert.NilError(t, err, unmarshalError)
startConfSum := conf.Checksum
assert.Equal(t, conf.Partitions[0].NodeSortPolicy.Type, "fair", "node
sort policy set incorrectly, not fair (json)")
@@ -536,7 +540,7 @@ func TestGetConfigJSON(t *testing.T) {
getClusterConfig(resp, req)
err = json.Unmarshal(resp.outputBytes, conf)
- assert.NilError(t, err, "failed to unmarshal config from response body
(json, updated config)")
+ assert.NilError(t, err, unmarshalError)
assert.Assert(t, startConfSum != conf.Checksum, "checksums did not
change in json output: %s, %s", startConfSum, conf.Checksum)
assert.Equal(t, conf.Partitions[0].NodeSortPolicy.Type, "binpacking",
"node sort policy not updated (json)")
assert.DeepEqual(t, conf.Extra, updatedExtraConf)
@@ -558,7 +562,7 @@ func TestBuildUpdateResponseFailure(t *testing.T) {
var errInfo dao.YAPIError
err1 := json.Unmarshal(resp.outputBytes, &errInfo)
- assert.NilError(t, err1, "failed to unmarshal updateconfig dao response
from response body: %s", string(resp.outputBytes))
+ assert.NilError(t, err1, unmarshalError)
assert.Equal(t, http.StatusConflict, resp.statusCode, "Status code is
wrong")
assert.Assert(t, strings.Contains(string(errInfo.Message),
err.Error()), "Error message should contain the reason")
assert.Equal(t, errInfo.StatusCode, http.StatusConflict)
@@ -875,7 +879,7 @@ func TestPartitions(t *testing.T) {
var partitionInfo []*dao.PartitionInfo
getPartitions(resp, req)
err = json.Unmarshal(resp.outputBytes, &partitionInfo)
- assert.NilError(t, err, "failed to unmarshal applications dao response
from response body: %s", string(resp.outputBytes))
+ assert.NilError(t, err, unmarshalError)
cs := make(map[string]*dao.PartitionInfo, 2)
for _, d := range partitionInfo {
@@ -933,7 +937,7 @@ func TestGetPartitionQueuesHandler(t *testing.T) {
var partitionQueuesDao dao.PartitionQueueDAOInfo
getPartitionQueues(resp, req)
err = json.Unmarshal(resp.outputBytes, &partitionQueuesDao)
- assert.NilError(t, err, "failed to unmarshal PartitionQueues dao
response from response body: %s", string(resp.outputBytes))
+ assert.NilError(t, err, unmarshalError)
assert.Equal(t, partitionQueuesDao.Children[0].Parent, "root")
assert.Equal(t, partitionQueuesDao.Children[1].Parent, "root")
assert.Equal(t, partitionQueuesDao.Children[2].Parent, "root")
@@ -1029,7 +1033,7 @@ func TestGetPartitionNodes(t *testing.T) {
var partitionNodesDao []*dao.NodeDAOInfo
getPartitionNodes(resp, req)
err = json.Unmarshal(resp.outputBytes, &partitionNodesDao)
- assert.NilError(t, err, "failed to unmarshal PartitionNodes dao
response from response body: %s", string(resp.outputBytes))
+ assert.NilError(t, err, unmarshalError)
assert.Equal(t, 1, len(partitionNodesDao[0].Allocations))
for _, node := range partitionNodesDao {
assert.Equal(t, 1, len(node.Allocations))
@@ -1140,7 +1144,7 @@ func TestGetQueueApplicationsHandler(t *testing.T) {
var appsDao []*dao.ApplicationDAOInfo
getQueueApplications(resp, req)
err = json.Unmarshal(resp.outputBytes, &appsDao)
- assert.NilError(t, err, "failed to unmarshal applications dao response
from response body: %s", string(resp.outputBytes))
+ assert.NilError(t, err, unmarshalError)
assert.Equal(t, len(appsDao), 1)
if !appsDao[0].HasReserved {
@@ -1193,7 +1197,7 @@ func TestGetQueueApplicationsHandler(t *testing.T) {
var appsDao3 []*dao.ApplicationDAOInfo
getQueueApplications(resp3, req3)
err = json.Unmarshal(resp3.outputBytes, &appsDao3)
- assert.NilError(t, err, "failed to unmarshal applications dao response
from response body: %s", string(resp.outputBytes))
+ assert.NilError(t, err, unmarshalError)
assert.Equal(t, len(appsDao3), 0)
// test missing params name
@@ -1234,7 +1238,7 @@ func TestGetApplicationHandler(t *testing.T) {
var appsDao *dao.ApplicationDAOInfo
getApplication(resp, req)
err = json.Unmarshal(resp.outputBytes, &appsDao)
- assert.NilError(t, err, "failed to unmarshal applications dao response
from response body: %s", string(resp.outputBytes))
+ assert.NilError(t, err, unmarshalError)
if !appsDao.HasReserved {
assert.Equal(t, len(appsDao.Reservations), 0)
@@ -1292,81 +1296,81 @@ 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 applications dao response
from response body")
- assert.Equal(t, http.StatusBadRequest, resp.statusCode, "Incorrect
Status code")
- assert.Equal(t, errInfo.Message, MissingParamsName, "JSON error message
is incorrect")
+ assert.NilError(t, err, unmarshalError)
+ assert.Equal(t, http.StatusBadRequest, resp.statusCode, statusCodeError)
+ assert.Equal(t, errInfo.Message, MissingParamsName, jsonMessageError)
assert.Equal(t, errInfo.StatusCode, http.StatusBadRequest)
}
func assertPartitionExists(t *testing.T, resp *MockResponseWriter) {
var errInfo dao.YAPIError
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, PartitionDoesNotExists, "JSON error
message is incorrect")
+ assert.NilError(t, err, unmarshalError)
+ assert.Equal(t, http.StatusBadRequest, resp.statusCode, statusCodeError)
+ assert.Equal(t, errInfo.Message, PartitionDoesNotExists,
jsonMessageError)
assert.Equal(t, errInfo.StatusCode, http.StatusBadRequest)
}
func assertQueueExists(t *testing.T, resp *MockResponseWriter) {
var errInfo dao.YAPIError
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, QueueDoesNotExists, "JSON error
message is incorrect")
+ assert.NilError(t, err, unmarshalError)
+ assert.Equal(t, http.StatusBadRequest, resp.statusCode, statusCodeError)
+ assert.Equal(t, errInfo.Message, QueueDoesNotExists, jsonMessageError)
assert.Equal(t, errInfo.StatusCode, http.StatusBadRequest)
}
func assertApplicationExists(t *testing.T, resp *MockResponseWriter) {
var errInfo dao.YAPIError
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, ApplicationDoesNotExists, "JSON error
message is incorrect")
+ assert.NilError(t, err, unmarshalError)
+ assert.Equal(t, http.StatusBadRequest, resp.statusCode, statusCodeError)
+ assert.Equal(t, errInfo.Message, ApplicationDoesNotExists,
jsonMessageError)
assert.Equal(t, errInfo.StatusCode, http.StatusBadRequest)
}
func assertUserExists(t *testing.T, resp *MockResponseWriter) {
var errInfo dao.YAPIError
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, UserDoesNotExists, "JSON error message
is incorrect")
+ assert.NilError(t, err, unmarshalError)
+ assert.Equal(t, http.StatusBadRequest, resp.statusCode, statusCodeError)
+ assert.Equal(t, errInfo.Message, UserDoesNotExists, jsonMessageError)
assert.Equal(t, errInfo.StatusCode, http.StatusBadRequest)
}
func assertUserNameExists(t *testing.T, resp *MockResponseWriter) {
var errInfo dao.YAPIError
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, UserNameMissing, "JSON error message
is incorrect")
+ assert.NilError(t, err, unmarshalError)
+ assert.Equal(t, http.StatusBadRequest, resp.statusCode, statusCodeError)
+ assert.Equal(t, errInfo.Message, UserNameMissing, jsonMessageError)
assert.Equal(t, errInfo.StatusCode, http.StatusBadRequest)
}
func assertGroupExists(t *testing.T, resp *MockResponseWriter) {
var errInfo dao.YAPIError
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, GroupDoesNotExists, "JSON error
message is incorrect")
+ assert.NilError(t, err, unmarshalError)
+ assert.Equal(t, http.StatusBadRequest, resp.statusCode, statusCodeError)
+ assert.Equal(t, errInfo.Message, GroupDoesNotExists, jsonMessageError)
assert.Equal(t, errInfo.StatusCode, http.StatusBadRequest)
}
func assertGroupNameExists(t *testing.T, resp *MockResponseWriter) {
var errInfo dao.YAPIError
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, GroupNameMissing, "JSON error message
is incorrect")
+ assert.NilError(t, err, unmarshalError)
+ assert.Equal(t, http.StatusBadRequest, resp.statusCode, statusCodeError)
+ assert.Equal(t, errInfo.Message, GroupNameMissing, jsonMessageError)
assert.Equal(t, errInfo.StatusCode, http.StatusBadRequest)
}
func assertNodeIDExists(t *testing.T, resp *MockResponseWriter) {
var errInfo dao.YAPIError
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, NodeDoesNotExists, "JSON error message
is incorrect")
+ assert.NilError(t, err, unmarshalError)
+ assert.Equal(t, http.StatusBadRequest, resp.statusCode, statusCodeError)
+ assert.Equal(t, errInfo.Message, NodeDoesNotExists, jsonMessageError)
assert.Equal(t, errInfo.StatusCode, http.StatusBadRequest)
}
@@ -1469,7 +1473,7 @@ func TestSpecificUserAndGroupResourceUsage(t *testing.T) {
var groupResourceUsageDao *dao.GroupResourceUsageDAOInfo
getGroupResourceUsage(resp, req)
err = json.Unmarshal(resp.outputBytes, &groupResourceUsageDao)
- assert.NilError(t, err, "failed to unmarshal group resource usage dao
response from response body: %s", string(resp.outputBytes))
+ assert.NilError(t, err, unmarshalError)
assert.DeepEqual(t, groupResourceUsageDao,
&dao.GroupResourceUsageDAOInfo{GroupName: "", Applications: nil, Queues: nil})
// Test non-existing group query
@@ -1499,7 +1503,7 @@ func TestUsersAndGroupsResourceUsage(t *testing.T) {
var usersResourceUsageDao []*dao.UserResourceUsageDAOInfo
getUsersResourceUsage(resp, req)
err = json.Unmarshal(resp.outputBytes, &usersResourceUsageDao)
- assert.NilError(t, err, "failed to unmarshal users resource usage dao
response from response body: %s", string(resp.outputBytes))
+ assert.NilError(t, err, unmarshalError)
assert.Equal(t, usersResourceUsageDao[0].Queues.ResourceUsage.String(),
resources.NewResourceFromMap(map[string]resources.Quantity{siCommon.CPU:
1}).String())
@@ -1514,7 +1518,7 @@ func TestUsersAndGroupsResourceUsage(t *testing.T) {
var expGroupsResourceUsageDao []*dao.GroupResourceUsageDAOInfo
getGroupsResourceUsage(resp, req)
err = json.Unmarshal(resp.outputBytes, &groupsResourceUsageDao)
- assert.NilError(t, err, "failed to unmarshal groups resource usage dao
response from response body: %s", string(resp.outputBytes))
+ assert.NilError(t, err, unmarshalError)
assert.DeepEqual(t, groupsResourceUsageDao, expGroupsResourceUsageDao)
// Assert existing groups
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]