added test for type

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

Branch: refs/heads/psql-rebase
Commit: a2edbb9a310bdd6f5afa5844e86c844781d47b2e
Parents: 8dbf70d
Author: David Neuman <david.neuma...@gmail.com>
Authored: Tue Dec 6 16:08:29 2016 -0700
Committer: Dave Neuman <neu...@apache.org>
Committed: Wed Dec 7 10:32:25 2016 -0700

----------------------------------------------------------------------
 .../client/tests/integration/type_test.go       | 58 ++++++++++++++++++++
 1 file changed, 58 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/a2edbb9a/traffic_ops/client/tests/integration/type_test.go
----------------------------------------------------------------------
diff --git a/traffic_ops/client/tests/integration/type_test.go 
b/traffic_ops/client/tests/integration/type_test.go
new file mode 100644
index 0000000..6dd0c94
--- /dev/null
+++ b/traffic_ops/client/tests/integration/type_test.go
@@ -0,0 +1,58 @@
+package integration
+
+import (
+       "encoding/json"
+       "fmt"
+       "testing"
+
+       traffic_ops 
"github.com/apache/incubator-trafficcontrol/traffic_ops/client"
+)
+
+func TestTypes(t *testing.T) {
+
+       uri := fmt.Sprintf("/api/1.2/types.json")
+       resp, err := Request(*to, "GET", uri, nil)
+       if err != nil {
+               t.Errorf("Could not get %s reponse was: %v\n", uri, err)
+               t.FailNow()
+       }
+
+       defer resp.Body.Close()
+       var apiTypeRes traffic_ops.TypeResponse
+       if err := json.NewDecoder(resp.Body).Decode(&apiTypeRes); err != nil {
+               t.Errorf("Could not decode type json.  Error is: %v\n", err)
+               t.FailNow()
+       }
+       apiTypes := apiTypeRes.Response
+
+       clientTypes, err := to.Types()
+       if err != nil {
+               t.Errorf("Could not get types from client.  Error is: %v\n", 
err)
+               t.FailNow()
+       }
+
+       if len(apiTypes) != len(clientTypes) {
+               t.Errorf("Types Response Length -- expected %v, got %v\n", 
len(apiTypes), len(clientTypes))
+       }
+
+       for _, apiType := range apiTypes {
+               match := false
+               for _, clientType := range clientTypes {
+                       if apiType.ID == clientType.ID {
+                               match = true
+                               if apiType.Description != 
clientType.Description {
+                                       t.Errorf("Description -- Expected %v, 
got %v\n", apiType.Description, clientType.Description)
+                               }
+                               if apiType.Name != clientType.Name {
+                                       t.Errorf("Name -- Expected %v, got 
%v\n", apiType.Name, clientType.Name)
+                               }
+                               if apiType.UseInTable != clientType.UseInTable {
+                                       t.Errorf("UseInTable -- Expected %v, 
got %v\n", apiType.UseInTable, clientType.UseInTable)
+                               }
+                       }
+               }
+               if !match {
+                       t.Errorf("Did not get a type matching %v\n", 
apiType.Name)
+               }
+       }
+}

Reply via email to