Skip to content

Commit

Permalink
Test UnixMilli#MarshalJSON()
Browse files Browse the repository at this point in the history
  • Loading branch information
Al2Klimov committed Jul 7, 2023
1 parent 7568c47 commit b8ed25c
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions pkg/types/unix_milli_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package types

import (
"github.com/stretchr/testify/require"
"testing"
"time"
"unicode/utf8"
)

func TestUnixMilli_MarshalJSON(t *testing.T) {
subtests := []struct {
name string
input UnixMilli
output string
}{
{"zero", UnixMilli{}, `null`},
{"epoch", UnixMilli(time.Unix(0, 0)), `0`},
{"nonzero", UnixMilli(time.Unix(1234567890, 62500000)), `1234567890062`},
}

for _, st := range subtests {
t.Run(st.name, func(t *testing.T) {
actual, err := st.input.MarshalJSON()

require.NoError(t, err)
require.True(t, utf8.Valid(actual))
require.Equal(t, st.output, string(actual))
})
}
}

0 comments on commit b8ed25c

Please sign in to comment.