From 83a65e5e4f7f6428c60bf07997270ffdf56de8fa Mon Sep 17 00:00:00 2001 From: ccoVeille <3875889+ccoVeille@users.noreply.github.com> Date: Thu, 12 Dec 2024 23:24:32 +0100 Subject: [PATCH] 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 --- .github/workflows/test.yml | 2 -- test.go | 13 +++++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ea1563af..990f7aac 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -2,8 +2,6 @@ name: test on: push -env: - TZ: "PRC" jobs: test: diff --git a/test.go b/test.go index eca6c584..c1947519 100644 --- a/test.go +++ b/test.go @@ -1,6 +1,7 @@ package carbon import ( + "os" "testing" ) @@ -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()