1
0
mirror of https://github.com/interviewstreet/go-jira.git synced 2025-11-29 22:28:34 +02:00

fix: change millisecond time format

If millisecond in go time is empty
they will be not exist in result string
if using "999" in format. And jira api
will response with error in the case.

Using "000" fix the problem.

Add test for time marshaling.
This commit is contained in:
mehanizm
2020-04-10 17:01:27 +03:00
committed by Andy Grunwald
parent f200e158b9
commit 8c77107df3
2 changed files with 33 additions and 4 deletions

View File

@@ -9,11 +9,9 @@ import (
"reflect"
"strings"
"testing"
"github.com/google/go-cmp/cmp"
"time"
"github.com/google/go-cmp/cmp"
"github.com/trivago/tgo/tcontainer"
)
@@ -1799,3 +1797,34 @@ func TestIssueService_AddRemoteLink(t *testing.T) {
t.Errorf("Error given: %s", err)
}
}
func TestTime_MarshalJSON(t *testing.T) {
timeFormatParseFrom := "2006-01-02T15:04:05.999Z"
testCases := []struct {
name string
inputTime string
expected string
}{
{
name: "test without ms",
inputTime: "2020-04-01T01:01:01.000Z",
expected: "\"2020-04-01T01:01:01.000+0000\"",
},
{
name: "test with ms",
inputTime: "2020-04-01T01:01:01.001Z",
expected: "\"2020-04-01T01:01:01.001+0000\"",
},
}
for _, tt := range testCases {
t.Run(tt.name, func(t *testing.T) {
rawTime, _ := time.Parse(timeFormatParseFrom, tt.inputTime)
time := Time(rawTime)
got, _ := time.MarshalJSON()
if string(got) != tt.expected {
t.Errorf("Time.MarshalJSON() = %v, want %v", string(got), tt.expected)
}
})
}
}