-
Notifications
You must be signed in to change notification settings - Fork 339
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated v4 tests to use totestv4 library in preparation for v5 tests (#…
- Loading branch information
1 parent
a416605
commit fa5eb59
Showing
70 changed files
with
2,277 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package totestv4 | ||
|
||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import ( | ||
"strconv" | ||
"testing" | ||
|
||
"github.com/apache/trafficcontrol/lib/go-util/assert" | ||
toclient "github.com/apache/trafficcontrol/traffic_ops/v4-client" | ||
) | ||
|
||
func CreateTestASNs(t *testing.T, cl *toclient.Session, dat TrafficControl) { | ||
for _, asn := range dat.ASNs { | ||
asn.CachegroupID = GetCacheGroupId(t, cl, asn.Cachegroup)() | ||
resp, _, err := cl.CreateASN(asn, toclient.RequestOptions{}) | ||
assert.RequireNoError(t, err, "Could not create ASN: %v - alerts: %+v", err, resp) | ||
} | ||
} | ||
|
||
func DeleteTestASNs(t *testing.T, cl *toclient.Session) { | ||
asns, _, err := cl.GetASNs(toclient.RequestOptions{}) | ||
assert.NoError(t, err, "Error trying to fetch ASNs for deletion: %v - alerts: %+v", err, asns.Alerts) | ||
|
||
for _, asn := range asns.Response { | ||
alerts, _, err := cl.DeleteASN(asn.ID, toclient.RequestOptions{}) | ||
assert.NoError(t, err, "Cannot delete ASN %d: %v - alerts: %+v", asn.ASN, err, alerts) | ||
// Retrieve the ASN to see if it got deleted | ||
opts := toclient.NewRequestOptions() | ||
opts.QueryParameters.Set("asn", strconv.Itoa(asn.ASN)) | ||
asns, _, err := cl.GetASNs(opts) | ||
assert.NoError(t, err, "Error trying to fetch ASN after deletion: %v - alerts: %+v", err, asns.Alerts) | ||
assert.Equal(t, 0, len(asns.Response), "Expected ASN %d to be deleted, but it was found in Traffic Ops", asn.ASN) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package totestv4 | ||
|
||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/apache/trafficcontrol/lib/go-util/assert" | ||
toclient "github.com/apache/trafficcontrol/traffic_ops/v4-client" | ||
) | ||
|
||
func CreateTestCachegroupsDeliveryServices(t *testing.T, cl *toclient.Session) { | ||
dses, _, err := cl.GetDeliveryServices(toclient.RequestOptions{}) | ||
assert.RequireNoError(t, err, "Cannot GET DeliveryServices: %v - %v", err, dses) | ||
|
||
opts := toclient.NewRequestOptions() | ||
opts.QueryParameters.Set("name", "cachegroup3") | ||
clientCGs, _, err := cl.GetCacheGroups(opts) | ||
assert.RequireNoError(t, err, "Cannot GET cachegroup: %v", err) | ||
assert.RequireEqual(t, len(clientCGs.Response), 1, "Getting cachegroup expected 1, got %v", len(clientCGs.Response)) | ||
assert.RequireNotNil(t, clientCGs.Response[0].ID, "Cachegroup has a nil ID") | ||
|
||
dsIDs := []int{} | ||
for _, ds := range dses.Response { | ||
if *ds.CDNName == "cdn1" && ds.Topology == nil { | ||
dsIDs = append(dsIDs, *ds.ID) | ||
} | ||
} | ||
assert.RequireGreaterOrEqual(t, len(dsIDs), 1, "No Delivery Services found in CDN 'cdn1', cannot continue.") | ||
resp, _, err := cl.SetCacheGroupDeliveryServices(*clientCGs.Response[0].ID, dsIDs, toclient.RequestOptions{}) | ||
assert.RequireNoError(t, err, "Setting cachegroup delivery services returned error: %v", err) | ||
assert.RequireGreaterOrEqual(t, len(resp.Response.ServerNames), 1, "Setting cachegroup delivery services returned success, but no servers set") | ||
} | ||
|
||
func DeleteTestCachegroupsDeliveryServices(t *testing.T, cl *toclient.Session) { | ||
opts := toclient.NewRequestOptions() | ||
opts.QueryParameters.Set("limit", "1000000") | ||
dss, _, err := cl.GetDeliveryServiceServers(opts) | ||
assert.NoError(t, err, "Unexpected error retrieving server-to-Delivery-Service assignments: %v - alerts: %+v", err, dss.Alerts) | ||
|
||
for _, ds := range dss.Response { | ||
setInactive(t, cl, *ds.DeliveryService) | ||
alerts, _, err := cl.DeleteDeliveryServiceServer(*ds.DeliveryService, *ds.Server, toclient.RequestOptions{}) | ||
assert.NoError(t, err, "Error deleting delivery service servers: %v - alerts: %+v", err, alerts.Alerts) | ||
} | ||
|
||
dss, _, err = cl.GetDeliveryServiceServers(toclient.RequestOptions{}) | ||
assert.NoError(t, err, "Unexpected error retrieving server-to-Delivery-Service assignments: %v - alerts: %+v", err, dss.Alerts) | ||
assert.Equal(t, len(dss.Response), 0, "Deleting delivery service servers: Expected empty subsequent get, actual %v", len(dss.Response)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
package totestv4 | ||
|
||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/apache/trafficcontrol/lib/go-tc" | ||
"github.com/apache/trafficcontrol/lib/go-util/assert" | ||
toclient "github.com/apache/trafficcontrol/traffic_ops/v4-client" | ||
) | ||
|
||
func CreateTestCacheGroups(t *testing.T, cl *toclient.Session, dat TrafficControl) { | ||
for _, cg := range dat.CacheGroups { | ||
|
||
resp, _, err := cl.CreateCacheGroup(cg, toclient.RequestOptions{}) | ||
if err != nil { | ||
t.Errorf("could not create Cache Group: %v - alerts: %+v", err, resp.Alerts) | ||
continue | ||
} | ||
|
||
// Testing 'join' fields during create | ||
if cg.ParentName != nil && resp.Response.ParentName == nil { | ||
t.Error("Parent cachegroup is null in response when it should have a value") | ||
} | ||
if cg.SecondaryParentName != nil && resp.Response.SecondaryParentName == nil { | ||
t.Error("Secondary parent cachegroup is null in response when it should have a value") | ||
} | ||
if cg.Type != nil && resp.Response.Type == nil { | ||
t.Error("Type is null in response when it should have a value") | ||
} | ||
assert.NotNil(t, resp.Response.LocalizationMethods, "Localization methods are null") | ||
assert.NotNil(t, resp.Response.Fallbacks, "Fallbacks are null") | ||
} | ||
} | ||
|
||
func DeleteTestCacheGroups(t *testing.T, cl *toclient.Session, dat TrafficControl) { | ||
var parentlessCacheGroups []tc.CacheGroupNullable | ||
opts := toclient.NewRequestOptions() | ||
|
||
// delete the edge caches. | ||
for _, cg := range dat.CacheGroups { | ||
if cg.Name == nil { | ||
t.Error("Found a Cache Group with null or undefined name") | ||
continue | ||
} | ||
|
||
// Retrieve the CacheGroup by name so we can get the id for Deletion | ||
opts.QueryParameters.Set("name", *cg.Name) | ||
resp, _, err := cl.GetCacheGroups(opts) | ||
assert.NoError(t, err, "Cannot GET CacheGroup by name '%s': %v - alerts: %+v", *cg.Name, err, resp.Alerts) | ||
|
||
if len(resp.Response) < 1 { | ||
t.Errorf("Could not find test data Cache Group '%s' in Traffic Ops", *cg.Name) | ||
continue | ||
} | ||
cg = resp.Response[0] | ||
|
||
// Cachegroups that are parents (usually mids but sometimes edges) | ||
// need to be deleted only after the children cachegroups are deleted. | ||
if cg.ParentCachegroupID == nil && cg.SecondaryParentCachegroupID == nil { | ||
parentlessCacheGroups = append(parentlessCacheGroups, cg) | ||
continue | ||
} | ||
|
||
if cg.ID == nil { | ||
t.Error("Traffic Ops returned a Cache Group with null or undefined ID") | ||
continue | ||
} | ||
|
||
alerts, _, err := cl.DeleteCacheGroup(*cg.ID, toclient.RequestOptions{}) | ||
assert.NoError(t, err, "Cannot delete Cache Group: %v - alerts: %+v", err, alerts) | ||
|
||
// Retrieve the CacheGroup to see if it got deleted | ||
opts.QueryParameters.Set("name", *cg.Name) | ||
cgs, _, err := cl.GetCacheGroups(opts) | ||
assert.NoError(t, err, "Error deleting Cache Group by name: %v - alerts: %+v", err, cgs.Alerts) | ||
assert.Equal(t, 0, len(cgs.Response), "Expected CacheGroup name: %s to be deleted", *cg.Name) | ||
} | ||
|
||
opts = toclient.NewRequestOptions() | ||
// now delete the parentless cachegroups | ||
for _, cg := range parentlessCacheGroups { | ||
// nil check for cg.Name occurs prior to insertion into parentlessCacheGroups | ||
opts.QueryParameters.Set("name", *cg.Name) | ||
// Retrieve the CacheGroup by name so we can get the id for Deletion | ||
resp, _, err := cl.GetCacheGroups(opts) | ||
assert.NoError(t, err, "Cannot get Cache Group by name '%s': %v - alerts: %+v", *cg.Name, err, resp.Alerts) | ||
|
||
if len(resp.Response) < 1 { | ||
t.Errorf("Cache Group '%s' somehow stopped existing since the last time we ask Traffic Ops about it", *cg.Name) | ||
continue | ||
} | ||
|
||
respCG := resp.Response[0] | ||
if respCG.ID == nil { | ||
t.Errorf("Traffic Ops returned Cache Group '%s' with null or undefined ID", *cg.Name) | ||
continue | ||
} | ||
delResp, _, err := cl.DeleteCacheGroup(*respCG.ID, toclient.RequestOptions{}) | ||
assert.NoError(t, err, "Cannot delete Cache Group '%s': %v - alerts: %+v", *respCG.Name, err, delResp.Alerts) | ||
|
||
// Retrieve the CacheGroup to see if it got deleted | ||
opts.QueryParameters.Set("name", *cg.Name) | ||
cgs, _, err := cl.GetCacheGroups(opts) | ||
assert.NoError(t, err, "Error attempting to fetch Cache Group '%s' after deletion: %v - alerts: %+v", *cg.Name, err, cgs.Alerts) | ||
assert.Equal(t, 0, len(cgs.Response), "Expected Cache Group '%s' to be deleted", *cg.Name) | ||
} | ||
} | ||
|
||
func GetCacheGroupId(t *testing.T, cl *toclient.Session, cacheGroupName string) func() int { | ||
return func() int { | ||
opts := toclient.NewRequestOptions() | ||
opts.QueryParameters.Set("name", cacheGroupName) | ||
|
||
resp, _, err := cl.GetCacheGroups(opts) | ||
assert.RequireNoError(t, err, "Get Cache Groups Request failed with error: %v", err) | ||
assert.RequireEqual(t, len(resp.Response), 1, "Expected response object length 1, but got %d", len(resp.Response)) | ||
assert.RequireNotNil(t, resp.Response[0].ID, "Expected id to not be nil") | ||
|
||
return *resp.Response[0].ID | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package totestv4 | ||
|
||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import ( | ||
"strconv" | ||
"testing" | ||
|
||
"github.com/apache/trafficcontrol/lib/go-util/assert" | ||
toclient "github.com/apache/trafficcontrol/traffic_ops/v4-client" | ||
) | ||
|
||
func GetCDNID(t *testing.T, cl *toclient.Session, cdnName string) func() int { | ||
return func() int { | ||
opts := toclient.NewRequestOptions() | ||
opts.QueryParameters.Set("name", cdnName) | ||
cdnsResp, _, err := cl.GetCDNs(opts) | ||
assert.RequireNoError(t, err, "Get CDNs Request failed with error:", err) | ||
assert.RequireEqual(t, 1, len(cdnsResp.Response), "Expected response object length 1, but got %d", len(cdnsResp.Response)) | ||
assert.RequireNotNil(t, cdnsResp.Response[0].ID, "Expected id to not be nil") | ||
return cdnsResp.Response[0].ID | ||
} | ||
} | ||
|
||
func CreateTestCDNs(t *testing.T, cl *toclient.Session, dat TrafficControl) { | ||
for _, cdn := range dat.CDNs { | ||
resp, _, err := cl.CreateCDN(cdn, toclient.RequestOptions{}) | ||
assert.NoError(t, err, "Could not create CDN: %v - alerts: %+v", err, resp.Alerts) | ||
} | ||
} | ||
|
||
func DeleteTestCDNs(t *testing.T, cl *toclient.Session) { | ||
resp, _, err := cl.GetCDNs(toclient.RequestOptions{}) | ||
assert.NoError(t, err, "Cannot get CDNs: %v - alerts: %+v", err, resp.Alerts) | ||
for _, cdn := range resp.Response { | ||
delResp, _, err := cl.DeleteCDN(cdn.ID, toclient.RequestOptions{}) | ||
assert.NoError(t, err, "Cannot delete CDN '%s' (#%d): %v - alerts: %+v", cdn.Name, cdn.ID, err, delResp.Alerts) | ||
|
||
// Retrieve the CDN to see if it got deleted | ||
opts := toclient.NewRequestOptions() | ||
opts.QueryParameters.Set("id", strconv.Itoa(cdn.ID)) | ||
cdns, _, err := cl.GetCDNs(opts) | ||
assert.NoError(t, err, "Error deleting CDN '%s': %v - alerts: %+v", cdn.Name, err, cdns.Alerts) | ||
assert.Equal(t, 0, len(cdns.Response), "Expected CDN '%s' to be deleted", cdn.Name) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package totestv4 | ||
|
||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import ( | ||
"strconv" | ||
"testing" | ||
|
||
"github.com/apache/trafficcontrol/lib/go-util/assert" | ||
toclient "github.com/apache/trafficcontrol/traffic_ops/v4-client" | ||
) | ||
|
||
func CreateTestCoordinates(t *testing.T, cl *toclient.Session, td TrafficControl) { | ||
for _, coordinate := range td.Coordinates { | ||
resp, _, err := cl.CreateCoordinate(coordinate, toclient.RequestOptions{}) | ||
assert.RequireNoError(t, err, "Could not create coordinate: %v - alerts: %+v", err, resp.Alerts) | ||
} | ||
} | ||
|
||
func DeleteTestCoordinates(t *testing.T, cl *toclient.Session) { | ||
coordinates, _, err := cl.GetCoordinates(toclient.RequestOptions{}) | ||
assert.NoError(t, err, "Cannot get Coordinates: %v - alerts: %+v", err, coordinates.Alerts) | ||
for _, coordinate := range coordinates.Response { | ||
alerts, _, err := cl.DeleteCoordinate(coordinate.ID, toclient.RequestOptions{}) | ||
assert.NoError(t, err, "Unexpected error deleting Coordinate '%s' (#%d): %v - alerts: %+v", coordinate.Name, coordinate.ID, err, alerts.Alerts) | ||
// Retrieve the Coordinate to see if it got deleted | ||
opts := toclient.NewRequestOptions() | ||
opts.QueryParameters.Set("id", strconv.Itoa(coordinate.ID)) | ||
getCoordinate, _, err := cl.GetCoordinates(opts) | ||
assert.NoError(t, err, "Error getting Coordinate '%s' after deletion: %v - alerts: %+v", coordinate.Name, err, getCoordinate.Alerts) | ||
assert.Equal(t, 0, len(getCoordinate.Response), "Expected Coordinate '%s' to be deleted, but it was found in Traffic Ops", coordinate.Name) | ||
} | ||
} |
Oops, something went wrong.