github.com/tilt-dev/tilt@v0.33.15-0.20240515162809-0a22ed45d8a0/pkg/apis/time_test.go (about) 1 package apis_test 2 3 import ( 4 "encoding/json" 5 "testing" 6 "time" 7 8 "github.com/stretchr/testify/require" 9 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 10 11 "github.com/tilt-dev/tilt/pkg/apis" 12 ) 13 14 func TestMicroTime(t *testing.T) { 15 now := apis.NowMicro() 16 require.Equal(t, 0, now.Nanosecond()%int(time.Microsecond)) 17 d, err := json.Marshal(now) 18 require.NoError(t, err) 19 var out metav1.MicroTime 20 require.NoError(t, json.Unmarshal(d, &out)) 21 // N.B. this is an intentional use of == operator against a time value 22 // because in this case we really want to know that the struct is identical 23 require.True(t, now == out, 24 "Time did not round-trip\noriginal: %s\nafter: %s", 25 now.String(), out.String()) 26 } 27 28 func TestTime(t *testing.T) { 29 now := apis.Now() 30 require.Equal(t, 0, now.Nanosecond()) 31 d, err := json.Marshal(now) 32 require.NoError(t, err) 33 var out metav1.Time 34 require.NoError(t, json.Unmarshal(d, &out)) 35 // N.B. this is an intentional use of == operator against a time value 36 // because in this case we really want to know that the struct is identical 37 require.True(t, now == out, 38 "Time did not round-trip\noriginal: %s\nafter: %s", 39 now.String(), out.String()) 40 }