You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@trafficcontrol.apache.org by GitBox <gi...@apache.org> on 2019/10/08 19:07:10 UTC
[GitHub] [trafficcontrol] mhoppa commented on a change in pull request
#3964: Add GET/POST/DELETE for server_server_capabilities
mhoppa commented on a change in pull request #3964: Add GET/POST/DELETE for server_server_capabilities
URL: https://github.com/apache/trafficcontrol/pull/3964#discussion_r332683249
##########
File path: traffic_ops/testing/api/v14/serverservercapability_test.go
##########
@@ -0,0 +1,167 @@
+package v14
+
+/*
+
+ 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"
+ "time"
+
+ "github.com/apache/trafficcontrol/lib/go-log"
+ "github.com/apache/trafficcontrol/lib/go-tc"
+ "github.com/apache/trafficcontrol/lib/go-util"
+)
+
+func TestServerServerCapabilities(t *testing.T) {
+ WithObjs(t, []TCObj{CDNs, Types, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers, ServerServerCapabilities}, func() {
+ GetTestServerServerCapabilities(t)
+ })
+}
+
+func CreateTestServerServerCapabilities(t *testing.T) {
+
+ // Valid POSTs
+
+ // loop through server ServerCapabilities, assign FKs and create
+ for _, ssc := range testData.ServerServerCapabilities {
+ servResp, _, err := TOSession.GetServerByHostName(*ssc.Server)
+ if err != nil {
+ t.Fatalf("cannot GET Server by hostname: %v - %v\n", *ssc.Server, err)
+ }
+ if servResp == nil || len(servResp) != 1 {
+ t.Fatalf("cannot GET Server by hostname: %v. Response did not include record.\n", *ssc.Server)
+ }
+ server := servResp[0]
+ ssc.ServerID = &server.ID
+ resp, _, err := TOSession.CreateServerServerCapability(ssc)
+ if err != nil {
+ t.Errorf("could not POST the server capability %v to server %v: %v\n", *ssc.ServerCapability, *ssc.Server, err)
+ }
+ log.Debugln("Response: ", server.HostName, " ", resp)
+ }
+
+ // Invalid POSTs
+
+ ssc := testData.ServerServerCapabilities[0]
+
+ // Attempt to assign already assigned server capability
+ _, _, err := TOSession.CreateServerServerCapability(ssc)
+ if err == nil {
+ t.Errorf("expected to receive error when assigning a already assigned server capability\n")
+ }
+
+ // Attempt to assign an server capability with no ID
+ sscNilID := tc.ServerServerCapabilityNullable{
+ ServerCapability: ssc.ServerCapability,
+ }
+ _, _, err = TOSession.CreateServerServerCapability(sscNilID)
+ if err == nil {
+ t.Errorf("expected to receive error when assigning a server capability without a server ID\n")
+ }
+
+ // Attempt to assign an server capability with no server capability
+ sscNilCapability := tc.ServerServerCapabilityNullable{
+ ServerID: ssc.ServerID,
+ }
+ _, _, err = TOSession.CreateServerServerCapability(sscNilCapability)
+ if err == nil {
+ t.Errorf("expected to receive error when assigning a server capability to a server without a server capability\n")
+ }
+
+ // Attempt to assign an server capability with invalid server capability
+ sscInvalidCapability := tc.ServerServerCapabilityNullable{
+ ServerID: ssc.ServerID,
+ ServerCapability: util.StrPtr("bogus"),
+ }
+ _, _, err = TOSession.CreateServerServerCapability(sscInvalidCapability)
+ if err == nil {
+ t.Errorf("expected to receive error when assigning a non existent server capability to a server\n")
+ }
+
+ // Attempt to assign an server capability with invalid server capability
+ sscInvalidID := tc.ServerServerCapabilityNullable{
+ ServerID: util.IntPtr(-1),
+ ServerCapability: ssc.ServerCapability,
+ }
+ _, _, err = TOSession.CreateServerServerCapability(sscInvalidID)
+ if err == nil {
+ t.Errorf("expected to receive error when assigning a server capability to a non existent server ID\n")
+ }
+}
+
+func GetTestServerServerCapabilities(t *testing.T) {
+ // Get All Server Capabilities
+ sscs, _, err := TOSession.GetServerServerCapabilities(nil, nil, nil)
+ if err != nil {
+ t.Fatalf("cannot GET server capabilities assigned to servers: %v\n", err)
+ }
+ if sscs == nil {
+ t.Fatalf("returned server capabilities assigned to servers was nil\n")
+ }
+ if len(sscs) != len(testData.ServerServerCapabilities) {
+ t.Errorf("expect %v server capabilities assigned to servers received %v \n", len(testData.ServerServerCapabilities), len(sscs))
+ }
+
+ for _, ssc := range sscs {
+
+ checkResp := func(t *testing.T, sscs []tc.ServerServerCapabilityNullable) {
+ if sscs == nil {
+ t.Fatalf("returned server capabilities assigned to servers was nil\n")
+ }
+ if len(sscs) != 1 {
+ t.Errorf("expect 1 server capabilities assigned to server received %v \n", len(sscs))
+ }
+ }
+ // Get assigned Server Capabilities by server id
+ sscs, _, err := TOSession.GetServerServerCapabilities(ssc.ServerID, nil, nil)
+ if err != nil {
+ t.Fatalf("cannot GET server capabilities assigned to servers by server ID %v: %v\n", *ssc.ServerID, err)
+ }
+ checkResp(t, sscs)
+ // Get assigned Server Capabilities by host name
+ sscs, _, err = TOSession.GetServerServerCapabilities(nil, ssc.Server, nil)
+ if err != nil {
+ t.Fatalf("cannot GET server capabilities assigned to servers by server host name %v: %v\n", *ssc.Server, err)
+ }
+ checkResp(t, sscs)
+
+ // Get assigned Server Capabilities by server capability
+ sscs, _, err = TOSession.GetServerServerCapabilities(nil, nil, ssc.ServerCapability)
+ if err != nil {
+ t.Fatalf("cannot GET server capabilities assigned to servers by server capability %v: %v\n", *ssc.ServerCapability, err)
+ }
+ checkResp(t, sscs)
+ }
+}
+
+func DeleteTestServerServerCapabilities(t *testing.T) {
+ time.Sleep(10 * time.Minute)
Review comment:
hahah shoot! was in for debugging and forgot to remove :)
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services