Commit d15f5f73 by cnam

Merge branch 'tests' into 'master'

Tests

See merge request !108
2 parents 4d6d46df 86c02e1f
Pipeline #7588430 passed
in 62 minutes 21 seconds
Showing with 1519 additions and 2067 deletions
image: cnam/make-builder:latest
variables:
DOCKER_DRIVER: overlay
services:
- docker:dind
stages:
- build
build:
stage: build
after_script:
- make clean
tags:
- docker
script:
- make test release IMAGE=registry.gitlab.com/leanlabsio/kanban TAG=${CI_BUILD_REF:0:12} REGISTRY_USERNAME=gitlab-ci-token REGISTRY_PASSWORD=$CI_BUILD_TOKEN
......@@ -2,44 +2,53 @@
"ImportPath": "gitlab.com/leanlabsio/kanban",
"GoVersion": "go1.8",
"GodepVersion": "v79",
"Packages": [
"./..."
],
"Deps": [
{
"ImportPath": "github.com/BurntSushi/toml",
"Comment": "v0.1.0-23-g5c4df71",
"Rev": "5c4df71dfe9ac89ef6287afc05e4c1b16ae65a1e"
"ImportPath": "github.com/Unknwon/com",
"Comment": "v1-12-g0db4a62",
"Rev": "0db4a625e949e956314d7d1adea9bf82384cc10c"
},
{
"ImportPath": "github.com/Unknwon/com",
"Rev": "28b053d5a2923b87ce8c5a08f3af779894a72758"
"ImportPath": "github.com/davecgh/go-spew/spew",
"Rev": "5215b55f46b2b919f50a1df0eaa5886afe4e3b3d"
},
{
"ImportPath": "github.com/dgrijalva/jwt-go",
"Comment": "v2.4.0-4-gafef698",
"Rev": "afef698c326bfd906b11659432544e5aae441d44"
"Comment": "v2.3.0-4-gc1da563",
"Rev": "c1da56349675b292d3200463e2c88b9aa5e02391"
},
{
"ImportPath": "github.com/elazarl/go-bindata-assetfs",
"Rev": "57eb5e1fc594ad4b0b1dbea7b286d299e0cb43c2"
"Rev": "30f82fa23fd844bd5bb1e5f216db87fd77b5eb43"
},
{
"ImportPath": "github.com/fsnotify/fsnotify",
"Comment": "v1.3.0",
"Rev": "30411dbcefb7a1da7e84f75530ad3abe4011b4f8"
},
{
"ImportPath": "github.com/go-macaron/bindata",
"Rev": "de74a053830c7d338bf209adf3b711c969f63e59"
"Rev": "85786f57eee3e5544a9cc24fa2afe425b97a8652"
},
{
"ImportPath": "github.com/go-macaron/binding",
"Rev": "2502aaf4bce3a4e6451b4610847bfb8dffdb6266"
"Rev": "677c5a4c2f0568d129a40004071d79ee1a06defb"
},
{
"ImportPath": "github.com/go-macaron/inject",
"Rev": "c5ab7bf3a307593cd44cb272d1a5beea473dd072"
"Rev": "d8a0b8677191f4380287cfebd08e462217bac7ad"
},
{
"ImportPath": "github.com/google/go-querystring/query",
"Rev": "2a60fc2ba6c19de80291203597d752e9ba58e4c0"
"Rev": "547ef5ac979778feb2f760cdb5f4eae1a2207b86"
},
{
"ImportPath": "github.com/gorilla/websocket",
"Rev": "3986be78bf859e01f01af631ad76da5b269d270c"
"Comment": "v1.1.0-27-gb258b4f",
"Rev": "b258b4fadb573ac412f187b9f31974ea99d32f50"
},
{
"ImportPath": "github.com/hashicorp/hcl",
......@@ -82,50 +91,72 @@
"Rev": "76626ae9c91c4f2a10f34cad8ce83ea42c93bb75"
},
{
"ImportPath": "github.com/kr/pretty",
"Comment": "go.weekly.2011-12-22-27-ge6ac2fc",
"Rev": "e6ac2fc51e89a3249e82157fa0bb7a18ef9dd5bb"
},
{
"ImportPath": "github.com/kr/text",
"Rev": "bb797dc4fb8320488f47bf11de07a733d7233e1f"
},
{
"ImportPath": "github.com/leanlabsio/sockets",
"Rev": "555ea7145f564a420c51194bb8b91eef028c7437"
},
{
"ImportPath": "github.com/magiconair/properties",
"Comment": "v1.6.0-1-gc81f9d7",
"Rev": "c81f9d71af8f8cba1466501d30326b99a4e56c19"
"Comment": "v1.7.0",
"Rev": "c265cfa48dda6474e208715ca93e987829f572f8"
},
{
"ImportPath": "github.com/mitchellh/mapstructure",
"Rev": "281073eb9eb092240d33ef253c404f1cca550309"
"Rev": "d2dd0262208475919e1a362f675cfc0e7c10e905"
},
{
"ImportPath": "github.com/pelletier/go-buffruneio",
"Rev": "c37440a7cf42ac63b919c752ca73a85067e05992"
},
{
"ImportPath": "github.com/pelletier/go-toml",
"Comment": "v0.4.0-13-g13d49d4",
"Rev": "13d49d4606eb801b8f01ae542b4afc4c6ee3d84a"
},
{
"ImportPath": "github.com/pmezard/go-difflib/difflib",
"Rev": "792786c7400a136282c1664665ae0a8db921c6c2"
},
{
"ImportPath": "github.com/spf13/afero",
"Rev": "9be650865eab0c12963d8753212f4f9c66cdcf12"
},
{
"ImportPath": "github.com/spf13/afero/mem",
"Rev": "9be650865eab0c12963d8753212f4f9c66cdcf12"
},
{
"ImportPath": "github.com/spf13/cast",
"Rev": "ee7b3e0353166ab1f3a605294ac8cd2b77953778"
"Comment": "v1.0.0",
"Rev": "ce135a4ebeee6cfe9a26c93ee0d37825f26113c7"
},
{
"ImportPath": "github.com/spf13/cobra",
"Rev": "8e91712f174ced10270cf66615e0a9127e7c4de5"
"Rev": "fcd0c5a1df88f5d6784cb4feead962c3f3d0b66c"
},
{
"ImportPath": "github.com/spf13/jwalterweatherman",
"Rev": "d00654080cddbd2b082acaa74007cb94a2b40866"
"Rev": "fa7ca7e836cf3a8bb4ebf799f472c12d7e903d66"
},
{
"ImportPath": "github.com/spf13/pflag",
"Rev": "7f60f83a2c81bc3c3c0d5297f61ddfa68da9d3b7"
"Rev": "9ff6c6923cfffbcd502984b8e0c80539a94968b7"
},
{
"ImportPath": "github.com/spf13/viper",
"Rev": "a212099cbe6fbe8d07476bfda8d2d39b6ff8f325"
"Rev": "7538d73b4eb9511d85a9f1dfef202eeb8ac260f4"
},
{
"ImportPath": "github.com/stretchr/testify/assert",
"Comment": "v1.1.3-18-g8d64eb7",
"Rev": "8d64eb7173c7753d6419fd4a9caf057398611364"
},
{
"ImportPath": "golang.org/x/crypto/pbkdf2",
"Rev": "40541ccb1c6e64c947ed6f606b8a6cb4b67d7436"
},
{
"ImportPath": "golang.org/x/net/context",
"Rev": "c92cdcb05f66ce5b61460e23498d2dc5fcf69aaf"
"Rev": "f2499483f923065a842d38eb4c7f1927e6fc6e6d"
},
{
"ImportPath": "golang.org/x/oauth2",
......@@ -136,22 +167,30 @@
"Rev": "ad0128250e8fba646a92ca9129716e523d63ef9f"
},
{
"ImportPath": "gopkg.in/bsm/ratelimit.v1",
"Rev": "f14ad9c78b155f69b480cfa41cb655259baac260"
"ImportPath": "golang.org/x/sys/unix",
"Rev": "d4feaf1a7e61e1d9e79e6c4e76c6349e9cab0a03"
},
{
"ImportPath": "golang.org/x/text/transform",
"Rev": "1b466db55e0ba5d56ef5315c728216b42f796491"
},
{
"ImportPath": "gopkg.in/fsnotify.v1",
"Comment": "v1.2.9",
"Rev": "8611c35ab31c1c28aa903d33cf8b6e44a399b09e"
"ImportPath": "golang.org/x/text/unicode/norm",
"Rev": "1b466db55e0ba5d56ef5315c728216b42f796491"
},
{
"ImportPath": "gopkg.in/bsm/ratelimit.v1",
"Rev": "bda20d5067a03094fc6762f7ead53027afac5f28"
},
{
"ImportPath": "gopkg.in/ini.v1",
"Comment": "v1.8.6",
"Rev": "afbd495e5aaea13597b5e14fe514ddeaa4d76fc3"
"Comment": "v1.25.2",
"Rev": "74bdc99692c3408cb103221e38675ce8fda0a718"
},
{
"ImportPath": "gopkg.in/macaron.v1",
"Rev": "564f398778297b0b083aaa070dda26e217f1e6b3"
"Comment": "v1.2.1",
"Rev": "a325110f8b392bce3e5cdeb8c44bf98078ada3be"
},
{
"ImportPath": "gopkg.in/redis.v3",
......@@ -180,7 +219,7 @@
},
{
"ImportPath": "gopkg.in/yaml.v2",
"Rev": "f7716cbe52baa25d2e9b0d0da546fcf909fc16b4"
"Rev": "a83829b6f1293c91addabc89d0571c246397bbf4"
}
]
}
REGISTRY_HOST = registry.gitlab.com
IMAGE = leanlabs/kanban
TAG = 1.7.1
CWD = /go/src/gitlab.com/leanlabsio/kanban
PACKAGES := `docker run --rm \
-v $(CURDIR):$(CWD) \
-w $(CWD) \
golang:1.8-alpine go list ./... | grep -v '/vendor/'`
all: clean
test:
@docker run -d -P --name selenium-hub selenium/hub:2.47.1
@docker run -d --link selenium-hub:hub selenium/node-chrome:2.47.1
@docker run -d --link selenium-hub:hub selenium/node-firefox:2.47.1
@docker run -d -P $(IMAGE):$(TAG)
@protractor $(CURDIR)/tests/e2e.conf.js
test: rel/kanban_x86_64_linux
@docker run --rm \
-v $(CURDIR):$(CWD) \
-w $(CWD) \
golang:1.8-alpine go test $(PACKAGES)
node_modules/: package.json
@docker run --rm \
......@@ -67,15 +71,30 @@ rel/kanban_x86_64_darwin: clean build templates/templates.go web/web.go $(find $
--entrypoint=/usr/local/go/bin/go \
golang:1.8.0 build -ldflags "-X main.AppVer=$(TAG) -s" -v -o $@
release: rel/kanban_x86_64_linux
login:
@docker login -u $(REGISTRY_USERNAME) -p $(REGISTRY_PASSWORD) $(REGISTRY_HOST)
release: login rel/kanban_x86_64_linux
@docker build -t $(IMAGE) .
@docker tag $(IMAGE):latest $(IMAGE):$(TAG)
@docker push $(IMAGE):latest
@docker push $(IMAGE):$(TAG)
clean:
@rm -rf web/
@rm -f templates/templates.go
@-docker run \
-v $(CURDIR):$(CWD) \
-w $(CWD) \
alpine:3.4 rm -rf web/
@-docker run \
-v $(CURDIR):$(CWD) \
-w $(CWD) \
alpine:3.4 rm -f templates/templates.go
@-docker run \
-v $(CURDIR):$(CWD) \
-w $(CWD) \
alpine:3.4 rm -rf rel node_modules
# Development targets
dev_redis:
......
......@@ -7,13 +7,13 @@ import (
)
type GitLabDataSource struct {
client *gitlabclient.GitlabContext
client *gitlabclient.Client
db *redis.Client
}
// New create new gitlab datasource instance
func New(t *oauth2.Token, pt string, r *redis.Client) GitLabDataSource {
c := gitlabclient.NewContext(t, pt)
c := gitlabclient.NewClient(t, pt)
return GitLabDataSource{client: c, db: r}
}
......@@ -6,12 +6,13 @@ import (
"encoding/json"
"errors"
"fmt"
"strings"
"time"
"github.com/dgrijalva/jwt-go"
"github.com/spf13/viper"
"gitlab.com/leanlabsio/kanban/modules/gitlab"
"golang.org/x/oauth2"
"strings"
"time"
)
type User struct {
......@@ -82,7 +83,7 @@ func LoadByToken(u *User, provider string) (*User, error) {
var user *User
switch provider {
case "gitlab":
c := gitlab.NewContext(u.Credential["gitlab"].Token, u.Credential["gitlab"].PrivateToken)
c := gitlab.NewClient(u.Credential["gitlab"].Token, u.Credential["gitlab"].PrivateToken)
r, err := c.CurrentUser()
if err != nil {
......
......@@ -14,7 +14,7 @@ type Config struct {
Oauth2 *oauth2.Config
}
type GitlabContext struct {
type Client struct {
client *http.Client
}
......@@ -63,10 +63,10 @@ func Exchange(c string) (*oauth2.Token, error) {
return cfg.Oauth2.Exchange(defaultContext(), c)
}
// NewContext
func NewContext(t *oauth2.Token, pt string) *GitlabContext {
// NewClient creates new client for usage gitlab api
func NewClient(t *oauth2.Token, pt string) *Client {
if pt != "" {
return &GitlabContext{
return &Client{
client: &http.Client{
Transport: &Transport{
Base: &http.Transport{
......@@ -78,7 +78,7 @@ func NewContext(t *oauth2.Token, pt string) *GitlabContext {
}
}
return &GitlabContext{
return &Client{
client: cfg.Oauth2.Client(defaultContext(), t),
}
}
......
package gitlab
import (
"net/http"
"net/http/httptest"
"golang.org/x/oauth2"
)
var (
mux *http.ServeMux
server *httptest.Server
)
func setup() (*Client, func(), error) {
mux = http.NewServeMux()
server = httptest.NewServer(mux)
teardown := func() {
server.Close()
}
NewEngine(&Config{
BasePath: server.URL,
})
c := NewClient(&oauth2.Token{}, "qwerty")
return c, teardown, nil
}
......@@ -37,7 +37,7 @@ type CommentRequest struct {
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/notes.html#list-project-issue-notes
func (g *GitlabContext) ListComments(project_id, issue_id string, o *ListOptions) ([]*Comment, error) {
func (g *Client) ListComments(project_id, issue_id string, o *ListOptions) ([]*Comment, error) {
path := getUrl([]string{"projects", url.QueryEscape(project_id), "issues", issue_id, "notes"})
u, err := addOptions(path, o)
if err != nil {
......@@ -76,7 +76,7 @@ func (p commentSlice) Swap(i, j int) {
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/notes.html#create-new-issue-note
func (g *GitlabContext) CreateComment(project_id, issue_id string, com *CommentRequest) (*Comment, *http.Response, error) {
func (g *Client) CreateComment(project_id, issue_id string, com *CommentRequest) (*Comment, *http.Response, error) {
path := []string{"projects", url.QueryEscape(project_id), "issues", issue_id, "notes"}
req, _ := g.NewRequest("POST", path, com)
......
......@@ -19,7 +19,7 @@ type File struct {
// UploadFile uploads file to gitlab project
//
// Gitlab API docs: http://docs.gitlab.com/ee/api/projects.html#upload-a-file
func (g *GitlabContext) UploadFile(projectID, name string, file io.Reader) (*File, error) {
func (g *Client) UploadFile(projectID, name string, file io.Reader) (*File, error) {
path := getUrl([]string{"projects", projectID, "uploads"})
body := new(bytes.Buffer)
......
......@@ -62,7 +62,7 @@ type IssueListOptions struct {
// takes pagination parameters page and per_page to restrict the list of issues.
//
// GitLab API docs: http://doc.gitlab.com/ce/api/issues.html#list-issues
func (g *GitlabContext) ListIssues(projectID string, o *IssueListOptions) ([]*Issue, *CollectionOptions, error) {
func (g *Client) ListIssues(projectID string, o *IssueListOptions) ([]*Issue, *CollectionOptions, error) {
path := getUrl([]string{"projects", url.QueryEscape(projectID), "issues"})
u, err := addOptions(path, o)
if err != nil {
......@@ -83,7 +83,7 @@ func (g *GitlabContext) ListIssues(projectID string, o *IssueListOptions) ([]*Is
// CreateIssue creates a new project issue.
//
// GitLab API docs: http://doc.gitlab.com/ce/api/issues.html#new-issues
func (g *GitlabContext) CreateIssue(project_id string, issue *IssueRequest) (*Issue, *http.Response, error) {
func (g *Client) CreateIssue(project_id string, issue *IssueRequest) (*Issue, *http.Response, error) {
path := []string{"projects", url.QueryEscape(project_id), "issues"}
req, _ := g.NewRequest("POST", path, issue)
......@@ -99,7 +99,7 @@ func (g *GitlabContext) CreateIssue(project_id string, issue *IssueRequest) (*Is
// to mark an issue as closed.
//
// GitLab API docs: http://doc.gitlab.com/ce/api/issues.html#edit-issues
func (g *GitlabContext) UpdateIssue(project_id, issue_id string, issue *IssueRequest) (*Issue, *http.Response, error) {
func (g *Client) UpdateIssue(project_id, issue_id string, issue *IssueRequest) (*Issue, *http.Response, error) {
path := []string{"projects", url.QueryEscape(project_id), "issues", issue_id}
req, _ := g.NewRequest("PUT", path, issue)
......@@ -114,7 +114,7 @@ func (g *GitlabContext) UpdateIssue(project_id, issue_id string, issue *IssueReq
// MoveAnIssue Moves an issue to a different project.
//
// Gitlab API docs: https://docs.gitlab.com/ee/api/issues.html#move-an-issue
func (g *GitlabContext) MoveAnIssue(projectID, issueID, toProjectId string) (*Issue, *http.Response, error) {
func (g *Client) MoveAnIssue(projectID, issueID, toProjectId string) (*Issue, *http.Response, error) {
body := MoveIssueRequest{
ToProjectID: toProjectId,
......
......@@ -34,7 +34,7 @@ type LabelDeleteOptions struct {
// ListLabels gets all labels for given project.
//
// GitLab API docs: http://doc.gitlab.com/ce/api/labels.html#list-labels
func (g *GitlabContext) ListLabels(project_id string, o *ListOptions) ([]*Label, error) {
func (g *Client) ListLabels(project_id string, o *ListOptions) ([]*Label, error) {
path := getUrl([]string{"projects", url.QueryEscape(project_id), "labels"})
u, err := addOptions(path, o)
if err != nil {
......@@ -54,7 +54,7 @@ func (g *GitlabContext) ListLabels(project_id string, o *ListOptions) ([]*Label,
// CreateIssue creates a new project issue.
//
// GitLab API docs: http://doc.gitlab.com/ce/api/issues.html#new-issues
func (g *GitlabContext) CreateLabel(project_id string, label *LabelRequest) (*Label, *http.Response, error) {
func (g *Client) CreateLabel(project_id string, label *LabelRequest) (*Label, *http.Response, error) {
path := []string{"projects", url.QueryEscape(project_id), "labels"}
req, _ := g.NewRequest("POST", path, label)
......@@ -69,7 +69,7 @@ func (g *GitlabContext) CreateLabel(project_id string, label *LabelRequest) (*La
// EditLabel updates an existing project labels
//
// GitLab API docs: http://doc.gitlab.com/ce/api/labels.html#edit-an-existing-label
func (g *GitlabContext) EditLabel(project_id string, label *LabelRequest) (*Label, *http.Response, error) {
func (g *Client) EditLabel(project_id string, label *LabelRequest) (*Label, *http.Response, error) {
path := []string{"projects", url.QueryEscape(project_id), "labels"}
req, _ := g.NewRequest("PUT", path, label)
......@@ -84,7 +84,7 @@ func (g *GitlabContext) EditLabel(project_id string, label *LabelRequest) (*Labe
//DeleteLabel deletes an existing project label
//
// GitLab API docs: http://doc.gitlab.com/ce/api/labels.html#delete-a-label
func (g *GitlabContext) DeleteLabel(project_id string, label *LabelRequest) (*Label, *http.Response, error) {
func (g *Client) DeleteLabel(project_id string, label *LabelRequest) (*Label, *http.Response, error) {
o := &LabelDeleteOptions{Name: label.Name}
path := []string{"projects", url.QueryEscape(project_id), "labels"}
......
......@@ -31,7 +31,7 @@ type MilestoneRequest struct {
// ListMilestones returns a list of project milestones.
//
// GitLab API docs: http://doc.gitlab.com/ce/api/milestones.html#list-project-milestones
func (g *GitlabContext) ListMilestones(project_id string, o *ListOptions) ([]*Milestone, error) {
func (g *Client) ListMilestones(project_id string, o *ListOptions) ([]*Milestone, error) {
path := getUrl([]string{"projects", url.QueryEscape(project_id), "milestones"})
u, err := addOptions(path, o)
if err != nil {
......@@ -51,7 +51,7 @@ func (g *GitlabContext) ListMilestones(project_id string, o *ListOptions) ([]*Mi
// CreateMilestone creates a new project milestone.
//
// GitLab API docs: http://doc.gitlab.com/ce/api/milestones.html#create-new-milestone
func (g *GitlabContext) CreateMilestone(project_id string, m *MilestoneRequest) (*Milestone, *http.Response, error) {
func (g *Client) CreateMilestone(project_id string, m *MilestoneRequest) (*Milestone, *http.Response, error) {
path := []string{"projects", url.QueryEscape(project_id), "milestones"}
req, _ := g.NewRequest("POST", path, m)
......@@ -66,7 +66,7 @@ func (g *GitlabContext) CreateMilestone(project_id string, m *MilestoneRequest)
// UpdateMilestone updates a project milestone.
//
// GitLab API docs: http://doc.gitlab.com/ce/api/milestones.html#edit-milestone
func (g *GitlabContext) UpdateMilestone(project_id string, m_id string, m *MilestoneRequest) (*Milestone, *http.Response, error) {
func (g *Client) UpdateMilestone(project_id string, m_id string, m *MilestoneRequest) (*Milestone, *http.Response, error) {
path := []string{"projects", url.QueryEscape(project_id), "milestones", m_id}
req, _ := g.NewRequest("PUT", path, m)
......
......@@ -52,7 +52,7 @@ type ProjectListOptions struct {
// ListProjects gets a list of projects accessible by the authenticated user.
//
// GitLab API docs: http://doc.gitlab.com/ce/api/projects.html#list-projects
func (g *GitlabContext) ListProjects(o *ProjectListOptions) ([]*Project, *CollectionOptions, error) {
func (g *Client) ListProjects(o *ProjectListOptions) ([]*Project, *CollectionOptions, error) {
u, err := addOptions(getUrl([]string{"projects"}), o)
if err != nil {
return nil, nil, err
......@@ -72,7 +72,7 @@ func (g *GitlabContext) ListProjects(o *ProjectListOptions) ([]*Project, *Collec
// StarredProjects gets a list starred project for user.
//
// GitLab API docs: http://doc.gitlab.com/ce/api/projects.html#list-starred-projects
func (g *GitlabContext) StarredProjects(opt *ProjectListOptions) ([]*Project, *CollectionOptions, error) {
func (g *Client) StarredProjects(opt *ProjectListOptions) ([]*Project, *CollectionOptions, error) {
u, err := addOptions(getUrl([]string{"projects/starred"}), opt)
if err != nil {
return nil, nil, err
......@@ -94,7 +94,7 @@ func (g *GitlabContext) StarredProjects(opt *ProjectListOptions) ([]*Project, *C
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/projects.html#get-single-project
func (g *GitlabContext) ItemProject(projectID string) (*Project, error) {
func (g *Client) ItemProject(projectID string) (*Project, error) {
path := getUrl([]string{"projects", strings.Replace(url.QueryEscape(projectID), ".", "%2E", -1)})
req, _ := http.NewRequest("GET", path, nil)
......
package gitlab
import (
"net/http"
"testing"
"github.com/stretchr/testify/assert"
)
var projectCollection = []byte(`[{
"id": 1,
"description": "My project",
"name":"my project",
"name_with_namespace": "admin / my-project",
"path_with_namespace": "admin/my-project"
}, {
"id": 2,
"description": "My project2",
"name":"my project2",
"name_with_namespace": "admin / my-project2",
"path_with_namespace": "admin/my-project2"
}]`)
func TestClient_ListProjectsSuccess(t *testing.T) {
c, teardown, _ := setup()
defer teardown()
mux.HandleFunc("/projects", func(w http.ResponseWriter, r *http.Request) {
w.Write(projectCollection)
})
pr, collOpt, err := c.ListProjects(&ProjectListOptions{})
assert.Nil(t, err)
assert.NotEmpty(t,pr)
assert.NotEmpty(t, collOpt)
assert.Equal(t, int64(1), (*pr[0]).Id)
assert.Equal(t, int64(2), (*pr[1]).Id)
assert.Equal(t, "my project", (*pr[0]).Name)
}
func TestClient_ListProjectsWithErr(t *testing.T) {
c, teardown, _ := setup()
defer teardown()
mux.HandleFunc("/projects", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`{[}`))
})
pr, collOpt, err := c.ListProjects(&ProjectListOptions{})
assert.NotNil(t, err)
assert.Empty(t, pr)
assert.Empty(t, collOpt)
}
func TestClient_ListProjectsRequestParams(t *testing.T) {
c, teardown, _ := setup()
defer teardown()
opt := &ProjectListOptions{
Archived: "false",
Search: "qwerty",
ListOptions: ListOptions{
Page: "1",
PerPage: "1",
},
}
mux.HandleFunc("/projects", func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, opt.Page, r.URL.Query().Get("page"))
assert.Equal(t, opt.PerPage, r.URL.Query().Get("per_page"))
assert.Equal(t, opt.Archived, r.URL.Query().Get("archived"))
assert.Equal(t, opt.Search, r.URL.Query().Get("search"))
})
c.ListProjects(opt)
}
func TestClient_StarredProjectsSuccess(t *testing.T) {
c, teardown, _ := setup()
defer teardown()
mux.HandleFunc("/projects/starred", func(w http.ResponseWriter, r *http.Request) {
w.Write(projectCollection)
})
pr, collOpt, err := c.StarredProjects(&ProjectListOptions{})
assert.Nil(t, err)
assert.NotEmpty(t,pr)
assert.NotEmpty(t, collOpt)
assert.Equal(t, int64(1), (*pr[0]).Id)
assert.Equal(t, int64(2), (*pr[1]).Id)
assert.Equal(t, "my project", (*pr[0]).Name)
}
func TestClient_ListProjectsErr(t *testing.T) {
c, teardown, _ := setup()
defer teardown()
mux.HandleFunc("/projects/starred", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`{[}`))
})
pr, opt, err := c.StarredProjects(&ProjectListOptions{})
assert.NotNil(t, err)
assert.Empty(t, pr)
assert.Empty(t, opt)
}
func TestClient_StarredProjectsRequestCheck(t *testing.T) {
c, teardown, _ := setup()
defer teardown()
opt := &ProjectListOptions{
Archived: "false",
Search: "false",
ListOptions: ListOptions{
Page: "1",
PerPage: "10",
},
}
mux.HandleFunc("/projects/starred", func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, opt.Archived, r.URL.Query().Get("archived"))
assert.Equal(t, opt.Page, r.URL.Query().Get("page"))
assert.Equal(t, opt.PerPage, r.URL.Query().Get("per_page"))
assert.Equal(t, opt.Search, r.URL.Query().Get("search"))
})
c.StarredProjects(opt)
}
func TestClient_ItemProjectSuccess(t *testing.T) {
c, teardown, _ := setup()
defer teardown()
mux.HandleFunc("/projects/admin/my-project", func(w http.ResponseWriter, r *http.Request) {
data := []byte(`{
"id": 1,
"description": "My project",
"name":"my project",
"name_with_namespace": "admin / my-project",
"path_with_namespace": "admin/my-project"
}`)
w.Write(data)
})
pr, err := c.ItemProject("admin/my-project")
assert.Nil(t, err)
assert.NotEmpty(t, pr)
assert.Equal(t, int64(1), pr.Id)
assert.Equal(t, "My project", pr.Description)
assert.Equal(t, "my project", pr.Name)
assert.Equal(t, "admin / my-project", pr.NamespaceWithName)
assert.Equal(t, "admin/my-project", pr.PathWithNamespace)
}
func TestClient_ItemProjectError(t *testing.T) {
c, teardown, _ := setup()
defer teardown()
mux.HandleFunc("/projects/admin/my-project", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`[{]`))
})
pr, err := c.ItemProject("admin/my-project")
assert.NotNil(t, err)
assert.Empty(t, pr)
}
......@@ -25,7 +25,7 @@ func (r ResponseError) Error() string {
// Do sends an HTTP request and returns an HTTP response, following
// policy (e.g. redirects, cookies, auth) as configured on the client.
func (g *GitlabContext) Do(req *http.Request, v interface{}) (*http.Response, error) {
func (g *Client) Do(req *http.Request, v interface{}) (*http.Response, error) {
res, err := g.client.Do(req)
if err != nil {
......@@ -74,7 +74,7 @@ func CheckResponse(r *http.Response) error {
// Relative URLs should always be specified without a preceding slash. If
// specified, the value pointed to by body is JSON encoded and included as the
// request body.
func (c *GitlabContext) NewRequest(method string, urlStr []string, body interface{}) (*http.Request, error) {
func (c *Client) NewRequest(method string, urlStr []string, body interface{}) (*http.Request, error) {
u := getUrl(urlStr)
var buf io.ReadWriter
......
......@@ -22,7 +22,7 @@ type User struct {
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/projects.html#list-project-team-members
func (g *GitlabContext) ListProjectMembers(project_id string, o *ListOptions) ([]*User, error) {
func (g *Client) ListProjectMembers(project_id string, o *ListOptions) ([]*User, error) {
path := getUrl([]string{"projects", url.QueryEscape(project_id), "members"})
u, err := addOptions(path, o)
if err != nil {
......@@ -43,7 +43,7 @@ func (g *GitlabContext) ListProjectMembers(project_id string, o *ListOptions) ([
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/groups.html#list-group-members
func (g *GitlabContext) ListGroupMembers(group_id string, o *ListOptions) ([]*User, error) {
func (g *Client) ListGroupMembers(group_id string, o *ListOptions) ([]*User, error) {
path := getUrl([]string{"groups", group_id, "members"})
u, err := addOptions(path, o)
if err != nil {
......@@ -63,7 +63,7 @@ func (g *GitlabContext) ListGroupMembers(group_id string, o *ListOptions) ([]*Us
// CurrentUser gets currently authenticated user.
//
// GitLab API docs: http://doc.gitlab.com/ce/api/users.html#current-user
func (g *GitlabContext) CurrentUser() (*User, error) {
func (g *Client) CurrentUser() (*User, error) {
path := getUrl([]string{"user"})
req, _ := http.NewRequest("GET", path, nil)
......
......@@ -5,10 +5,9 @@ import (
"net/url"
"strings"
"gopkg.in/redis.v3"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"gopkg.in/redis.v3"
)
// NewContext created new context for settings
......@@ -92,10 +91,10 @@ func NewDbClient() *redis.Client {
DB: int64(viper.GetInt("redis.db")),
}
url, _ := url.Parse(viper.GetString("redis.addr"))
u, _ := url.Parse(viper.GetString("redis.addr"))