Skip to content

Commit

Permalink
Updated Integration tests for apache#7519
Browse files Browse the repository at this point in the history
  • Loading branch information
jagan-parthiban committed May 28, 2023
1 parent e413966 commit bdd96b1
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 13 deletions.
33 changes: 27 additions & 6 deletions traffic_ops/testing/api/v4/servers_id_deliveryservices_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,13 @@ func TestServersIDDeliveryServices(t *testing.T) {
"replace": true,
},
Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK),
validateServersDeliveryServicesPost(totest.GetServerID(t, TOSession, "atlanta-edge-01")(), totest.GetDeliveryServiceId(t, TOSession, "ds1")())),
validateServersDeliveryServicesPost(
totest.GetServerID(t, TOSession, "atlanta-edge-01")(),
[]int{
totest.GetDeliveryServiceId(t, TOSession, "ds1")(),
totest.GetDeliveryServiceId(t, TOSession, "ds-based-top-with-no-mids")(),
},
2)),
},
"OK when ASSIGNING EDGE to TOPOLOGY BASED DELIVERY SERVICE": {
EndpointID: totest.GetServerID(t, TOSession, "atlanta-edge-03"),
Expand All @@ -67,7 +73,12 @@ func TestServersIDDeliveryServices(t *testing.T) {
"replace": true,
},
Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK),
validateServersDeliveryServicesPost(totest.GetServerID(t, TOSession, "atlanta-edge-03")(), totest.GetDeliveryServiceId(t, TOSession, "top-ds-in-cdn1")())),
validateServersDeliveryServicesPost(
totest.GetServerID(t, TOSession, "atlanta-edge-03")(),
[]int{
totest.GetDeliveryServiceId(t, TOSession, "top-ds-in-cdn1")(),
},
1)),
},
"OK when ASSIGNING ORIGIN to TOPOLOGY BASED DELIVERY SERVICE": {
EndpointID: totest.GetServerID(t, TOSession, "denver-mso-org-01"),
Expand All @@ -77,7 +88,14 @@ func TestServersIDDeliveryServices(t *testing.T) {
"replace": true,
},
Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK),
validateServersDeliveryServicesPost(totest.GetServerID(t, TOSession, "denver-mso-org-01")(), totest.GetDeliveryServiceId(t, TOSession, "ds-top")())),
validateServersDeliveryServicesPost(
totest.GetServerID(t, TOSession, "denver-mso-org-01")(),
[]int{
totest.GetDeliveryServiceId(t, TOSession, "ds-top")(),
totest.GetDeliveryServiceId(t, TOSession, "ds-top-req-cap2")(),
totest.GetDeliveryServiceId(t, TOSession, "ds-forked-topology")(),
},
3)),
},
"CONFLICT when SERVER NOT IN SAME CDN as DELIVERY SERVICE": {
EndpointID: totest.GetServerID(t, TOSession, "cdn2-test-edge"),
Expand Down Expand Up @@ -171,11 +189,14 @@ func validateServersDeliveryServices(expectedDSID int) utils.CkReqFunc {
}
}

func validateServersDeliveryServicesPost(serverID int, expectedDSID int) utils.CkReqFunc {
func validateServersDeliveryServicesPost(serverID int, expectedDSID []int, expectedDSCount int) utils.CkReqFunc {
return func(t *testing.T, _ toclientlib.ReqInf, resp interface{}, _ tc.Alerts, _ error) {
serverDeliveryServices, _, err := TOSession.GetServerIDDeliveryServices(serverID, client.RequestOptions{})
assert.RequireNoError(t, err, "Error getting Server Delivery Services: %v - alerts: %+v", err, serverDeliveryServices.Alerts)
assert.RequireEqual(t, 1, len(serverDeliveryServices.Response), "Expected one Delivery Service returned Got: %d", len(serverDeliveryServices.Response))
validateServersDeliveryServices(expectedDSID)(t, toclientlib.ReqInf{}, serverDeliveryServices.Response, tc.Alerts{}, nil)
assert.RequireEqual(t, expectedDSCount, len(serverDeliveryServices.Response), "Expected Two Delivery Service returned Got: %d", len(serverDeliveryServices.Response))
for i := 0; i < len(expectedDSID); i++ {
validateServersDeliveryServices(expectedDSID[i])(t, toclientlib.ReqInf{}, serverDeliveryServices.Response, tc.Alerts{}, nil)

}
}
}
33 changes: 27 additions & 6 deletions traffic_ops/testing/api/v5/servers_id_deliveryservices_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,13 @@ func TestServersIDDeliveryServices(t *testing.T) {
"replace": true,
},
Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK),
validateServersDeliveryServicesPost(GetServerID(t, "atlanta-edge-01")(), GetDeliveryServiceId(t, "ds1")())),
validateServersDeliveryServicesPost(
GetServerID(t, "atlanta-edge-01")(),
[]int{
GetDeliveryServiceId(t, "ds1")(),
GetDeliveryServiceId(t, "ds-based-top-with-no-mids")(),
},
2)),
},
"OK when ASSIGNING EDGE to TOPOLOGY BASED DELIVERY SERVICE": {
EndpointID: GetServerID(t, "atlanta-edge-03"),
Expand All @@ -66,7 +72,12 @@ func TestServersIDDeliveryServices(t *testing.T) {
"replace": true,
},
Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK),
validateServersDeliveryServicesPost(GetServerID(t, "atlanta-edge-03")(), GetDeliveryServiceId(t, "top-ds-in-cdn1")())),
validateServersDeliveryServicesPost(
GetServerID(t, "atlanta-edge-03")(),
[]int{
GetDeliveryServiceId(t, "top-ds-in-cdn1")(),
},
1)),
},
"OK when ASSIGNING ORIGIN to TOPOLOGY BASED DELIVERY SERVICE": {
EndpointID: GetServerID(t, "denver-mso-org-01"),
Expand All @@ -76,7 +87,14 @@ func TestServersIDDeliveryServices(t *testing.T) {
"replace": true,
},
Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK),
validateServersDeliveryServicesPost(GetServerID(t, "denver-mso-org-01")(), GetDeliveryServiceId(t, "ds-top")())),
validateServersDeliveryServicesPost(
GetServerID(t, "denver-mso-org-01")(),
[]int{
GetDeliveryServiceId(t, "ds-top")(),
GetDeliveryServiceId(t, "ds-top-req-cap2")(),
GetDeliveryServiceId(t, "ds-forked-topology")(),
},
3)),
},
"CONFLICT when SERVER NOT IN SAME CDN as DELIVERY SERVICE": {
EndpointID: GetServerID(t, "cdn2-test-edge"),
Expand Down Expand Up @@ -170,11 +188,14 @@ func validateServersDeliveryServices(expectedDSID int) utils.CkReqFunc {
}
}

func validateServersDeliveryServicesPost(serverID int, expectedDSID int) utils.CkReqFunc {
func validateServersDeliveryServicesPost(serverID int, expectedDSID []int, expectedDSCount int) utils.CkReqFunc {
return func(t *testing.T, _ toclientlib.ReqInf, resp interface{}, _ tc.Alerts, _ error) {
serverDeliveryServices, _, err := TOSession.GetServerIDDeliveryServices(serverID, client.RequestOptions{})
assert.RequireNoError(t, err, "Error getting Server Delivery Services: %v - alerts: %+v", err, serverDeliveryServices.Alerts)
assert.RequireEqual(t, 1, len(serverDeliveryServices.Response), "Expected one Delivery Service returned Got: %d", len(serverDeliveryServices.Response))
validateServersDeliveryServices(expectedDSID)(t, toclientlib.ReqInf{}, serverDeliveryServices.Response, tc.Alerts{}, nil)
assert.RequireEqual(t, expectedDSCount, len(serverDeliveryServices.Response), "Expected Two Delivery Service returned Got: %d", len(serverDeliveryServices.Response))
for i := 0; i < len(expectedDSID); i++ {
validateServersDeliveryServices(expectedDSID[i])(t, toclientlib.ReqInf{}, serverDeliveryServices.Response, tc.Alerts{}, nil)

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,7 @@ func (dss *TODSSDeliveryService) Read(h http.Header, useIMS bool) ([]interface{}
where = "WHERE "
}

where += "ds.id in (SELECT deliveryService FROM deliveryservice_server WHERE server = :server) OR ds.id in (SELECT id FROM deliveryservice WHERE topology = ( SELECT topology FROM topology_cachegroup WHERE cachegroup = ( SELECT name FROM cachegroup WHERE id = ( SELECT cachegroup FROM server WHERE id = :server ))))"
where += "ds.id in (SELECT deliveryService FROM deliveryservice_server WHERE server = :server) OR ds.id in (SELECT id FROM deliveryservice WHERE topology in ( SELECT topology FROM topology_cachegroup WHERE cachegroup = ( SELECT name FROM cachegroup WHERE id = ( SELECT cachegroup FROM server WHERE id = :server ))))"

tenantIDs, err := tenant.GetUserTenantIDListTx(tx, user.TenantID)
if err != nil {
Expand Down

0 comments on commit bdd96b1

Please sign in to comment.