Skip to content

Commit 83a65e5

Browse files
committed
ci: tests were written by someone in PRC timezone
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
1 parent 7117a5e commit 83a65e5

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

.github/workflows/test.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ name: test
22

33
on:
44
push
5-
env:
6-
TZ: "PRC"
75
jobs:
86

97
test:

test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package carbon
22

33
import (
4+
"os"
45
"testing"
56
)
67

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

26+
// TestMain sets up the testing environment for all tests
27+
// https://pkg.go.dev/testing#hdr-Main
28+
func TestMain(m *testing.M) {
29+
// The whole tests were written for PRC timezone (China).
30+
// The codebase of test is too large to be changed.
31+
// Without this hack the tests will fail if you use a different timezone than PRC
32+
// This will affect the way Go compute the timezone when using time.Local
33+
_ = os.Setenv("TZ", "PRC")
34+
35+
m.Run()
36+
}
37+
2538
func prepareTest(tb testing.TB) {
2639
tb.Helper()
2740

0 commit comments

Comments
 (0)