Commit 259cc194 authored by Sander van Harmelen's avatar Sander van Harmelen

Cleanup a bit and improve the readability of some tests

parent 85c5274e
......@@ -34,7 +34,7 @@ import (
const (
libraryVersion = "0.2.0"
defaultBaseURL = "https://gitlab.com/api/v3/"
defaultBaseURL = "https://gitlab.com/api/v4/"
userAgent = "go-gitlab/" + libraryVersion
)
......
......@@ -132,7 +132,7 @@ func TestCheckResponse(t *testing.T) {
t.Fatal("Expected error response.")
}
want := "GET https://gitlab.com/api/v3/test: 400 {error: message 1}, {message: {embed1: {prop3: [msg 1, msg2]}}, {embed2: {prop4: [some msg]}}, {prop1: [message 1, message 2]}, {prop2: [message 3]}}"
want := "GET https://gitlab.com/api/v4/test: 400 {error: message 1}, {message: {embed1: {prop3: [msg 1, msg2]}}, {embed2: {prop4: [some msg]}}, {prop1: [message 1, message 2]}, {prop2: [message 3]}}"
if errResp.Error() != want {
t.Errorf("Expected error: %s, got %s", want, errResp.Error())
......
......@@ -155,11 +155,11 @@ type ListProjectsOptions struct {
Sort *string `url:"sort,omitempty" json:"sort,omitempty"`
Search *string `url:"search,omitempty" json:"search,omitempty"`
Simple *bool `url:"simple,omitempty" json:"simple,omitempty"`
Visibility *VisibilityLevelValue `url:"visibility,omitempty" json:"visibility,omitempty"`
Statistics *bool `url:"statistics,omitempty" json:"statistics,omitempty"`
Owned *bool `url:"owned,omitempty" json:"owned,omitempty"`
Membership *bool `url:"membership,omitempty" json:"membership,omitempty"`
Starred *bool `url:"starred,omitempty" json:"starred,omitempty"`
Statistics *bool `url:"statistics,omitempty" json:"statistics,omitempty"`
Visibility *VisibilityLevelValue `url:"visibility,omitempty" json:"visibility,omitempty"`
}
// ListProjects gets a list of projects accessible by the authenticated user.
......
......@@ -22,17 +22,21 @@ func TestListProjects(t *testing.T) {
"search": "query",
"simple": "true",
"visibility": "public",
"statistics": "false",
"owned": "false",
"membership": "false",
"starred": "false",
})
fmt.Fprint(w, `[{"id":1},{"id":2}]`)
})
opt := &ListProjectsOptions{ListOptions{2, 3}, Bool(true), String("name"), String("asc"), String("query"), Bool(true), VisibilityLevel(PublicVisibility), Bool(false), Bool(false), Bool(false), Bool(false)}
projects, _, err := client.Projects.ListProjects(opt)
opt := &ListProjectsOptions{
ListOptions: ListOptions{2, 3},
Archived: Bool(true),
OrderBy: String("name"),
Sort: String("asc"),
Search: String("query"),
Simple: Bool(true),
Visibility: VisibilityLevel(PublicVisibility),
}
projects, _, err := client.Projects.ListProjects(opt)
if err != nil {
t.Errorf("Projects.ListProjects returned error: %v", err)
}
......@@ -57,18 +61,24 @@ func TestListOwnedProjects(t *testing.T) {
"sort": "asc",
"search": "query",
"simple": "true",
"owned": "true",
"visibility": "public",
"statistics": "false",
"owned": "true",
"membership": "false",
"starred": "false",
})
fmt.Fprint(w, `[{"id":1},{"id":2}]`)
})
opt := &ListProjectsOptions{ListOptions{2, 3}, Bool(true), String("name"), String("asc"), String("query"), Bool(true), VisibilityLevel(PublicVisibility), Bool(false), Bool(true), Bool(false), Bool(false)}
projects, _, err := client.Projects.ListProjects(opt)
opt := &ListProjectsOptions{
ListOptions: ListOptions{2, 3},
Archived: Bool(true),
OrderBy: String("name"),
Sort: String("asc"),
Search: String("query"),
Simple: Bool(true),
Owned: Bool(true),
Visibility: VisibilityLevel(PublicVisibility),
}
projects, _, err := client.Projects.ListProjects(opt)
if err != nil {
t.Errorf("Projects.ListOwnedProjects returned error: %v", err)
}
......@@ -93,18 +103,24 @@ func TestListStarredProjects(t *testing.T) {
"sort": "asc",
"search": "query",
"simple": "true",
"starred": "true",
"visibility": "public",
"statistics": "false",
"owned": "false",
"membership": "false",
"starred": "true",
})
fmt.Fprint(w, `[{"id":1},{"id":2}]`)
})
opt := &ListProjectsOptions{ListOptions{2, 3}, Bool(true), String("name"), String("asc"), String("query"), Bool(true), VisibilityLevel(PublicVisibility), Bool(false), Bool(false), Bool(false), Bool(true)}
projects, _, err := client.Projects.ListProjects(opt)
opt := &ListProjectsOptions{
ListOptions: ListOptions{2, 3},
Archived: Bool(true),
OrderBy: String("name"),
Sort: String("asc"),
Search: String("query"),
Simple: Bool(true),
Starred: Bool(true),
Visibility: VisibilityLevel(PublicVisibility),
}
projects, _, err := client.Projects.ListProjects(opt)
if err != nil {
t.Errorf("Projects.ListStarredProjects returned error: %v", err)
}
......@@ -126,7 +142,6 @@ func TestGetProject_byID(t *testing.T) {
want := &Project{ID: 1}
project, _, err := client.Projects.GetProject(1)
if err != nil {
t.Fatalf("Projects.GetProject returns an error: %v", err)
}
......@@ -148,7 +163,6 @@ func TestGetProject_byName(t *testing.T) {
want := &Project{ID: 1}
project, _, err := client.Projects.GetProject("namespace/name")
if err != nil {
t.Fatalf("Projects.GetProject returns an error: %v", err)
}
......@@ -172,8 +186,8 @@ func TestCreateProject(t *testing.T) {
})
opt := &CreateProjectOptions{Name: String("n")}
project, _, err := client.Projects.CreateProject(opt)
project, _, err := client.Projects.CreateProject(opt)
if err != nil {
t.Errorf("Projects.CreateProject returned error: %v", err)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment