zrhoffman commented on code in PR #7151:
URL: https://github.com/apache/trafficcontrol/pull/7151#discussion_r1002131580
##########
traffic_ops/testing/api/v5/cachegroups_test.go:
##########
@@ -65,184 +67,173 @@ func TestCacheGroups(t *testing.T) {
Expectations:
utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusNotModified)),
},
"OK when VALID request": {
- ClientSession: TOSession, Expectations:
utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK)),
+ ClientSession: TOSession,
+ Expectations:
utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK)),
},
"OK when VALID NAME parameter": {
- ClientSession: TOSession, RequestOpts:
client.RequestOptions{QueryParameters: url.Values{"name":
{"parentCachegroup"}}},
+ ClientSession: TOSession,
+ RequestOpts:
client.RequestOptions{QueryParameters: url.Values{"name":
{"parentCachegroup"}}},
Expectations:
utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK),
utils.ResponseHasLength(1),
ValidateExpectedField("Name",
"parentCachegroup")),
},
"OK when VALID SHORTNAME parameter": {
- ClientSession: TOSession, RequestOpts:
client.RequestOptions{QueryParameters: url.Values{"shortName": {"pg2"}}},
+ ClientSession: TOSession,
+ RequestOpts:
client.RequestOptions{QueryParameters: url.Values{"shortName": {"pg2"}}},
Expectations:
utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK),
utils.ResponseHasLength(1),
ValidateExpectedField("ShortName", "pg2")),
},
"OK when VALID TOPOLOGY parameter": {
- ClientSession: TOSession, RequestOpts:
client.RequestOptions{QueryParameters: url.Values{"topology":
{"mso-topology"}}},
- Expectations:
utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK)),
+ ClientSession: TOSession,
+ RequestOpts:
client.RequestOptions{QueryParameters: url.Values{"topology":
{"mso-topology"}}},
+ Expectations:
utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK)),
},
"OK when VALID TYPE parameter": {
- ClientSession: TOSession, RequestOpts:
client.RequestOptions{QueryParameters: url.Values{"type": {"ORG_LOC"}}},
+ ClientSession: TOSession,
+ RequestOpts:
client.RequestOptions{QueryParameters: url.Values{"type":
{strconv.Itoa(GetTypeId(t, "ORG_LOC"))}}},
Expectations:
utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK),
utils.ResponseLengthGreaterOrEqual(1),
ValidateExpectedField("TypeName", "ORG_LOC")),
},
"EMPTY RESPONSE when INVALID ID parameter": {
- ClientSession: TOSession, RequestOpts:
client.RequestOptions{QueryParameters: url.Values{"id": {"10000"}}},
- Expectations:
utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK),
utils.ResponseHasLength(0)),
+ ClientSession: TOSession,
+ RequestOpts:
client.RequestOptions{QueryParameters: url.Values{"id": {"10000"}}},
+ Expectations:
utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK),
utils.ResponseHasLength(0)),
},
"EMPTY RESPONSE when INVALID TYPE parameter": {
- ClientSession: TOSession, RequestOpts:
client.RequestOptions{QueryParameters: url.Values{"type": {"10000"}}},
- Expectations:
utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK),
utils.ResponseHasLength(0)),
+ ClientSession: TOSession,
+ RequestOpts:
client.RequestOptions{QueryParameters: url.Values{"type": {"10000"}}},
+ Expectations:
utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK),
utils.ResponseHasLength(0)),
},
"FIRST RESULT when LIMIT=1": {
- ClientSession: TOSession, RequestOpts:
client.RequestOptions{QueryParameters: url.Values{"orderby": {"id"}, "limit":
{"1"}}},
- Expectations:
utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK),
ValidatePagination("limit")),
+ ClientSession: TOSession,
+ RequestOpts:
client.RequestOptions{QueryParameters: url.Values{"orderby": {"id"}, "limit":
{"1"}}},
+ Expectations:
utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK),
ValidatePagination("limit")),
},
"SECOND RESULT when LIMIT=1 OFFSET=1": {
- ClientSession: TOSession, RequestOpts:
client.RequestOptions{QueryParameters: url.Values{"orderby": {"id"}, "limit":
{"1"}, "offset": {"1"}}},
- Expectations:
utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK),
ValidatePagination("offset")),
+ ClientSession: TOSession,
+ RequestOpts:
client.RequestOptions{QueryParameters: url.Values{"orderby": {"id"}, "limit":
{"1"}, "offset": {"1"}}},
+ Expectations:
utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK),
ValidatePagination("offset")),
},
"SECOND RESULT when LIMIT=1 PAGE=2": {
- ClientSession: TOSession, RequestOpts:
client.RequestOptions{QueryParameters: url.Values{"orderby": {"id"}, "limit":
{"1"}, "page": {"2"}}},
- Expectations:
utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK),
ValidatePagination("page")),
+ ClientSession: TOSession,
+ RequestOpts:
client.RequestOptions{QueryParameters: url.Values{"orderby": {"id"}, "limit":
{"1"}, "page": {"2"}}},
+ Expectations:
utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK),
ValidatePagination("page")),
},
"BAD REQUEST when INVALID LIMIT parameter": {
- ClientSession: TOSession, RequestOpts:
client.RequestOptions{QueryParameters: url.Values{"limit": {"-2"}}},
- Expectations:
utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusBadRequest)),
+ ClientSession: TOSession,
+ RequestOpts:
client.RequestOptions{QueryParameters: url.Values{"limit": {"-2"}}},
+ Expectations:
utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusBadRequest)),
},
"BAD REQUEST when INVALID OFFSET parameter": {
- ClientSession: TOSession, RequestOpts:
client.RequestOptions{QueryParameters: url.Values{"limit": {"1"}, "offset":
{"0"}}},
- Expectations:
utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusBadRequest)),
+ ClientSession: TOSession,
+ RequestOpts:
client.RequestOptions{QueryParameters: url.Values{"limit": {"1"}, "offset":
{"0"}}},
+ Expectations:
utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusBadRequest)),
},
"BAD REQUEST when INVALID PAGE parameter": {
- ClientSession: TOSession, RequestOpts:
client.RequestOptions{QueryParameters: url.Values{"limit": {"1"}, "page":
{"0"}}},
- Expectations:
utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusBadRequest)),
+ ClientSession: TOSession,
+ RequestOpts:
client.RequestOptions{QueryParameters: url.Values{"limit": {"1"}, "page":
{"0"}}},
+ Expectations:
utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusBadRequest)),
},
"UNAUTHORIZED when NOT LOGGED IN": {
- ClientSession: NoAuthTOSession,
Expectations: utils.CkRequest(utils.HasError(),
utils.HasStatus(http.StatusUnauthorized)),
+ ClientSession: NoAuthTOSession,
+ Expectations:
utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusUnauthorized)),
+ },
+ "OK when CHANGES made": {
+ ClientSession: TOSession,
+ RequestOpts:
client.RequestOptions{Header: http.Header{rfc.IfModifiedSince:
{currentTimeRFC}}},
+ Expectations:
utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK)),
},
},
"POST": {
"UNAUTHORIZED when NOT LOGGED IN": {
- ClientSession: NoAuthTOSession,
Expectations: utils.CkRequest(utils.HasError(),
utils.HasStatus(http.StatusUnauthorized)),
+ ClientSession: NoAuthTOSession,
+ Expectations:
utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusUnauthorized)),
},
},
"PUT": {
"OK when VALID request": {
EndpointId: GetCacheGroupId(t,
"cachegroup1"), ClientSession: TOSession,
- RequestBody: map[string]interface{}{
- "latitude": 17.5,
- "longitude": 17.5,
- "name":
"cachegroup1",
- "shortName":
"newShortName",
- "localizationMethods":
[]string{"CZ"},
- "fallbacks":
[]string{"fallback1"},
- "typeName":
"EDGE_LOC",
- "typeId": -1,
+ RequestBody: tc.CacheGroupNullable{
+ Latitude:
util.Ptr(17.5),
+ Longitude:
util.Ptr(17.5),
+ Name:
util.Ptr("cachegroup1"),
+ ShortName:
util.Ptr("newShortName"),
+ LocalizationMethods:
util.Ptr([]tc.LocalizationMethod{tc.LocalizationMethodCZ}),
+ Fallbacks:
util.Ptr([]string{"fallback1"}),
+ Type:
util.Ptr("EDGE_LOC"),
+ TypeID:
util.Ptr(GetTypeId(t, "EDGE_LOC")),
},
Expectations:
utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK)),
},
"OK when updating CG with null Lat/Long": {
EndpointId: GetCacheGroupId(t,
"nullLatLongCG"), ClientSession: TOSession,
- RequestBody: map[string]interface{}{
- "name": "nullLatLongCG",
- "shortName": "null-ll",
- "typeName": "EDGE_LOC",
- "fallbacks":
[]string{"fallback1"},
- "typeId": -1,
+ RequestBody: tc.CacheGroupNullable{
+ Name:
util.Ptr("nullLatLongCG"),
+ ShortName: util.Ptr("null-ll"),
+ Type: util.Ptr("EDGE_LOC"),
+ Fallbacks:
util.Ptr([]string{"fallback1"}),
+ TypeID:
util.Ptr(GetTypeId(t, "EDGE_LOC")),
},
Expectations:
utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK)),
},
"BAD REQUEST when updating TYPE of CG in
TOPOLOGY": {
EndpointId: GetCacheGroupId(t,
"topology-edge-cg-01"), ClientSession: TOSession,
- RequestBody: map[string]interface{}{
- "id": -1,
- "latitude": 0,
- "longitude": 0,
- "name":
"topology-edge-cg-01",
- "shortName": "te1",
- "typeName": "MID_LOC",
- "typeId": -1,
+ RequestBody: tc.CacheGroupNullable{
+ Latitude: util.Ptr(0.0),
+ Longitude: util.Ptr(0.0),
+ Name:
util.Ptr("topology-edge-cg-01"),
+ ShortName: util.Ptr("te1"),
+ Type: util.Ptr("MID_LOC"),
+ TypeID:
util.Ptr(GetTypeId(t, "MID_LOC")),
},
Expectations:
utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusBadRequest)),
},
"PRECONDITION FAILED when updating with IMS &
IUS Headers": {
EndpointId: GetCacheGroupId(t,
"cachegroup1"), ClientSession: TOSession,
RequestOpts:
client.RequestOptions{Header: http.Header{rfc.IfUnmodifiedSince:
{currentTimeRFC}}},
- RequestBody: map[string]interface{}{
- "name": "cachegroup1",
- "shortName": "changeName",
- "typeName": "EDGE_LOC",
- "typeId": -1,
+ RequestBody: tc.CacheGroupNullable{
+ Name:
util.Ptr("cachegroup1"),
+ ShortName:
util.Ptr("changeName"),
+ Type: util.Ptr("EDGE_LOC"),
+ TypeID:
util.Ptr(GetTypeId(t, "EDGE_LOC")),
},
Expectations:
utils.CkRequest(utils.HasError(),
utils.HasStatus(http.StatusPreconditionFailed)),
},
"PRECONDITION FAILED when updating with IFMATCH
ETAG Header": {
EndpointId: GetCacheGroupId(t,
"cachegroup1"), ClientSession: TOSession,
RequestOpts:
client.RequestOptions{Header: http.Header{rfc.IfMatch:
{rfc.ETag(currentTime)}}},
- RequestBody: map[string]interface{}{
- "name": "cachegroup1",
- "shortName": "changeName",
- "typeName": "EDGE_LOC",
- "typeId": -1,
+ RequestBody: tc.CacheGroupNullable{
+ Name:
util.Ptr("cachegroup1"),
+ ShortName:
util.Ptr("changeName"),
+ Type: util.Ptr("EDGE_LOC"),
+ TypeID:
util.Ptr(GetTypeId(t, "EDGE_LOC")),
},
Expectations:
utils.CkRequest(utils.HasError(),
utils.HasStatus(http.StatusPreconditionFailed)),
},
"UNAUTHORIZED when NOT LOGGED IN": {
- EndpointId: GetCacheGroupId(t,
"cachegroup1"), ClientSession: NoAuthTOSession,
- Expectations:
utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusUnauthorized)),
+ EndpointId: GetCacheGroupId(t,
"cachegroup1"),
+ ClientSession: NoAuthTOSession,
+ Expectations:
utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusUnauthorized)),
},
},
"DELETE": {
"NOT FOUND when INVALID ID parameter": {
- EndpointId: func() int { return 111111
}, ClientSession: TOSession,
- Expectations:
utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusNotFound)),
+ EndpointId: func() int { return
111111 },
+ ClientSession: TOSession,
+ Expectations:
utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusNotFound)),
},
"UNAUTHORIZED when NOT LOGGED IN": {
- EndpointId: GetCacheGroupId(t,
"cachegroup1"), ClientSession: NoAuthTOSession,
- Expectations:
utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusUnauthorized)),
- },
- },
- "GET AFTER CHANGES": {
- "OK when CHANGES made": {
- ClientSession: TOSession,
- RequestOpts:
client.RequestOptions{Header: http.Header{rfc.IfModifiedSince:
{currentTimeRFC}}},
- Expectations:
utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK)),
+ EndpointId: GetCacheGroupId(t,
"cachegroup1"),
+ ClientSession: NoAuthTOSession,
+ Expectations:
utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusUnauthorized)),
},
},
}
for method, testCases := range methodTests {
t.Run(method, func(t *testing.T) {
for name, testCase := range testCases {
- cg := tc.CacheGroupNullable{}
-
- if
testCase.RequestOpts.QueryParameters.Has("type") {
- val :=
testCase.RequestOpts.QueryParameters.Get("type")
- if _, err := strconv.Atoi(val);
err != nil {
-
testCase.RequestOpts.QueryParameters.Set("type", strconv.Itoa(GetTypeId(t,
val)))
- }
- }
Review Comment:
This also
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]