Skip to content
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

bug-39 fix date test #43

Merged
merged 2 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ jobs:
test:
strategy:
matrix:
go-version: [1.19.x]
go-version: [1.21.x]
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
Expand All @@ -29,7 +29,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.19.x
go-version: 1.21.x
- name: Checkout code
uses: actions/checkout@v2
- uses: actions/cache@v2
Expand Down
22 changes: 11 additions & 11 deletions harvest/date_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func TestDate_String(t *testing.T) {
loc, err := time.LoadLocation("Local")
assert.NoError(t, err)

time.Local = loc
time.UTC = loc

tests := []struct {
name string
Expand All @@ -25,17 +25,17 @@ func TestDate_String(t *testing.T) {
}{
{
name: "2nd of January",
input: harvest.Date{Time: time.Date(2006, time.January, 2, 0, 0, 0, 0, time.Local)},
input: harvest.Date{Time: time.Date(2006, time.January, 2, 0, 0, 0, 0, time.UTC)},
want: "2006-01-02",
},
{
name: "31th of December",
input: harvest.Date{Time: time.Date(2006, time.December, 31, 0, 0, 0, 0, time.Local)},
input: harvest.Date{Time: time.Date(2006, time.December, 31, 0, 0, 0, 0, time.UTC)},
want: "2006-12-31",
},
{
name: "6th of May",
input: harvest.Date{Time: time.Date(2016, time.May, 6, 0, 0, 0, 0, time.Local)},
input: harvest.Date{Time: time.Date(2016, time.May, 6, 0, 0, 0, 0, time.UTC)},
want: "2016-05-06",
},
}
Expand All @@ -55,7 +55,7 @@ func TestDate_UnmarshalJSONParse(t *testing.T) {
loc, err := time.LoadLocation("Local")
assert.NoError(t, err)

time.Local = loc
time.UTC = loc

type args struct {
str string
Expand All @@ -69,19 +69,19 @@ func TestDate_UnmarshalJSONParse(t *testing.T) {
{
name: "2nd of January",
args: args{"2006-01-02"},
want: harvest.Date{Time: time.Date(2006, time.January, 2, 0, 0, 0, 0, time.Local)},
want: harvest.Date{Time: time.Date(2006, time.January, 2, 0, 0, 0, 0, time.UTC)},
err: nil,
},
{
name: "31th of December",
args: args{"2006-12-31"},
want: harvest.Date{Time: time.Date(2006, time.December, 31, 0, 0, 0, 0, time.Local)},
want: harvest.Date{Time: time.Date(2006, time.December, 31, 0, 0, 0, 0, time.UTC)},
err: nil,
},
{
name: "With quotes",
args: args{"\"2006-04-05\""},
want: harvest.Date{Time: time.Date(2006, time.April, 5, 0, 0, 0, 0, time.Local)},
want: harvest.Date{Time: time.Date(2006, time.April, 5, 0, 0, 0, 0, time.UTC)},
err: nil,
},
{
Expand Down Expand Up @@ -140,7 +140,7 @@ func TestDate_UnmarshalJSON(t *testing.T) {
args: args{`{"id": 123, "date": "2019-01-02"}`},
want: foo{
ID: harvest.Int64(123),
Date: &harvest.Date{Time: time.Date(2019, time.January, 2, 0, 0, 0, 0, time.Local)},
Date: &harvest.Date{Time: time.Date(2019, time.January, 2, 0, 0, 0, 0, time.UTC)},
},
err: nil,
},
Expand Down Expand Up @@ -203,7 +203,7 @@ func TestDate_EncodeValues(t *testing.T) {
name: "All fields filled in",
args: &foo{
Query: harvest.String("foo"),
Date: &harvest.Date{Time: time.Date(2019, time.January, 2, 0, 0, 0, 0, time.Local)},
Date: &harvest.Date{Time: time.Date(2019, time.January, 2, 0, 0, 0, 0, time.UTC)},
},
want: url.Values{
"query": []string{"foo"},
Expand All @@ -213,7 +213,7 @@ func TestDate_EncodeValues(t *testing.T) {
{
name: "No query",
args: &foo{
Date: &harvest.Date{Time: time.Date(2019, time.January, 2, 0, 0, 0, 0, time.Local)},
Date: &harvest.Date{Time: time.Date(2019, time.January, 2, 0, 0, 0, 0, time.UTC)},
},
want: url.Values{
"date": []string{"2019-01-02"},
Expand Down
Loading