MCPcopy
hub / github.com/rs/zerolog / TestAppendTimes

Function TestAppendTimes

internal/cbor/time_test.go:204–251  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

202 }
203}
204func TestAppendTimes(t *testing.T) {
205 const timeFloatFmt = "2006-01-02T15:04:05.999999-07:00"
206 array := make([]time.Time, len(internal.TimeFloatTestcases))
207 want := make([]byte, 0)
208 want = append(want, 0x82) // start small array
209 for i, tt := range internal.TimeFloatTestcases {
210 array[i], _ = time.Parse(timeFloatFmt, tt.RfcStr)
211 want = append(want, []byte(tt.Out)...)
212 }
213
214 got := enc.AppendTimes([]byte{}, array, "unused")
215 if !bytes.Equal(got, want) {
216 t.Errorf("AppendTimes(%v)\ngot: 0x%s\nwant: 0x%s",
217 array, hex.EncodeToString(got),
218 hex.EncodeToString(want))
219 }
220
221 // now empty array case
222 array = make([]time.Time, 0)
223 want = make([]byte, 0)
224 want = append(want, 0x9f) // start and end array
225 want = append(want, 0xff) // for empty array
226 got = enc.AppendTimes([]byte{}, array, "unused")
227 if !bytes.Equal(got, want) {
228 t.Errorf("AppendTimes(%v)\ngot: 0x%s\nwant: 0x%s",
229 array, hex.EncodeToString(got),
230 hex.EncodeToString(want))
231 }
232
233 // now large array case
234 testtime, _ := time.Parse(timeFloatFmt, internal.TimeFloatTestcases[0].RfcStr)
235 outbytes := internal.TimeFloatTestcases[0].Out
236 array = make([]time.Time, 24)
237 want = make([]byte, 0)
238 want = append(want, 0x98) // start a large array
239 want = append(want, 0x18) // of length 24
240 for i := 0; i < len(array); i++ {
241 array[i] = testtime
242 want = append(want, []byte(outbytes)...)
243 }
244 got = enc.AppendTimes([]byte{}, array, "unused")
245 if !bytes.Equal(got, want) {
246 t.Errorf("AppendTimes(%v)\ngot: 0x%s\nwant: 0x%s",
247 array,
248 hex.EncodeToString(got),
249 hex.EncodeToString(want))
250 }
251}
252
253func TestAppendDurationFloat(t *testing.T) {
254 for _, tt := range internal.DurTestcases {

Callers

nothing calls this directly

Calls 1

AppendTimesMethod · 0.65

Tested by

no test coverage detected