2018-10-08 15:18:43 -07:00
|
|
|
package jira
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
"net/http"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestFilterService_GetList(t *testing.T) {
|
|
|
|
setup()
|
|
|
|
defer teardown()
|
2019-08-26 20:29:43 +09:00
|
|
|
testAPIEndpoint := "/rest/api/2/filter"
|
2018-10-08 15:18:43 -07:00
|
|
|
raw, err := ioutil.ReadFile("./mocks/all_filters.json")
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err.Error())
|
|
|
|
}
|
2019-08-26 20:29:43 +09:00
|
|
|
testMux.HandleFunc(testAPIEndpoint, func(writer http.ResponseWriter, request *http.Request) {
|
2018-10-08 15:18:43 -07:00
|
|
|
testMethod(t, request, "GET")
|
2019-08-26 20:29:43 +09:00
|
|
|
testRequestURL(t, request, testAPIEndpoint)
|
2018-10-08 15:18:43 -07:00
|
|
|
fmt.Fprint(writer, string(raw))
|
|
|
|
})
|
|
|
|
|
|
|
|
filters, _, err := testClient.Filter.GetList()
|
|
|
|
if filters == nil {
|
|
|
|
t.Error("Expected Filters list. Filters list is nil")
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Error given: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestFilterService_Get(t *testing.T) {
|
|
|
|
setup()
|
|
|
|
defer teardown()
|
2019-08-26 20:29:43 +09:00
|
|
|
testAPIEndpoint := "/rest/api/2/filter/10000"
|
2018-10-08 15:18:43 -07:00
|
|
|
raw, err := ioutil.ReadFile("./mocks/filter.json")
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err.Error())
|
|
|
|
}
|
2019-08-26 20:29:43 +09:00
|
|
|
testMux.HandleFunc(testAPIEndpoint, func(writer http.ResponseWriter, request *http.Request) {
|
2018-10-08 15:18:43 -07:00
|
|
|
testMethod(t, request, "GET")
|
2019-08-26 20:29:43 +09:00
|
|
|
testRequestURL(t, request, testAPIEndpoint)
|
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
|
|
|
fmt.Fprint(writer, string(raw))
|
2018-10-08 15:18:43 -07:00
|
|
|
})
|
|
|
|
|
|
|
|
filter, _, err := testClient.Filter.Get(10000)
|
|
|
|
if filter == nil {
|
|
|
|
t.Errorf("Expected Filter, got nil")
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Error given: %s", err)
|
|
|
|
}
|
|
|
|
|
2018-11-20 17:00:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestFilterService_GetFavouriteList(t *testing.T) {
|
|
|
|
setup()
|
|
|
|
defer teardown()
|
2019-08-26 20:29:43 +09:00
|
|
|
testAPIEndpoint := "/rest/api/2/filter/favourite"
|
2018-11-20 17:00:27 -05:00
|
|
|
raw, err := ioutil.ReadFile("./mocks/favourite_filters.json")
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err.Error())
|
|
|
|
}
|
2019-08-26 20:29:43 +09:00
|
|
|
testMux.HandleFunc(testAPIEndpoint, func(writer http.ResponseWriter, request *http.Request) {
|
2018-11-20 17:00:27 -05:00
|
|
|
testMethod(t, request, "GET")
|
2019-08-26 20:29:43 +09:00
|
|
|
testRequestURL(t, request, testAPIEndpoint)
|
2018-11-20 17:00:27 -05:00
|
|
|
fmt.Fprint(writer, string(raw))
|
|
|
|
})
|
2018-10-08 15:18:43 -07:00
|
|
|
|
2018-11-20 17:00:27 -05:00
|
|
|
filters, _, err := testClient.Filter.GetFavouriteList()
|
|
|
|
if filters == nil {
|
|
|
|
t.Error("Expected Filters list. Filters list is nil")
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Error given: %s", err)
|
|
|
|
}
|
2018-10-08 15:18:43 -07:00
|
|
|
}
|
2019-08-25 10:25:32 +09:00
|
|
|
|
|
|
|
func TestFilterService_GetMyFilters(t *testing.T) {
|
|
|
|
setup()
|
|
|
|
defer teardown()
|
|
|
|
testAPIEndpoint := "/rest/api/3/filter/my"
|
|
|
|
raw, err := ioutil.ReadFile("./mocks/my_filters.json")
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err.Error())
|
|
|
|
}
|
|
|
|
testMux.HandleFunc(testAPIEndpoint, func(writer http.ResponseWriter, request *http.Request) {
|
|
|
|
testMethod(t, request, "GET")
|
|
|
|
testRequestURL(t, request, testAPIEndpoint)
|
|
|
|
fmt.Fprint(writer, string(raw))
|
|
|
|
})
|
|
|
|
|
|
|
|
opts := GetMyFiltersQueryOptions{}
|
|
|
|
filters, _, err := testClient.Filter.GetMyFilters(&opts)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Error given: %s", err)
|
|
|
|
}
|
|
|
|
if filters == nil {
|
|
|
|
t.Errorf("Expected Filters, got nil")
|
|
|
|
}
|
|
|
|
}
|
2019-08-26 20:27:12 +09:00
|
|
|
|
|
|
|
func TestFilterService_Search(t *testing.T) {
|
|
|
|
setup()
|
|
|
|
defer teardown()
|
|
|
|
testAPIEndpoint := "/rest/api/3/filter/search"
|
|
|
|
raw, err := ioutil.ReadFile("./mocks/search_filters.json")
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err.Error())
|
|
|
|
}
|
|
|
|
testMux.HandleFunc(testAPIEndpoint, func(writer http.ResponseWriter, request *http.Request) {
|
|
|
|
testMethod(t, request, "GET")
|
|
|
|
testRequestURL(t, request, testAPIEndpoint)
|
|
|
|
fmt.Fprint(writer, string(raw))
|
|
|
|
})
|
|
|
|
|
|
|
|
opt := FilterSearchOptions{}
|
|
|
|
filters, _, err := testClient.Filter.Search(&opt)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Error given: %s", err)
|
|
|
|
}
|
|
|
|
if filters == nil {
|
|
|
|
t.Errorf("Expected Filters, got nil")
|
|
|
|
}
|
|
|
|
}
|