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:37 UTC
[25/50] incubator-trafficcontrol git commit: added user test
added user test
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/f706d994
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/f706d994
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/f706d994
Branch: refs/heads/master
Commit: f706d994ee6e754879089a0746cf8b454e6d4341
Parents: 18efd3d
Author: David Neuman <da...@gmail.com>
Authored: Tue Dec 6 16:08:55 2016 -0700
Committer: Dan Kirkwood <da...@gmail.com>
Committed: Sun Jan 8 21:05:00 2017 -0700
----------------------------------------------------------------------
.../client/tests/integration/user_test.go | 52 ++++++++++++++++++++
traffic_ops/client/user.go | 3 +-
2 files changed, 54 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/f706d994/traffic_ops/client/tests/integration/user_test.go
----------------------------------------------------------------------
diff --git a/traffic_ops/client/tests/integration/user_test.go b/traffic_ops/client/tests/integration/user_test.go
new file mode 100644
index 0000000..b0f6ab7
--- /dev/null
+++ b/traffic_ops/client/tests/integration/user_test.go
@@ -0,0 +1,52 @@
+package integration
+
+import (
+ "encoding/json"
+ "fmt"
+ "testing"
+
+ traffic_ops "github.com/apache/incubator-trafficcontrol/traffic_ops/client"
+)
+
+func TestUsers(t *testing.T) {
+
+ uri := fmt.Sprintf("/api/1.2/users.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 apiUserRes traffic_ops.UserResponse
+ if err := json.NewDecoder(resp.Body).Decode(&apiUserRes); err != nil {
+ t.Errorf("Could not decode user json. Error is: %v\n", err)
+ t.FailNow()
+ }
+ apiUsers := apiUserRes.Response
+
+ clientUsers, err := to.Users()
+ if err != nil {
+ t.Errorf("Could not get users from client. Error is: %v\n", err)
+ t.FailNow()
+ }
+
+ if len(apiUsers) != len(clientUsers) {
+ t.Errorf("Users Response Length -- expected %v, got %v\n", len(apiUsers), len(clientUsers))
+ }
+
+ for _, apiUser := range apiUsers {
+ match := false
+ for _, clientUser := range clientUsers {
+ if apiUser.ID == clientUser.ID {
+ match = true
+ if apiUser != clientUser {
+ t.Errorf("apiUser and clientUser do not match! Expected %+v, got %+v\n", apiUser, clientUser)
+ }
+ }
+ }
+ if !match {
+ t.Errorf("Did not get a user matching %v\n", apiUser.Email)
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/f706d994/traffic_ops/client/user.go
----------------------------------------------------------------------
diff --git a/traffic_ops/client/user.go b/traffic_ops/client/user.go
index 8f8cca2..3534c77 100644
--- a/traffic_ops/client/user.go
+++ b/traffic_ops/client/user.go
@@ -28,6 +28,7 @@ type User struct {
PublicSSHKey string `json:"publicSshKey,omitempty"`
Role int `json:"role,omitempty"`
RoleName string `json:"rolename,omitempty"`
+ ID int `json:"id,omitempty"`
UID int `json:"uid,omitempty"`
GID int `json:"gid,omitempty"`
Company string `json:"company,omitempty"`
@@ -47,7 +48,7 @@ func (to *Session) Users() ([]User, error) {
resp.Body.Close()
var data UserResponse
- if err := json.NewDecoder(resp.Body).Decode(&data.Response); err != nil {
+ if err := json.NewDecoder(resp.Body).Decode(&data); err != nil {
return nil, err
}