| 10 | ) |
| 11 | |
| 12 | func TestTimeYAML(t *testing.T) { |
| 13 | { |
| 14 | type TestStruct struct { |
| 15 | T Time `yaml:"time"` |
| 16 | } |
| 17 | |
| 18 | var testStruct TestStruct |
| 19 | require.NoError(t, testStruct.T.Set("2020-10-20")) |
| 20 | |
| 21 | marshaled, err := yaml.Marshal(testStruct) |
| 22 | require.NoError(t, err) |
| 23 | |
| 24 | expected := `time: "2020-10-20T00:00:00Z"` + "\n" |
| 25 | assert.Equal(t, expected, string(marshaled)) |
| 26 | |
| 27 | var actualStruct TestStruct |
| 28 | err = yaml.Unmarshal([]byte(expected), &actualStruct) |
| 29 | require.NoError(t, err) |
| 30 | assert.Equal(t, testStruct, actualStruct) |
| 31 | } |
| 32 | |
| 33 | { |
| 34 | type TestStruct struct { |
| 35 | T *Time `yaml:"time"` |
| 36 | } |
| 37 | |
| 38 | var testStruct TestStruct |
| 39 | testStruct.T = &Time{} |
| 40 | require.NoError(t, testStruct.T.Set("2020-10-20")) |
| 41 | |
| 42 | marshaled, err := yaml.Marshal(testStruct) |
| 43 | require.NoError(t, err) |
| 44 | |
| 45 | expected := `time: "2020-10-20T00:00:00Z"` + "\n" |
| 46 | assert.Equal(t, expected, string(marshaled)) |
| 47 | |
| 48 | var actualStruct TestStruct |
| 49 | err = yaml.Unmarshal([]byte(expected), &actualStruct) |
| 50 | require.NoError(t, err) |
| 51 | assert.Equal(t, testStruct, actualStruct) |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | func TestTimeFormats(t *testing.T) { |
| 56 | ts := &Time{} |