Skip to content

Commit

Permalink
chore: add test case with time.Time in struct
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed Nov 29, 2023
1 parent 3694961 commit a533a04
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions tests/serialize_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tests

import (
"fmt"
"testing"
"time"

Expand All @@ -11,12 +12,18 @@ import (
_ "github.com/robertkrimen/otto/underscore"
)

type myTime struct {
Time time.Time `json:"time"`
Duration time.Duration `json:"duration"`
}

func Test_serialize(t *testing.T) {
t.Parallel()

tests := []struct {
name string
in map[string]any
skip bool
want map[string]any
wantErr bool
}{
Expand Down Expand Up @@ -159,6 +166,22 @@ func Test_serialize(t *testing.T) {
},
},
},
{
name: "nested time.Duration",
skip: true, // TODO:
in: map[string]any{
"a": &myTime{
Time: time.Now(),
Duration: time.Second,
},
},
want: map[string]any{
"a": map[string]any{
"time": time.Now(),
"duration": time.Second,
},
},
},
{
name: "canary checker ctx.Environment",
in: map[string]any{
Expand Down Expand Up @@ -234,6 +257,10 @@ func Test_serialize(t *testing.T) {

for i := range tests {
tt := tests[i]
if tt.skip {
fmt.Printf("Skipping %s\n", tt.name)
continue
}

t.Run(tt.name, func(t *testing.T) {
t.Parallel()
Expand Down

0 comments on commit a533a04

Please sign in to comment.