mirror of
https://github.com/interviewstreet/go-jira.git
synced 2024-11-24 08:22:42 +02:00
43e8242f2c
* 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
108 lines
2.4 KiB
Go
108 lines
2.4 KiB
Go
package jira
|
|
|
|
import (
|
|
"fmt"
|
|
"io/ioutil"
|
|
"net/http"
|
|
"testing"
|
|
)
|
|
|
|
func TestRoleService_GetList_NoList(t *testing.T) {
|
|
setup()
|
|
defer teardown()
|
|
testAPIEndpoint := "/rest/api/3/role"
|
|
|
|
raw, err := ioutil.ReadFile("./mocks/no_roles.json")
|
|
if err != nil {
|
|
t.Error(err.Error())
|
|
}
|
|
|
|
testMux.HandleFunc(testAPIEndpoint, func(w http.ResponseWriter, r *http.Request) {
|
|
testMethod(t, r, "GET")
|
|
testRequestURL(t, r, testAPIEndpoint)
|
|
fmt.Fprint(w, string(raw))
|
|
})
|
|
|
|
roles, _, err := testClient.Role.GetList()
|
|
if roles != nil {
|
|
t.Errorf("Expected role list has %d entries but should be nil", len(*roles))
|
|
}
|
|
if err == nil {
|
|
t.Errorf("No error given")
|
|
}
|
|
}
|
|
|
|
func TestRoleService_GetList(t *testing.T) {
|
|
setup()
|
|
defer teardown()
|
|
testAPIEndpoint := "/rest/api/3/role"
|
|
|
|
raw, err := ioutil.ReadFile("./mocks/all_roles.json")
|
|
if err != nil {
|
|
t.Error(err.Error())
|
|
}
|
|
testMux.HandleFunc(testAPIEndpoint, func(w http.ResponseWriter, r *http.Request) {
|
|
testMethod(t, r, "GET")
|
|
testRequestURL(t, r, testAPIEndpoint)
|
|
fmt.Fprint(w, string(raw))
|
|
})
|
|
|
|
roles, _, err := testClient.Role.GetList()
|
|
if err != nil {
|
|
t.Errorf("Error given: %v", err)
|
|
}
|
|
if roles == nil {
|
|
t.Error("Expected role list. Role list is nil")
|
|
return
|
|
}
|
|
if len(*roles) != 2 {
|
|
t.Errorf("Expected %d roles but got %d", 2, len(*roles))
|
|
}
|
|
}
|
|
|
|
func TestRoleService_Get_NoRole(t *testing.T) {
|
|
setup()
|
|
defer teardown()
|
|
testAPIEdpoint := "/rest/api/3/role/99999"
|
|
raw, err := ioutil.ReadFile("./mocks/no_role.json")
|
|
if err != nil {
|
|
t.Error(err.Error())
|
|
}
|
|
testMux.HandleFunc(testAPIEdpoint, func(writer http.ResponseWriter, request *http.Request) {
|
|
testMethod(t, request, "GET")
|
|
testRequestURL(t, request, testAPIEdpoint)
|
|
fmt.Fprint(writer, string(raw))
|
|
})
|
|
|
|
role, _, err := testClient.Role.Get(99999)
|
|
if role != nil {
|
|
t.Errorf("Expected nil, got role %v", role)
|
|
}
|
|
if err == nil {
|
|
t.Errorf("No error given")
|
|
}
|
|
}
|
|
|
|
func TestRoleService_Get(t *testing.T) {
|
|
setup()
|
|
defer teardown()
|
|
testAPIEdpoint := "/rest/api/3/role/10002"
|
|
raw, err := ioutil.ReadFile("./mocks/role.json")
|
|
if err != nil {
|
|
t.Error(err.Error())
|
|
}
|
|
testMux.HandleFunc(testAPIEdpoint, func(writer http.ResponseWriter, request *http.Request) {
|
|
testMethod(t, request, "GET")
|
|
testRequestURL(t, request, testAPIEdpoint)
|
|
fmt.Fprint(writer, string(raw))
|
|
})
|
|
|
|
role, _, err := testClient.Role.Get(10002)
|
|
if role == nil {
|
|
t.Errorf("Expected Role, got nil")
|
|
}
|
|
if err != nil {
|
|
t.Errorf("Error given: %s", err)
|
|
}
|
|
}
|