-
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.
Add TO Go delete ds_servers client funcs, tests
- Loading branch information
Showing
4 changed files
with
186 additions
and
2 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
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 @@ | ||
/* | ||
Licensed 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. | ||
*/ | ||
|
||
package v13 | ||
|
||
import ( | ||
"encoding/json" | ||
"strconv" | ||
|
||
"github.com/apache/trafficcontrol/lib/go-tc" | ||
"github.com/apache/trafficcontrol/lib/go-util" | ||
) | ||
|
||
func (to *Session) GetDeliveryServiceServers() ([]tc.DeliveryServiceServer, ReqInf, error) { | ||
path := apiBase + `/deliveryserviceserver` | ||
// deliveryService | ||
resp := tc.DeliveryServiceServerResponse{} | ||
reqInf, err := get(to, path, &resp) | ||
if err != nil { | ||
return nil, reqInf, err | ||
} | ||
return resp.Response, reqInf, nil | ||
} | ||
|
||
// CreateDeliveryServiceServers associates the given servers with the given delivery services. If replace is true, it deletes any existing associations for the given delivery service. | ||
func (to *Session) CreateDeliveryServiceServers(dsID int, serverIDs []int, replace bool) (*tc.DSServerIDs, error) { | ||
path := apiBase + `/deliveryserviceserver` | ||
req := tc.DSServerIDs{ | ||
DeliveryServiceID: util.IntPtr(dsID), | ||
ServerIDs: serverIDs, | ||
Replace: util.BoolPtr(replace), | ||
} | ||
jsonReq, err := json.Marshal(&req) | ||
if err != nil { | ||
return nil, err | ||
} | ||
resp := struct { | ||
Response tc.DSServerIDs `json:"response"` | ||
}{} | ||
if err := post(to, path, jsonReq, &resp); err != nil { | ||
return nil, err | ||
} | ||
return &resp.Response, nil | ||
} | ||
|
||
// DeleteDeliveryService deletes the given delivery service server association. | ||
func (to *Session) DeleteDeliveryServiceServer(dsID int, serverID int) error { | ||
path := apiBase + `/deliveryservice_server/` + strconv.Itoa(dsID) + `/` + strconv.Itoa(serverID) | ||
resp := struct{ tc.Alerts }{} | ||
err := del(to, path, &resp) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} |
111 changes: 111 additions & 0 deletions
111
traffic_ops/testing/api/v13/deliveryserviceservers_test.go
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,111 @@ | ||
package v13 | ||
|
||
/* | ||
Licensed 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-log" | ||
) | ||
|
||
func TestDeliveryServiceServers(t *testing.T) { | ||
CreateTestCDNs(t) | ||
CreateTestTypes(t) | ||
CreateTestProfiles(t) | ||
CreateTestStatuses(t) | ||
CreateTestDivisions(t) | ||
CreateTestRegions(t) | ||
CreateTestPhysLocations(t) | ||
CreateTestCacheGroups(t) | ||
CreateTestServers(t) | ||
CreateTestDeliveryServices(t) | ||
|
||
DeleteTestDeliveryServiceServers(t) | ||
|
||
DeleteTestDeliveryServices(t) | ||
DeleteTestServers(t) | ||
DeleteTestCacheGroups(t) | ||
DeleteTestPhysLocations(t) | ||
DeleteTestRegions(t) | ||
DeleteTestDivisions(t) | ||
DeleteTestStatuses(t) | ||
DeleteTestProfiles(t) | ||
DeleteTestTypes(t) | ||
DeleteTestCDNs(t) | ||
} | ||
|
||
func DeleteTestDeliveryServiceServers(t *testing.T) { | ||
log.Debugln("DeleteTestDeliveryServiceServers") | ||
|
||
dses, _, err := TOSession.GetDeliveryServices() | ||
if err != nil { | ||
t.Fatalf("cannot GET DeliveryServices: %v\n", err) | ||
} | ||
if len(dses) < 1 { | ||
t.Fatalf("GET DeliveryServices returned no dses, must have at least 1 to test ds-servers") | ||
} | ||
ds := dses[0] | ||
|
||
servers, _, err := TOSession.GetServers() | ||
if err != nil { | ||
t.Fatalf("cannot GET Servers: %v\n", err) | ||
} | ||
if len(servers) < 1 { | ||
t.Fatalf("GET Servers returned no dses, must have at least 1 to test ds-servers") | ||
} | ||
server := servers[0] | ||
|
||
_, err = TOSession.CreateDeliveryServiceServers(ds.ID, []int{server.ID}, true) | ||
if err != nil { | ||
t.Fatalf("POST delivery service servers: %v\n", err) | ||
} | ||
|
||
dsServers, _, err := TOSession.GetDeliveryServiceServers() | ||
if err != nil { | ||
t.Fatalf("GET delivery service servers: %v\n", err) | ||
} | ||
|
||
found := false | ||
for _, dss := range dsServers { | ||
if *dss.DeliveryService == ds.ID && *dss.Server == server.ID { | ||
found = true | ||
break | ||
} | ||
} | ||
if !found { | ||
t.Fatalf("POST delivery service servers returned success, but ds-server not in GET") | ||
} | ||
|
||
if err := TOSession.DeleteDeliveryServiceServer(ds.ID, server.ID); err != nil { | ||
t.Fatalf("DELETE delivery service server: %v\n", err) | ||
} | ||
|
||
dsServers, _, err = TOSession.GetDeliveryServiceServers() | ||
if err != nil { | ||
t.Fatalf("GET delivery service servers: %v\n", err) | ||
} | ||
|
||
found = false | ||
for _, dss := range dsServers { | ||
if *dss.DeliveryService == ds.ID && *dss.Server == server.ID { | ||
found = true | ||
break | ||
} | ||
} | ||
if found { | ||
t.Fatalf("DELETE delivery service servers returned success, but still in GET") | ||
} | ||
} |
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