You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by ne...@apache.org on 2016/11/01 20:43:24 UTC

[1/2] incubator-trafficcontrol git commit: add `DeliveryServiceServer` tests

Repository: incubator-trafficcontrol
Updated Branches:
  refs/heads/master 7182647d7 -> d0121d178


add `DeliveryServiceServer` tests


Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/d0121d17
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/d0121d17
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/d0121d17

Branch: refs/heads/master
Commit: d0121d178f0423e898aa94f744f3086ddf94f4f7
Parents: a61ef2e
Author: Mike Ball <mi...@gmail.com>
Authored: Sat Oct 29 10:50:30 2016 -0400
Committer: Dave Neuman <ne...@apache.org>
Committed: Tue Nov 1 14:35:52 2016 -0600

----------------------------------------------------------------------
 traffic_ops/client/delivery_service.go          |  4 +-
 traffic_ops/client/fixtures/delivery_service.go | 20 ++++++-
 .../client/tests/delivery_service_test.go       | 59 ++++++++++++++++++++
 3 files changed, 79 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/d0121d17/traffic_ops/client/delivery_service.go
----------------------------------------------------------------------
diff --git a/traffic_ops/client/delivery_service.go b/traffic_ops/client/delivery_service.go
index da28590..7e716c3 100644
--- a/traffic_ops/client/delivery_service.go
+++ b/traffic_ops/client/delivery_service.go
@@ -227,14 +227,14 @@ func (to *Session) DeliveryServiceRouting(id string) (*DeliveryServiceRouting, e
 }
 
 // DeliveryServiceServer gets the DeliveryServiceServer
-func (to *Session) DeliveryServiceServer(page, limit string) (*[]DeliveryServiceServer, error) {
+func (to *Session) DeliveryServiceServer(page, limit string) ([]DeliveryServiceServer, error) {
 	var data DeliveryServiceServerResponse
 	err := get(to, deliveryServiceServerEp(page, limit), &data)
 	if err != nil {
 		return nil, err
 	}
 
-	return &data.Response, nil
+	return data.Response, nil
 }
 
 func get(to *Session, endpoint string, respStruct interface{}) error {

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/d0121d17/traffic_ops/client/fixtures/delivery_service.go
----------------------------------------------------------------------
diff --git a/traffic_ops/client/fixtures/delivery_service.go b/traffic_ops/client/fixtures/delivery_service.go
index d4fdd9b..98580d0 100644
--- a/traffic_ops/client/fixtures/delivery_service.go
+++ b/traffic_ops/client/fixtures/delivery_service.go
@@ -110,7 +110,7 @@ func DeliveryServiceCapacity() *client.DeliveryServiceCapacityResponse {
 
 // DeliveryServiceRouting returns a default DeliveryServiceRoutingResponse to be used for testing.
 func DeliveryServiceRouting() *client.DeliveryServiceRoutingResponse {
-	dsc := client.DeliveryServiceRouting{
+	dsr := client.DeliveryServiceRouting{
 		StaticRoute:       1,
 		Miss:              2,
 		Geo:               3.33,
@@ -123,6 +123,22 @@ func DeliveryServiceRouting() *client.DeliveryServiceRoutingResponse {
 	}
 
 	return &client.DeliveryServiceRoutingResponse{
-		Response: dsc,
+		Response: dsr,
+	}
+}
+
+// DeliveryServiceServer returns a default DeliveryServiceServerResponse to be used for testing.
+func DeliveryServiceServer() *client.DeliveryServiceServerResponse {
+	dss := client.DeliveryServiceServer{
+		LastUpdated:     "lastUpdated",
+		Server:          "someServer",
+		DeliveryService: "someService",
+	}
+
+	return &client.DeliveryServiceServerResponse{
+		Response: []client.DeliveryServiceServer{dss},
+		Page:     1,
+		OrderBy:  "foo",
+		Limit:    1,
 	}
 }

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/d0121d17/traffic_ops/client/tests/delivery_service_test.go
----------------------------------------------------------------------
diff --git a/traffic_ops/client/tests/delivery_service_test.go b/traffic_ops/client/tests/delivery_service_test.go
index 107a567..03273fe 100644
--- a/traffic_ops/client/tests/delivery_service_test.go
+++ b/traffic_ops/client/tests/delivery_service_test.go
@@ -355,3 +355,62 @@ func TestDeliveryServiceRoutingUnauthorized(t *testing.T) {
 		testHelper.Success(t, "Should not be able to make a request to Traffic Ops")
 	}
 }
+
+func TestDeliveryServiceServer(t *testing.T) {
+	resp := fixtures.DeliveryServiceServer()
+	server := testHelper.ValidHTTPServer(resp)
+	defer server.Close()
+
+	var httpClient http.Client
+	to := client.Session{
+		URL:       server.URL,
+		UserAgent: &httpClient,
+	}
+
+	testHelper.Context(t, "Given the need to test a successful Traffic Ops request for a DeliveryServiceServer")
+
+	s, err := to.DeliveryServiceServer("1", "1")
+	if err != nil {
+		testHelper.Error(t, "Should be able to make a request to Traffic Ops")
+	} else {
+		testHelper.Success(t, "Should be able to make a request to Traffic Ops")
+	}
+
+	if s[0].LastUpdated != "lastUpdated" {
+		testHelper.Error(t, "Should get back \"lastUpdated\" for \"LastUpdated\", got: %s", s[0].LastUpdated)
+	} else {
+		testHelper.Success(t, "Should get back \"lastUpdated\" for \"LastUpdated\"")
+	}
+
+	if s[0].Server != "someServer" {
+		testHelper.Error(t, "Should get back \"someServer\" for \"Server\", got: %s", s[0].Server)
+	} else {
+		testHelper.Success(t, "Should get back \"someServer\" for \"Server\"")
+	}
+
+	if s[0].DeliveryService != "someService" {
+		testHelper.Error(t, "Should get back \"someService\" for \"DeliveryService\", got: %s", s[0].DeliveryService)
+	} else {
+		testHelper.Success(t, "Should get back \"someService\" for \"DeliveryService\"")
+	}
+}
+
+func TestDeliveryServiceServerUnauthorized(t *testing.T) {
+	server := testHelper.InvalidHTTPServer(http.StatusUnauthorized)
+	defer server.Close()
+
+	var httpClient http.Client
+	to := client.Session{
+		URL:       server.URL,
+		UserAgent: &httpClient,
+	}
+
+	testHelper.Context(t, "Given the need to test a failed Traffic Ops request for a DeliveryServiceServer")
+
+	_, err := to.DeliveryServiceServer("1", "1")
+	if err == nil {
+		testHelper.Error(t, "Should not be able to make a request to Traffic Ops")
+	} else {
+		testHelper.Success(t, "Should not be able to make a request to Traffic Ops")
+	}
+}


[2/2] incubator-trafficcontrol git commit: add `DeliveryServiceServer` method

Posted by ne...@apache.org.
add `DeliveryServiceServer` method

Add a `DeliveryServiceServer` method to the `traffic_ops` client.


Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/a61ef2e8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/a61ef2e8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/a61ef2e8

Branch: refs/heads/master
Commit: a61ef2e8a18b4d4332ec83fe93e833b098d88561
Parents: 7182647
Author: Mike Ball <mi...@gmail.com>
Authored: Thu Oct 27 10:46:48 2016 -0400
Committer: Dave Neuman <ne...@apache.org>
Committed: Tue Nov 1 14:35:52 2016 -0600

----------------------------------------------------------------------
 traffic_ops/client/delivery_service.go          | 26 ++++++++++++++++++++
 .../client/delivery_service_endpoints.go        | 11 ++++++---
 .../client/delivery_service_endpoints_test.go   | 12 +++++++++
 3 files changed, 46 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/a61ef2e8/traffic_ops/client/delivery_service.go
----------------------------------------------------------------------
diff --git a/traffic_ops/client/delivery_service.go b/traffic_ops/client/delivery_service.go
index beea2ff..da28590 100644
--- a/traffic_ops/client/delivery_service.go
+++ b/traffic_ops/client/delivery_service.go
@@ -145,6 +145,21 @@ type DeliveryServiceRouting struct {
 	RegionalDenied    int     `json:"regionalDenied"`
 }
 
+// DeliveryServiceServerResponse ...
+type DeliveryServiceServerResponse struct {
+	Response []DeliveryServiceServer `json:"response"`
+	Page     int                     `json:"page"`
+	OrderBy  string                  `json:"orderby"`
+	Limit    int                     `json:"limit"`
+}
+
+// DeliveryServiceServer ...
+type DeliveryServiceServer struct {
+	LastUpdated     string `json:"lastUpdated"`
+	Server          string `json:"server"`
+	DeliveryService string `json:"deliveryService"`
+}
+
 // DeliveryServices gets an array of DeliveryServices
 func (to *Session) DeliveryServices() ([]DeliveryService, error) {
 	var data DeliveryServiceResponse
@@ -211,6 +226,17 @@ func (to *Session) DeliveryServiceRouting(id string) (*DeliveryServiceRouting, e
 	return &data.Response, nil
 }
 
+// DeliveryServiceServer gets the DeliveryServiceServer
+func (to *Session) DeliveryServiceServer(page, limit string) (*[]DeliveryServiceServer, error) {
+	var data DeliveryServiceServerResponse
+	err := get(to, deliveryServiceServerEp(page, limit), &data)
+	if err != nil {
+		return nil, err
+	}
+
+	return &data.Response, nil
+}
+
 func get(to *Session, endpoint string, respStruct interface{}) error {
 	resp, err := to.request(endpoint, nil)
 	if err != nil {

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/a61ef2e8/traffic_ops/client/delivery_service_endpoints.go
----------------------------------------------------------------------
diff --git a/traffic_ops/client/delivery_service_endpoints.go b/traffic_ops/client/delivery_service_endpoints.go
index 39779a4..862a727 100644
--- a/traffic_ops/client/delivery_service_endpoints.go
+++ b/traffic_ops/client/delivery_service_endpoints.go
@@ -15,14 +15,15 @@
 
 package client
 
-const dsPath = "/api/1.2/deliveryservices"
+const apiBase = "/api/1.2"
+const dsPath = "/deliveryservices"
 
 func deliveryServicesEp() string {
-	return dsPath + ".json"
+	return apiBase + dsPath + ".json"
 }
 
 func deliveryServiceBaseEp(id string) string {
-	return dsPath + "/" + id
+	return apiBase + dsPath + "/" + id
 }
 
 func deliveryServiceEp(id string) string {
@@ -44,3 +45,7 @@ func deliveryServiceCapacityEp(id string) string {
 func deliveryServiceRoutingEp(id string) string {
 	return deliveryServiceBaseEp(id) + "/routing.json"
 }
+
+func deliveryServiceServerEp(page, limit string) string {
+	return apiBase + "/deliveryserviceserver.json?page=" + page + "&limit=" + limit
+}

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/a61ef2e8/traffic_ops/client/delivery_service_endpoints_test.go
----------------------------------------------------------------------
diff --git a/traffic_ops/client/delivery_service_endpoints_test.go b/traffic_ops/client/delivery_service_endpoints_test.go
index 4ce98e8..93163af 100644
--- a/traffic_ops/client/delivery_service_endpoints_test.go
+++ b/traffic_ops/client/delivery_service_endpoints_test.go
@@ -92,3 +92,15 @@ func TestDeliveryServiceRoutingEp(t *testing.T) {
 		testHelper.Success(t, "Should be able to get the correct delivery service routing endpoint")
 	}
 }
+
+func TestDeliveryServiceServerEp(t *testing.T) {
+	testHelper.Context(t, "Given the need to test that DeliveryServiceServer uses the correct URL")
+
+	ep := deliveryServiceServerEp("1", "2")
+	expected := "/api/1.2/deliveryserviceserver.json?page=1&limit=2"
+	if ep != expected {
+		testHelper.Error(t, "Should get back %s for \"deliveryServiceServerEp\", got: %s", expected, ep)
+	} else {
+		testHelper.Success(t, "Should be able to get the correct delivery service server endpoint")
+	}
+}