mirror of
https://github.com/interviewstreet/go-jira.git
synced 2025-11-27 22:18:45 +02:00
Merge pull request #147 from Xjs/master
Add MarshalJSON method for Time type
This commit is contained in:
6
issue.go
6
issue.go
@@ -344,6 +344,12 @@ func (t *Time) UnmarshalJSON(b []byte) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MarshalJSON will transform the time.Time into a JIRA time
|
||||||
|
// during the creation of a JIRA request
|
||||||
|
func (t Time) MarshalJSON() ([]byte, error) {
|
||||||
|
return []byte(time.Time(t).Format("\"2006-01-02T15:04:05.999-0700\"")), nil
|
||||||
|
}
|
||||||
|
|
||||||
// UnmarshalJSON will transform the JIRA date into a time.Time
|
// UnmarshalJSON will transform the JIRA date into a time.Time
|
||||||
// during the transformation of the JIRA JSON response
|
// during the transformation of the JIRA JSON response
|
||||||
func (t *Date) UnmarshalJSON(b []byte) error {
|
func (t *Date) UnmarshalJSON(b []byte) error {
|
||||||
|
|||||||
@@ -3,14 +3,16 @@ package jira
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/trivago/tgo/tcontainer"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/trivago/tgo/tcontainer"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestIssueService_Get_Success(t *testing.T) {
|
func TestIssueService_Get_Success(t *testing.T) {
|
||||||
@@ -79,6 +81,54 @@ func TestIssueService_Create(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestIssueService_CreateThenGet(t *testing.T) {
|
||||||
|
setup()
|
||||||
|
defer teardown()
|
||||||
|
testMux.HandleFunc("/rest/api/2/issue", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
testMethod(t, r, "POST")
|
||||||
|
testRequestURL(t, r, "/rest/api/2/issue")
|
||||||
|
|
||||||
|
w.WriteHeader(http.StatusCreated)
|
||||||
|
io.Copy(w, r.Body)
|
||||||
|
})
|
||||||
|
|
||||||
|
i := &Issue{
|
||||||
|
Fields: &IssueFields{
|
||||||
|
Description: "example bug report",
|
||||||
|
Created: Time(time.Now()),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
issue, _, err := testClient.Issue.Create(i)
|
||||||
|
if issue == nil {
|
||||||
|
t.Error("Expected issue. Issue is nil")
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Error given: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
testMux.HandleFunc("/rest/api/2/issue/10002", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
testMethod(t, r, "GET")
|
||||||
|
testRequestURL(t, r, "/rest/api/2/issue/10002")
|
||||||
|
|
||||||
|
bytes, err := json.Marshal(issue)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Error marshaling issue: %s", err)
|
||||||
|
}
|
||||||
|
_, err = w.Write(bytes)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Error writing response: %s", err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
issue2, _, err := testClient.Issue.Get("10002", nil)
|
||||||
|
if issue2 == nil {
|
||||||
|
t.Error("Expected issue. Issue is nil")
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Error given: %s", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestIssueService_Update(t *testing.T) {
|
func TestIssueService_Update(t *testing.T) {
|
||||||
setup()
|
setup()
|
||||||
defer teardown()
|
defer teardown()
|
||||||
@@ -1349,7 +1399,6 @@ func TestIssueService_UpdateAssignee(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func TestIssueService_Get_Fields_Changelog(t *testing.T) {
|
func TestIssueService_Get_Fields_Changelog(t *testing.T) {
|
||||||
setup()
|
setup()
|
||||||
defer teardown()
|
defer teardown()
|
||||||
|
|||||||
Reference in New Issue
Block a user