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 5, 2023
1 parent c2ffe0e commit b0f2aa3
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions pkg/types/unix_milli_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package types

import (
"encoding/json"
"github.com/stretchr/testify/require"
"testing"
"time"
)

func TestUnixMilli_MarshalJSON(t *testing.T) {
assertUnixMilli_MarshalJSON(t, UnixMilli{}, nil)
assertUnixMilli_MarshalJSON(t, UnixMilli(time.Unix(0, 0)), 0.0)
assertUnixMilli_MarshalJSON(t, UnixMilli(time.Unix(1234567890, 0)), 1234567890000.0)
}

func assertUnixMilli_MarshalJSON(t *testing.T, input UnixMilli, expect any) {
t.Helper()

jsn, err := input.MarshalJSON()
require.NoError(t, err)

var actual any
require.NoError(t, json.Unmarshal(jsn, &actual))

require.Equal(t, expect, actual)
}

0 comments on commit b0f2aa3

Please sign in to comment.