-
Notifications
You must be signed in to change notification settings - Fork 345
fix: make DayValue serialization timezone stable #1114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
8fd7d66
4d59c7e
c9bb4ae
aa954fa
59b8168
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ package flagext | |
|
|
||
| import ( | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
|
|
@@ -63,6 +64,36 @@ func TestDayValueYAML(t *testing.T) { | |
| require.NoError(t, err) | ||
| assert.Equal(t, expected, actual) | ||
|
|
||
| var actualStruct TestStruct | ||
| err = yaml.Unmarshal(expected, &actualStruct) | ||
| require.NoError(t, err) | ||
| assert.Equal(t, testStruct, actualStruct) | ||
| } | ||
| // Test UTC-stable string and YAML serialization in western timezones. | ||
| { | ||
| loc, err := time.LoadLocation("America/Los_Angeles") | ||
| if err != nil { | ||
| loc = time.FixedZone("UTC-8", -8*60*60) | ||
| } | ||
|
|
||
| originalLocal := time.Local | ||
| time.Local = loc | ||
| defer func() { | ||
| time.Local = originalLocal | ||
| }() | ||
| type TestStruct struct { | ||
| Day *DayValue `yaml:"day"` | ||
| } | ||
| var testStruct TestStruct | ||
| testStruct.Day = &DayValue{} | ||
| require.NoError(t, testStruct.Day.Set("1985-06-02")) | ||
| expected := []byte(`day: "1985-06-02" | ||
| `) | ||
|
|
||
| actual, err := yaml.Marshal(testStruct) | ||
| require.NoError(t, err) | ||
| assert.Equal(t, expected, actual) | ||
|
Comment on lines
+84
to
+95
|
||
|
|
||
| var actualStruct TestStruct | ||
| err = yaml.Unmarshal(expected, &actualStruct) | ||
| require.NoError(t, err) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment says this block tests "UTC-stable string and YAML serialization", but the test only asserts YAML marshal/unmarshal output and never checks DayValue.String(). Either add an assertion for the String() output under the modified time.Local, or adjust the comment to only mention YAML serialization to keep the test intent accurate.