1
0
mirror of https://github.com/interviewstreet/go-jira.git synced 2025-11-25 22:12:08 +02:00

Merge pull request #147 from Xjs/master

Add MarshalJSON method for Time type
This commit is contained in:
rbriski
2018-10-17 08:48:51 +11:00
committed by GitHub
2 changed files with 58 additions and 3 deletions

View File

@@ -344,6 +344,12 @@ func (t *Time) UnmarshalJSON(b []byte) error {
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
// during the transformation of the JIRA JSON response
func (t *Date) UnmarshalJSON(b []byte) error {

View File

@@ -3,14 +3,16 @@ package jira
import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"reflect"
"strings"
"testing"
"github.com/trivago/tgo/tcontainer"
"time"
"github.com/trivago/tgo/tcontainer"
)
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) {
setup()
defer teardown()
@@ -1349,7 +1399,6 @@ func TestIssueService_UpdateAssignee(t *testing.T) {
}
}
func TestIssueService_Get_Fields_Changelog(t *testing.T) {
setup()
defer teardown()
@@ -1360,7 +1409,7 @@ func TestIssueService_Get_Fields_Changelog(t *testing.T) {
fmt.Fprint(w, `{"expand":"changelog","id":"10002","self":"http://www.example.com/jira/rest/api/2/issue/10002","key":"EX-1","changelog":{"startAt": 0,"maxResults": 1, "total": 1, "histories": [{"id": "10002", "author": {"self": "http://www.example.com/jira/rest/api/2/user?username=fred", "name": "fred", "key": "fred", "emailAddress": "fred@example.com", "avatarUrls": {"48x48": "http://www.example.com/secure/useravatar?ownerId=fred&avatarId=33072", "24x24": "http://www.example.com/secure/useravatar?size=small&ownerId=fred&avatarId=33072", "16x16": "http://www.example.com/secure/useravatar?size=xsmall&ownerId=fred&avatarId=33072", "32x32": "http://www.example.com/secure/useravatar?size=medium&ownerId=fred&avatarId=33072"},"displayName":"Fred","active": true,"timeZone":"Australia/Sydney"},"created":"2018-06-20T16:50:35.000+0300","items":[{"field":"Rank","fieldtype":"custom","from":"","fromString":"","to":"","toString":"Ranked higher"}]}]}}`)
})
issue, _, _ := testClient.Issue.Get("10002", &GetQueryOptions{Expand:"changelog"})
issue, _, _ := testClient.Issue.Get("10002", &GetQueryOptions{Expand: "changelog"})
if issue == nil {
t.Error("Expected issue. Issue is nil")
}