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/18efd3d4 Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/18efd3d4 Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/18efd3d4 Branch: refs/heads/master Commit: 18efd3d49a7e008123328dcf4254d64430355b7c Parents: 57225e9 Author: David Neuman <david.neuma...@gmail.com> Authored: Tue Dec 6 16:08:29 2016 -0700 Committer: Dan Kirkwood <dang...@gmail.com> Committed: Sun Jan 8 21:05:00 2017 -0700 ---------------------------------------------------------------------- .../client/tests/integration/type_test.go | 58 ++++++++++++++++++++ 1 file changed, 58 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/18efd3d4/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) + } + } +}