Skip to content

Commit

Permalink
ci: tests were written by someone in PRC timezone
Browse files Browse the repository at this point in the history
Nothing was working if you were not in this timezone.

The CI was forced in this timezone, but it was uneasy to catch.

Now all tests are launched in the PRC timezone.

We are using TestMain to sort this out.
https://pkg.go.dev/testing#hdr-Main
  • Loading branch information
ccoVeille committed Dec 12, 2024
1 parent 7117a5e commit 83a65e5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ name: test

on:
push
env:
TZ: "PRC"
jobs:

test:
Expand Down
13 changes: 13 additions & 0 deletions test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package carbon

import (
"os"
"testing"
)

Expand All @@ -22,6 +23,18 @@ func (c Carbon) IsSetTestNow() bool {
return c.testNow > 0
}

// TestMain sets up the testing environment for all tests
// https://pkg.go.dev/testing#hdr-Main
func TestMain(m *testing.M) {
// The whole tests were written for PRC timezone (China).
// The codebase of test is too large to be changed.
// Without this hack the tests will fail if you use a different timezone than PRC
// This will affect the way Go compute the timezone when using time.Local
_ = os.Setenv("TZ", "PRC")

m.Run()
}

func prepareTest(tb testing.TB) {
tb.Helper()

Expand Down

0 comments on commit 83a65e5

Please sign in to comment.