You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by mi...@apache.org on 2017/01/10 03:38:17 UTC
[05/50] incubator-trafficcontrol git commit: add HardwareTest
add HardwareTest
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/9ca43617
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/9ca43617
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/9ca43617
Branch: refs/heads/master
Commit: 9ca43617820661b3d05973db98bef1818da3f944
Parents: 940d621
Author: David Neuman <da...@gmail.com>
Authored: Fri Dec 2 15:01:05 2016 -0700
Committer: Dan Kirkwood <da...@gmail.com>
Committed: Sun Jan 8 21:04:59 2017 -0700
----------------------------------------------------------------------
.../client/delivery_service_resources.go | 4 +-
.../tests/integration/deliveryservice_test.go | 11 +-
.../client/tests/integration/hardware_test.go | 105 +++++++++++++++++++
3 files changed, 109 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/9ca43617/traffic_ops/client/delivery_service_resources.go
----------------------------------------------------------------------
diff --git a/traffic_ops/client/delivery_service_resources.go b/traffic_ops/client/delivery_service_resources.go
index 32f2ff3..26d64d8 100644
--- a/traffic_ops/client/delivery_service_resources.go
+++ b/traffic_ops/client/delivery_service_resources.go
@@ -188,9 +188,9 @@ type DeliveryServiceRouting struct {
// DeliveryServiceServerResponse ...
type DeliveryServiceServerResponse struct {
Response []DeliveryServiceServer `json:"response"`
- Size string `json:"size"`
+ Size int `json:"size"`
OrderBy string `json:"orderby"`
- Limit string `json:"limit"`
+ Limit int `json:"limit"`
}
// DeliveryServiceServer ...
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/9ca43617/traffic_ops/client/tests/integration/deliveryservice_test.go
----------------------------------------------------------------------
diff --git a/traffic_ops/client/tests/integration/deliveryservice_test.go b/traffic_ops/client/tests/integration/deliveryservice_test.go
index bffa769..4b56058 100644
--- a/traffic_ops/client/tests/integration/deliveryservice_test.go
+++ b/traffic_ops/client/tests/integration/deliveryservice_test.go
@@ -40,13 +40,6 @@ func init() {
os.Exit(1)
}
- // existingTestDS, err := GetDeliveryService()
- // if err != nil {
- // fmt.Printf("Deliverservice_test init -- Could not get Deliveryservices from TO...%v\n", err)
- // os.Exit(1)
- // }
- // existingTestDSID = strconv.Itoa(existingTestDS.ID)
-
//create DeliveryService object for testing
testDs.Active = false
testDs.CCRDNSTTL = 30
@@ -329,7 +322,7 @@ func TestDeliveryServiceCapacity(t *testing.T) {
t.Errorf("Could not ge Deliveryserivce Capacity for %s reponse was: %v\n", existingTestDSID, err)
}
- if apiDsCapacity.AvailablePercent != clientDsCapacity.AvailablePercent {
+ if fmt.Sprintf("%6.5f", apiDsCapacity.AvailablePercent) != fmt.Sprintf("%6.5f", clientDsCapacity.AvailablePercent) {
t.Errorf("AvailablePercent -- Expected %v got %v", apiDsCapacity.AvailablePercent, clientDsCapacity.AvailablePercent)
}
@@ -337,7 +330,7 @@ func TestDeliveryServiceCapacity(t *testing.T) {
t.Errorf("MaintenenancePercent -- Expected %v got %v", apiDsCapacity.MaintenancePercent, clientDsCapacity.MaintenancePercent)
}
- if apiDsCapacity.UnavailablePercent != clientDsCapacity.UnavailablePercent {
+ if fmt.Sprintf("%6.5f", apiDsCapacity.UnavailablePercent) != fmt.Sprintf("%6.5f", clientDsCapacity.UnavailablePercent) {
t.Errorf("UnavailablePercent -- Expected %v got %v", apiDsCapacity.UnavailablePercent, clientDsCapacity.UnavailablePercent)
}
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/9ca43617/traffic_ops/client/tests/integration/hardware_test.go
----------------------------------------------------------------------
diff --git a/traffic_ops/client/tests/integration/hardware_test.go b/traffic_ops/client/tests/integration/hardware_test.go
new file mode 100644
index 0000000..6c7fb47
--- /dev/null
+++ b/traffic_ops/client/tests/integration/hardware_test.go
@@ -0,0 +1,105 @@
+package integration
+
+import (
+ // "encoding/json"
+ "encoding/json"
+ "testing"
+
+ traffic_ops "github.com/apache/incubator-trafficcontrol/traffic_ops/client"
+)
+
+func TestHardware(t *testing.T) {
+ resp, err := Request(*to, "GET", "/api/1.2/hwinfo.json", nil)
+ if err != nil {
+ t.Errorf("Could not get hardware.json reponse was: %v\n", err)
+ t.FailNow()
+ }
+
+ defer resp.Body.Close()
+ var apiHwRes traffic_ops.HardwareResponse
+ if err := json.NewDecoder(resp.Body).Decode(&apiHwRes); err != nil {
+ t.Errorf("Could not decode hwinfo json. Error is: %v\n", err)
+ t.FailNow()
+ }
+ apiHardware := apiHwRes.Response
+
+ clientHardware, err := to.Hardware(0)
+ if err != nil {
+ t.Errorf("Could not get Hardware from client. Error is: %v\n", err)
+ t.FailNow()
+ }
+
+ if len(apiHardware) != len(clientHardware) {
+ t.Errorf("Hardware Response Length -- expected %v, got %v\n", len(apiHardware), len(clientHardware))
+ }
+
+ for _, apiHw := range apiHardware {
+ match := false
+ for _, clientHw := range clientHardware {
+ if apiHw.HostName == clientHw.HostName && apiHw.Description == clientHw.Description {
+ match = true
+ compareHw(apiHw, clientHw, t)
+ }
+ }
+ if !match {
+ t.Errorf("No hardware information returned from client for %s\n", apiHw.HostName)
+ }
+ }
+}
+
+func TestHardwareWithLimit(t *testing.T) {
+ resp, err := Request(*to, "GET", "/api/1.2/hwinfo.json?limit=10", nil)
+ if err != nil {
+ t.Errorf("Could not get hwinfo.json reponse was: %v\n", err)
+ t.FailNow()
+ }
+
+ defer resp.Body.Close()
+ var apiHwRes traffic_ops.HardwareResponse
+ if err := json.NewDecoder(resp.Body).Decode(&apiHwRes); err != nil {
+ t.Errorf("Could not decode hwinfo json. Error is: %v\n", err)
+ t.FailNow()
+ }
+ apiHardware := apiHwRes.Response
+
+ clientHardware, err := to.Hardware(10)
+ if err != nil {
+ t.Errorf("Could not get Hardware from client. Error is: %v\n", err)
+ t.FailNow()
+ }
+
+ if len(apiHardware) != len(clientHardware) {
+ t.Errorf("Hardware Response Length -- expected %v, got %v\n", len(apiHardware), len(clientHardware))
+ }
+
+ for _, apiHw := range apiHardware {
+ match := false
+ for _, clientHw := range clientHardware {
+ if apiHw.HostName == clientHw.HostName && apiHw.Description == clientHw.Description {
+ match = true
+ compareHw(apiHw, clientHw, t)
+ }
+ }
+ if !match {
+ t.Errorf("No hardware information returned from client for %s\n", apiHw.HostName)
+ }
+ }
+}
+
+func compareHw(hw1 traffic_ops.Hardware, hw2 traffic_ops.Hardware, t *testing.T) {
+ if hw1.Description != hw2.Description {
+ t.Errorf("Description -- Expected %v, got %v", hw1.Description, hw2.Description)
+ }
+ if hw1.HostName != hw2.HostName {
+ t.Errorf("HostName -- Expected %v, got %v", hw1.HostName, hw2.HostName)
+ }
+ if hw1.ID != hw2.ID {
+ t.Errorf("ID -- Expected %v, got %v", hw1.ID, hw2.ID)
+ }
+ if hw1.LastUpdated != hw2.LastUpdated {
+ t.Errorf("LastUpdated -- Expected %v, got %v", hw1.LastUpdated, hw2.LastUpdated)
+ }
+ if hw1.Value != hw2.Value {
+ t.Errorf("Value -- Expected %v, got %v", hw1.Value, hw2.Value)
+ }
+}