MCPcopy Index your code
hub / github.com/google/go-github / TestTimestamp_Unmarshal

Function TestTimestamp_Unmarshal

github/timestamp_test.go:54–86  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

52}
53
54func TestTimestamp_Unmarshal(t *testing.T) {
55 t.Parallel()
56 testCases := []struct {
57 desc string
58 data string
59 want Timestamp
60 wantErr bool
61 equal bool
62 }{
63 {"Reference", referenceTimeStr, Timestamp{referenceTime}, false, true},
64 {"ReferenceUnix", referenceUnixTimeStr, Timestamp{referenceTime}, false, true},
65 {"ReferenceUnixMillisecond", referenceUnixTimeStrMilliSeconds, Timestamp{referenceTime}, false, true},
66 {"ReferenceFractional", referenceTimeStrFractional, Timestamp{referenceTime}, false, true},
67 {"Empty", emptyTimeStr, Timestamp{}, false, true},
68 {"UnixStart", `0`, Timestamp{unixOrigin}, false, true},
69 {"Mismatch", referenceTimeStr, Timestamp{}, false, false},
70 {"MismatchUnix", `0`, Timestamp{}, false, false},
71 {"Invalid", `"asdf"`, Timestamp{referenceTime}, true, false},
72 {"OffByMillisecond", `1136214245001`, Timestamp{referenceTime}, false, false},
73 }
74 for _, tc := range testCases {
75 var got Timestamp
76 err := json.Unmarshal([]byte(tc.data), &got)
77 if gotErr := err != nil; gotErr != tc.wantErr {
78 t.Errorf("%v: gotErr=%v, wantErr=%v, err=%v", tc.desc, gotErr, tc.wantErr, err)
79 continue
80 }
81 equal := got.Equal(tc.want)
82 if equal != tc.equal {
83 t.Errorf("%v: got=%#v, want=%#v, equal=%v, want=%v", tc.desc, got, tc.want, equal, tc.equal)
84 }
85 }
86}
87
88func TestTimestamp_MarshalReflexivity(t *testing.T) {
89 t.Parallel()

Callers

nothing calls this directly

Calls 1

EqualMethod · 0.95

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…