You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by el...@apache.org on 2018/07/06 17:16:15 UTC

[trafficcontrol] 02/03: Add TO Go user/current client funcs, test

This is an automated email from the ASF dual-hosted git repository.

elsloo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git

commit 91f4ed116571136a6333bcfba6abecd61e708013
Author: Robert Butts <ro...@apache.org>
AuthorDate: Fri Jun 29 15:43:42 2018 -0600

    Add TO Go user/current client funcs, test
---
 lib/go-tc/users.go                       |  4 ++
 traffic_ops/client/v13/user.go           | 13 ++++++-
 traffic_ops/testing/api/v13/user_test.go | 64 ++++++++++++++++++++++++++++++++
 3 files changed, 80 insertions(+), 1 deletion(-)

diff --git a/lib/go-tc/users.go b/lib/go-tc/users.go
index 43a2ee1..728908c 100644
--- a/lib/go-tc/users.go
+++ b/lib/go-tc/users.go
@@ -116,3 +116,7 @@ type UserCurrent struct {
 	UID             *int    `json:"uid,omitempty"`
 	UserName        *string `json:"username,omitempty"`
 }
+
+type UserCurrentResponse struct {
+	Response UserCurrent `json:"response"`
+}
diff --git a/traffic_ops/client/v13/user.go b/traffic_ops/client/v13/user.go
index ac8ff5b..0102498 100644
--- a/traffic_ops/client/v13/user.go
+++ b/traffic_ops/client/v13/user.go
@@ -18,7 +18,7 @@ package v13
 import (
 	"encoding/json"
 
-	tc "github.com/apache/trafficcontrol/lib/go-tc"
+	"github.com/apache/trafficcontrol/lib/go-tc"
 )
 
 // Users gets an array of Users.
@@ -44,3 +44,14 @@ func (to *Session) GetUsers() ([]tc.User, ReqInf, error) {
 
 	return data.Response, reqInf, nil
 }
+
+// GetUserCurrent gets information about the current user
+func (to *Session) GetUserCurrent() (*tc.UserCurrent, ReqInf, error) {
+	url := apiBase + `/user/current`
+	resp := tc.UserCurrentResponse{}
+	reqInf, err := get(to, url, &resp)
+	if err != nil {
+		return nil, reqInf, err
+	}
+	return &resp.Response, reqInf, nil
+}
diff --git a/traffic_ops/testing/api/v13/user_test.go b/traffic_ops/testing/api/v13/user_test.go
new file mode 100644
index 0000000..abe8bbf
--- /dev/null
+++ b/traffic_ops/testing/api/v13/user_test.go
@@ -0,0 +1,64 @@
+package v13
+
+/*
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+*/
+
+import (
+	"testing"
+
+	"github.com/apache/trafficcontrol/lib/go-log"
+)
+
+func TestUsers(t *testing.T) {
+	CreateTestCDNs(t)
+	CreateTestTypes(t)
+	CreateTestProfiles(t)
+	CreateTestStatuses(t)
+	CreateTestDivisions(t)
+	CreateTestRegions(t)
+	CreateTestPhysLocations(t)
+	CreateTestCacheGroups(t)
+	CreateTestServers(t)
+	CreateTestDeliveryServices(t)
+
+	GetTestUserCurrent(t)
+
+	DeleteTestDeliveryServices(t)
+	DeleteTestServers(t)
+	DeleteTestCacheGroups(t)
+	DeleteTestPhysLocations(t)
+	DeleteTestRegions(t)
+	DeleteTestDivisions(t)
+	DeleteTestStatuses(t)
+	DeleteTestProfiles(t)
+	DeleteTestTypes(t)
+	DeleteTestCDNs(t)
+
+}
+
+const SessionUserName = "admin" // TODO make dynamic?
+
+func GetTestUserCurrent(t *testing.T) {
+	log.Debugln("GetTestUserCurrent")
+	user, _, err := TOSession.GetUserCurrent()
+	if err != nil {
+		t.Fatalf("cannot GET current user: %v\n", err)
+	}
+	if user.UserName == nil {
+		t.Fatalf("current user expected: %v actual: %v\n", SessionUserName, nil)
+	}
+	if *user.UserName != SessionUserName {
+		t.Fatalf("current user expected: %v actual: %v\n", SessionUserName, *user.UserName)
+	}
+}