Commit f3009e27 authored by snehal dangroshiya's avatar snehal dangroshiya Committed by Sander van Harmelen

Added unit test for issues and settings (#526)

parent 960038d4
...@@ -33,62 +33,64 @@ type IssuesService struct { ...@@ -33,62 +33,64 @@ type IssuesService struct {
timeStats *timeStatsService timeStats *timeStatsService
} }
// IssueAuthor represents a author of the issue.
type IssueAuthor struct {
ID int `json:"id"`
State string `json:"state"`
WebURL string `json:"web_url"`
Name string `json:"name"`
AvatarURL string `json:"avatar_url"`
Username string `json:"username"`
}
// IssueAssignee represents a assignee of the issue.
type IssueAssignee struct {
ID int `json:"id"`
State string `json:"state"`
WebURL string `json:"web_url"`
Name string `json:"name"`
AvatarURL string `json:"avatar_url"`
Username string `json:"username"`
}
// IssueLinks represents links of the issue.
type IssueLinks struct {
Self string `json:"self"`
Notes string `json:"notes"`
AwardEmoji string `json:"award_emoji"`
Project string `json:"project"`
}
// Issue represents a GitLab issue. // Issue represents a GitLab issue.
// //
// GitLab API docs: https://docs.gitlab.com/ce/api/issues.html // GitLab API docs: https://docs.gitlab.com/ce/api/issues.html
type Issue struct { type Issue struct {
ID int `json:"id"` ID int `json:"id"`
IID int `json:"iid"` IID int `json:"iid"`
ProjectID int `json:"project_id"` ProjectID int `json:"project_id"`
Milestone *Milestone `json:"milestone"` Milestone *Milestone `json:"milestone"`
Author struct { Author *IssueAuthor `json:"author"`
ID int `json:"id"` Description string `json:"description"`
State string `json:"state"` State string `json:"state"`
WebURL string `json:"web_url"` Assignees []*IssueAssignee `json:"assignees"`
Name string `json:"name"` Assignee *IssueAssignee `json:"assignee"`
AvatarURL string `json:"avatar_url"` Upvotes int `json:"upvotes"`
Username string `json:"username"` Downvotes int `json:"downvotes"`
} `json:"author"` Labels []string `json:"labels"`
Description string `json:"description"` Title string `json:"title"`
State string `json:"state"` UpdatedAt *time.Time `json:"updated_at"`
Assignees []struct { CreatedAt *time.Time `json:"created_at"`
ID int `json:"id"` ClosedAt *time.Time `json:"closed_at"`
State string `json:"state"` Subscribed bool `json:"subscribed"`
WebURL string `json:"web_url"` UserNotesCount int `json:"user_notes_count"`
Name string `json:"name"` DueDate *ISOTime `json:"due_date"`
AvatarURL string `json:"avatar_url"` WebURL string `json:"web_url"`
Username string `json:"username"` TimeStats *TimeStats `json:"time_stats"`
} `json:"assignees"` Confidential bool `json:"confidential"`
Assignee struct { Weight int `json:"weight"`
ID int `json:"id"` DiscussionLocked bool `json:"discussion_locked"`
State string `json:"state"` Links *IssueLinks `json:"_links"`
WebURL string `json:"web_url"` IssueLinkID int `json:"issue_link_id"`
Name string `json:"name"`
AvatarURL string `json:"avatar_url"`
Username string `json:"username"`
} `json:"assignee"`
Upvotes int `json:"upvotes"`
Downvotes int `json:"downvotes"`
Labels []string `json:"labels"`
Title string `json:"title"`
UpdatedAt *time.Time `json:"updated_at"`
CreatedAt *time.Time `json:"created_at"`
ClosedAt *time.Time `json:"closed_at"`
Subscribed bool `json:"subscribed"`
UserNotesCount int `json:"user_notes_count"`
DueDate *ISOTime `json:"due_date"`
WebURL string `json:"web_url"`
TimeStats *TimeStats `json:"time_stats"`
Confidential bool `json:"confidential"`
Weight int `json:"weight"`
DiscussionLocked bool `json:"discussion_locked"`
Links struct {
Self string `json:"self"`
Notes string `json:"notes"`
AwardEmoji string `json:"award_emoji"`
Project string `json:"project"`
} `json:"_links"`
IssueLinkID int `json:"issue_link_id"`
} }
func (i Issue) String() string { func (i Issue) String() string {
......
This diff is collapsed.
...@@ -27,7 +27,7 @@ func TestCreateLabel(t *testing.T) { ...@@ -27,7 +27,7 @@ func TestCreateLabel(t *testing.T) {
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
want := &Label{ID:1, Name:"My Label", Color:"#11FF22"} want := &Label{ID: 1, Name: "My Label", Color: "#11FF22"}
if !reflect.DeepEqual(want, label) { if !reflect.DeepEqual(want, label) {
t.Errorf("Labels.CreateLabel returned %+v, want %+v", label, want) t.Errorf("Labels.CreateLabel returned %+v, want %+v", label, want)
} }
...@@ -64,13 +64,13 @@ func TestUpdateLabel(t *testing.T) { ...@@ -64,13 +64,13 @@ func TestUpdateLabel(t *testing.T) {
// Update label // Update label
l := &UpdateLabelOptions{ l := &UpdateLabelOptions{
Name : String("My Label"), Name: String("My Label"),
NewName : String("New Label"), NewName: String("New Label"),
Color : String("#11FF23"), Color: String("#11FF23"),
Description : String("This is updated label"), Description: String("This is updated label"),
} }
label, resp , err := client.Labels.UpdateLabel("1", l) label, resp, err := client.Labels.UpdateLabel("1", l)
if resp == nil { if resp == nil {
log.Fatal(err) log.Fatal(err)
...@@ -79,14 +79,14 @@ func TestUpdateLabel(t *testing.T) { ...@@ -79,14 +79,14 @@ func TestUpdateLabel(t *testing.T) {
log.Fatal(err) log.Fatal(err)
} }
want := &Label{ID:1, Name:"New Label", Color:"#11FF23", Description:"This is updated label"} want := &Label{ID: 1, Name: "New Label", Color: "#11FF23", Description: "This is updated label"}
if !reflect.DeepEqual(want, label) { if !reflect.DeepEqual(want, label) {
t.Errorf("Labels.UpdateLabel returned %+v, want %+v", label, want) t.Errorf("Labels.UpdateLabel returned %+v, want %+v", label, want)
} }
} }
func TestSubscribeToLabel(t *testing.T) { func TestSubscribeToLabel(t *testing.T) {
mux, server, client := setup() mux, server, client := setup()
defer teardown(server) defer teardown(server)
...@@ -95,17 +95,17 @@ func TestSubscribeToLabel(t *testing.T) { ...@@ -95,17 +95,17 @@ func TestSubscribeToLabel(t *testing.T) {
fmt.Fprint(w, `{ "id" : 5, "name" : "bug", "color" : "#d9534f", "description": "Bug reported by user", "open_issues_count": 1, "closed_issues_count": 0, "open_merge_requests_count": 1, "subscribed": true,"priority": null}`) fmt.Fprint(w, `{ "id" : 5, "name" : "bug", "color" : "#d9534f", "description": "Bug reported by user", "open_issues_count": 1, "closed_issues_count": 0, "open_merge_requests_count": 1, "subscribed": true,"priority": null}`)
}) })
label, _ , err := client.Labels.SubscribeToLabel("1", "5") label, _, err := client.Labels.SubscribeToLabel("1", "5")
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
want := &Label{ID:5, Name:"bug", Color:"#d9534f", Description:"Bug reported by user", OpenIssuesCount:1, ClosedIssuesCount:0, OpenMergeRequestsCount:1, Subscribed: true} want := &Label{ID: 5, Name: "bug", Color: "#d9534f", Description: "Bug reported by user", OpenIssuesCount: 1, ClosedIssuesCount: 0, OpenMergeRequestsCount: 1, Subscribed: true}
if !reflect.DeepEqual(want, label) { if !reflect.DeepEqual(want, label) {
t.Errorf("Labels.UpdateLabel returned %+v, want %+v", label, want) t.Errorf("Labels.SubscribeToLabel returned %+v, want %+v", label, want)
} }
} }
func TestUnsubscribeFromLabel(t *testing.T) { func TestUnsubscribeFromLabel(t *testing.T) {
mux, server, client := setup() mux, server, client := setup()
defer teardown(server) defer teardown(server)
...@@ -113,7 +113,7 @@ func TestUnsubscribeFromLabel(t *testing.T) { ...@@ -113,7 +113,7 @@ func TestUnsubscribeFromLabel(t *testing.T) {
testMethod(t, r, "POST") testMethod(t, r, "POST")
}) })
_ , err := client.Labels.UnsubscribeFromLabel("1", "5") _, err := client.Labels.UnsubscribeFromLabel("1", "5")
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
...@@ -128,17 +128,17 @@ func TestListLabels(t *testing.T) { ...@@ -128,17 +128,17 @@ func TestListLabels(t *testing.T) {
fmt.Fprint(w, `[{ "id" : 5, "name" : "bug", "color" : "#d9534f", "description": "Bug reported by user", "open_issues_count": 1, "closed_issues_count": 0, "open_merge_requests_count": 1, "subscribed": true,"priority": null}]`) fmt.Fprint(w, `[{ "id" : 5, "name" : "bug", "color" : "#d9534f", "description": "Bug reported by user", "open_issues_count": 1, "closed_issues_count": 0, "open_merge_requests_count": 1, "subscribed": true,"priority": null}]`)
}) })
o := &ListLabelsOptions { o := &ListLabelsOptions{
Page:1, Page: 1,
PerPage:10, PerPage: 10,
} }
label, _ , err := client.Labels.ListLabels("1", o) label, _, err := client.Labels.ListLabels("1", o)
if err != nil { if err != nil {
t.Log(err.Error() == "invalid ID type 1.1, the ID must be an int or a string") t.Log(err.Error() == "invalid ID type 1.1, the ID must be an int or a string")
} }
want := []*Label{{ID:5, Name:"bug", Color:"#d9534f", Description:"Bug reported by user", OpenIssuesCount:1, ClosedIssuesCount:0, OpenMergeRequestsCount:1, Subscribed: true}} want := []*Label{{ID: 5, Name: "bug", Color: "#d9534f", Description: "Bug reported by user", OpenIssuesCount: 1, ClosedIssuesCount: 0, OpenMergeRequestsCount: 1, Subscribed: true}}
if !reflect.DeepEqual(want, label) { if !reflect.DeepEqual(want, label) {
t.Errorf("Labels.UpdateLabel returned %+v, want %+v", label, want) t.Errorf("Labels.ListLabels returned %+v, want %+v", label, want)
} }
} }
\ No newline at end of file
package gitlab
import (
"fmt"
"net/http"
"reflect"
"testing"
)
func TestGetSettings(t *testing.T) {
mux, server, client := setup()
defer teardown(server)
mux.HandleFunc("/api/v4/application/settings", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `{"id":1, "default_projects_limit" : 100000}`)
})
settings, _, err := client.Settings.GetSettings()
if err != nil {
t.Fatal(err)
}
want := &Settings{ID: 1, DefaultProjectsLimit: 100000}
if !reflect.DeepEqual(settings, want) {
t.Errorf("Settings.GetSettings returned %+v, want %+v", settings, want)
}
}
func TestUpdateSettings(t *testing.T) {
mux, server, client := setup()
defer teardown(server)
mux.HandleFunc("/api/v4/application/settings", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "PUT")
fmt.Fprint(w, `{"default_projects_limit" : 100}`)
})
options := &UpdateSettingsOptions{
DefaultProjectsLimit: Int(100),
}
settings, _, err := client.Settings.UpdateSettings(options)
if err != nil {
t.Fatal(err)
}
want := &Settings{DefaultProjectsLimit: 100}
if !reflect.DeepEqual(settings, want) {
t.Errorf("Settings.UpdateSettings returned %+v, want %+v", settings, want)
}
}
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