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

Failing tests #268

Open
deining opened this issue Dec 12, 2024 · 4 comments · May be fixed by #269
Open

Failing tests #268

deining opened this issue Dec 12, 2024 · 4 comments · May be fixed by #269
Labels
Bug Report a reproducible bug or regression

Comments

@deining
Copy link
Contributor

deining commented Dec 12, 2024

I encountered issue with running go test in the project's root. Various tests failed for me.

Example:

traveler_unit_test.go, function TestCarbon_SubNanoseconds:

I expected the test to pass, but it didn't:

Running tool: /usr/local/go/bin/go test -timeout 30s -run ^TestCarbon_SubNanoseconds$ github.com/dromara/carbon/v2

--- FAIL: TestCarbon_SubNanoseconds (0.00s)
    --- FAIL: TestCarbon_SubNanoseconds/case2 (0.00s)
        /home/andreas/carbon/traveler_unit_test.go:2925: 
            	Error Trace:	/home/andreas/carbon/traveler_unit_test.go:2925
            	Error:      	Not equal: 
            	            	expected: "2020-08-05 13:14:15.222222221 +0800 CST"
            	            	actual  : "2020-08-05 13:14:15.222222221 +0200 CEST"
            	            	
            	            	Diff:
            	            	--- Expected
            	            	+++ Actual
            	            	@@ -1 +1 @@
            	            	-2020-08-05 13:14:15.222222221 +0800 CST
            	            	+2020-08-05 13:14:15.222222221 +0200 CEST
            	Test:       	TestCarbon_SubNanoseconds/case2
            	Messages:   	SubNanoseconds()
    --- FAIL: TestCarbon_SubNanoseconds/case3 (0.00s)
        /home/andreas/carbon/traveler_unit_test.go:2925: 
            	Error Trace:	/home/andreas/carbon/traveler_unit_test.go:2925
            	Error:      	Not equal: 
            	            	expected: "2020-08-05 13:14:15.22222222 +0800 CST"
            	            	actual  : "2020-08-05 13:14:15.22222222 +0200 CEST"
            	            	
            	            	Diff:
            	            	--- Expected
            	            	+++ Actual
            	            	@@ -1 +1 @@
            	            	-2020-08-05 13:14:15.22222222 +0800 CST
            	            	+2020-08-05 13:14:15.22222222 +0200 CEST
            	Test:       	TestCarbon_SubNanoseconds/case3
            	Messages:   	SubNanoseconds()
FAIL
FAIL	github.com/dromara/carbon/v2	0.006s
FAIL

I suspect the reason is the fact that I am on a time zone different from the test's author. My time zone:

$ timedatectl
               Local time: Do 2024-12-12 21:45:43 CET
           Universal time: Do 2024-12-12 20:45:43 UTC
                 RTC time: Do 2024-12-12 21:45:44
                Time zone: Europe/Berlin (CET, +0100)
@deining deining added the Bug Report a reproducible bug or regression label Dec 12, 2024
@ccoVeille
Copy link
Contributor

ccoVeille commented Dec 12, 2024

I think is exactly what I'm fixing in another project

Timezones are always fun and full of surprises.

@ccoVeille
Copy link
Contributor

But here in the test it could be way simpler

Calling .SetLocation(time.UTC) and updating all could be enough, I think.

@ccoVeille
Copy link
Contributor

I will try to provide a fix

@ccoVeille
Copy link
Contributor

ccoVeille commented Dec 12, 2024

There are many problems in the code right now.

They should be addressed

But for now, here is a quick fix if you want to launch the unit tests:

Take a look at this
https://github.com/dromara/carbon/blob/master/.github/workflows/test.yml#L6

so you can launch the unit tests by using this

$ TZ=PRC go test ./...

I'm not saying it's a good solution, I'm saying that's why the CI works while it shouldn't

@ccoVeille ccoVeille linked a pull request Dec 12, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Report a reproducible bug or regression
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants