1
0
mirror of https://github.com/interviewstreet/go-jira.git synced 2024-12-02 08:51:43 +02:00
go-jira/project_test.go
Andy Grunwald 43e8242f2c
style: Fix staticcheck (static analysis) errors for this library (#283)
* style: Fix staticcheck errors for "error strings should not be capitalized (ST1005)"

staticcheck is a static analysis tool for go.
It reports several "error strings should not be capitalized (ST1005)" messages.
Here, we fix it to be more compliant with the go coding styleguide.

Related: #280

* style: Fix staticcheck errors for "printf-style function with dynamic format ... (SA1006)"

staticcheck is a static analysis tool for go.
It reports several "printf-style function with dynamic format string and no further arguments should use print-style function instead (SA1006)" messages.
Here, we fix it to be more compliant with the go coding styleguide.

Related: #280

* style: Fix staticcheck errors for "type X is unused (U1000)"

staticcheck is a static analysis tool for go.
It reports several "type X is unused (U1000)" messages.
Here, we fix it to be more compliant with the go coding styleguide.

Related: #280

* style: Fix staticcheck errors for "should use X instead (S1003 & SA6005)"

staticcheck is a static analysis tool for go.
It reports several

- should use !bytes.Contains(b, []byte(`"password":"bar"`)) instead (S1003)
- should use strings.EqualFold instead (SA6005)

messages.
Here, we fix it to be more compliant with the go coding styleguide.

Related: #280

* style: Fix staticcheck errors for "unnecessary use of fmt.Sprintf (S1039)"

staticcheck is a static analysis tool for go.
It report several "unnecessary use of fmt.Sprintf (S1039)" messages.
Here, we fix it to be more compliant with the go coding styleguide.

Related: #280

* style: Fix staticcheck errors for "this value of X is never used (SA4006)"

staticcheck is a static analysis tool for go.
It report several "this value of X is never used (SA4006)" messages.
Here, we fix it to be more compliant with the go coding styleguide.

Related: #280

* style: Fix staticcheck errors for "redundant return statement (S1023)"

staticcheck is a static analysis tool for go.
It report several "redundant return statement (S1023)" messages.
Here, we fix it to be more compliant with the go coding styleguide.

Related: #280

* style: Fix staticcheck errors for "possible nil pointer dereference (SA5011)"

staticcheck is a static analysis tool for go.
It report several

    file.go:Line:character: possible nil pointer dereference (SA5011)
        file.go:Line:character: this check suggests that the pointer can be nil

messages.
Here, we fix it to be more compliant with the go coding styleguide.

Related: #280

* style: Fix staticcheck errors for "this value of X is never used (SA4006)"

staticcheck is a static analysis tool for go.
It report several "this value of X is never used (SA4006)" messages.
Here, we fix it to be more compliant with the go coding styleguide.

Related: #280
2020-05-02 23:08:01 +02:00

163 lines
4.1 KiB
Go

package jira
import (
"fmt"
"io/ioutil"
"net/http"
"testing"
)
func TestProjectService_GetList(t *testing.T) {
setup()
defer teardown()
testAPIEdpoint := "/rest/api/2/project"
raw, err := ioutil.ReadFile("./mocks/all_projects.json")
if err != nil {
t.Error(err.Error())
}
testMux.HandleFunc(testAPIEdpoint, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testRequestURL(t, r, testAPIEdpoint)
fmt.Fprint(w, string(raw))
})
projects, _, err := testClient.Project.GetList()
if projects == nil {
t.Error("Expected project list. Project list is nil")
}
if err != nil {
t.Errorf("Error given: %s", err)
}
}
func TestProjectService_ListWithOptions(t *testing.T) {
setup()
defer teardown()
testAPIEdpoint := "/rest/api/2/project"
raw, err := ioutil.ReadFile("./mocks/all_projects.json")
if err != nil {
t.Error(err.Error())
}
testMux.HandleFunc(testAPIEdpoint, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testRequestURL(t, r, "/rest/api/2/project?expand=issueTypes")
fmt.Fprint(w, string(raw))
})
projects, _, err := testClient.Project.ListWithOptions(&GetQueryOptions{Expand: "issueTypes"})
if projects == nil {
t.Error("Expected project list. Project list is nil")
}
if err != nil {
t.Errorf("Error given: %s", err)
}
}
func TestProjectService_Get(t *testing.T) {
setup()
defer teardown()
testAPIEdpoint := "/rest/api/2/project/12310505"
raw, err := ioutil.ReadFile("./mocks/project.json")
if err != nil {
t.Error(err.Error())
}
testMux.HandleFunc(testAPIEdpoint, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testRequestURL(t, r, testAPIEdpoint)
fmt.Fprint(w, string(raw))
})
projects, _, err := testClient.Project.Get("12310505")
if err != nil {
t.Errorf("Error given: %s", err)
}
if projects == nil {
t.Error("Expected project list. Project list is nil")
return
}
if len(projects.Roles) != 9 {
t.Errorf("Expected 9 roles but got %d", len(projects.Roles))
}
}
func TestProjectService_Get_NoProject(t *testing.T) {
setup()
defer teardown()
testAPIEdpoint := "/rest/api/2/project/99999999"
testMux.HandleFunc(testAPIEdpoint, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testRequestURL(t, r, testAPIEdpoint)
fmt.Fprint(w, nil)
})
projects, resp, err := testClient.Project.Get("99999999")
if projects != nil {
t.Errorf("Expected nil. Got %+v", projects)
}
if resp.Status == "404" {
t.Errorf("Expected status 404. Got %s", resp.Status)
}
if err == nil {
t.Errorf("Error given: %s", err)
}
}
func TestProjectService_GetPermissionScheme_Failure(t *testing.T) {
setup()
defer teardown()
testAPIEdpoint := "/rest/api/2/project/99999999/permissionscheme"
testMux.HandleFunc(testAPIEdpoint, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testRequestURL(t, r, testAPIEdpoint)
fmt.Fprint(w, nil)
})
permissionScheme, resp, err := testClient.Project.GetPermissionScheme("99999999")
if permissionScheme != nil {
t.Errorf("Expected nil. Got %+v", permissionScheme)
}
if resp.Status == "404" {
t.Errorf("Expected status 404. Got %s", resp.Status)
}
if err == nil {
t.Errorf("Error given: %s", err)
}
}
func TestProjectService_GetPermissionScheme_Success(t *testing.T) {
setup()
defer teardown()
testAPIEdpoint := "/rest/api/2/project/99999999/permissionscheme"
testMux.HandleFunc(testAPIEdpoint, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testRequestURL(t, r, testAPIEdpoint)
fmt.Fprint(w, `{
"expand": "permissions,user,group,projectRole,field,all",
"id": 10201,
"self": "https://www.example.com/rest/api/2/permissionscheme/10201",
"name": "Project for specific-users",
"description": "Projects that can only see for people belonging to specific-users group"
}`)
})
permissionScheme, resp, err := testClient.Project.GetPermissionScheme("99999999")
if permissionScheme.ID != 10201 {
t.Errorf("Expected Permission Scheme ID. Got %+v", permissionScheme)
}
if resp.Status == "404" {
t.Errorf("Expected status 404. Got %s", resp.Status)
}
if err != nil {
t.Errorf("Error given: %s", err)
}
}