mirror of
https://github.com/interviewstreet/go-jira.git
synced 2025-03-21 21:07:03 +02:00
* origin/master: When creating issue links, the id and self should be omitted along with comment if none is provided Expose comment ID Make issue link direction visible using Time for WorklogRecord.Started Adjusted a few things to be in line with other methods go fmt go fmt, go doc and reuse of Project struct Renamed "json_mocks" into "mocks" Refactored struct types by reusing already existing components Fixed typo in Cookies Moved progect.go to project.go Fix #12: Expose the base JIRA URL update .gitignore using native time.Time updating with search and worklogs # Conflicts: # project_test.go
81 lines
1.8 KiB
Go
81 lines
1.8 KiB
Go
package jira
|
|
|
|
import (
|
|
"fmt"
|
|
"io/ioutil"
|
|
"net/http"
|
|
"testing"
|
|
)
|
|
|
|
func TestProjectGetAll(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 TestProjectGet(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 projects == nil {
|
|
t.Error("Expected project list. Project list is nil")
|
|
}
|
|
if err != nil {
|
|
t.Errorf("Error given: %s", err)
|
|
}
|
|
}
|
|
|
|
func TestProjectGet_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 %s", err)
|
|
}
|
|
|
|
if resp.Status == "404" {
|
|
t.Errorf("Expected status 404. Got %s", resp.Status)
|
|
}
|
|
if err == nil {
|
|
t.Errorf("Error given: %s", err)
|
|
}
|
|
}
|