# Test Suite error - time.Local vs time.UTC?

**URL:** <https://discuss.elastic.co/t/test-suite-error-time-local-vs-time-utc/286735>\
**Category:** Beats\
**Tags:** libbeat\
**Created:** [October 14, 2021, 2:18pm UTC](https://discuss.elastic.co/t/test-suite-error-time-local-vs-time-utc/286735 "2021-10-14T14:18:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hinchliff](https://avatars.discourse-cdn.com/v4/letter/h/e274bd/32.png) [@hinchliff](https://discuss.elastic.co/u/hinchliff)\
**Post date:** [October 14, 2021, 2:18pm UTC](https://discuss.elastic.co/t/test-suite-error-time-local-vs-time-utc/286735/1 "2021-10-14T14:18:23Z")

</div>

Seeing some failures for `make testsuite` for libbeat, that seem to be Timezone related. (My computer is in US Eastern.)

```auto
command [go test -cover -coverprofile /tmp/gotestcover-1560318489 github.com/elastic/beats/v7/libbeat/common/fmtstr]: exit status 1
--- FAIL: TestEventFormatString (0.00s)
    formatevents_test.go:135: test(0): empty string
    formatevents_test.go:135: test(1): no fields configured
    formatevents_test.go:135: test(2): expand event field
    formatevents_test.go:135: test(3): expand with default
    formatevents_test.go:135: test(4): expand nested event field
    formatevents_test.go:135: test(5): expand nested event field (alt. syntax)
    formatevents_test.go:135: test(6): multiple event fields
    formatevents_test.go:135: test(7): same fields
    formatevents_test.go:135: test(8): same fields with default (first)
    formatevents_test.go:135: test(9): same fields with default (second)
    formatevents_test.go:135: test(10): test timestamp formatter
    formatevents_test.go:135: test(11): test timestamp formatter
    formatevents_test.go:146: 
        	Error Trace:	formatevents_test.go:146
        	Error: Not equal: 
        	            	expected: "2015-05-01T20:12:34.000Z: 2015.05.01"
        	            	actual : "2015-05-02T00:12:34.000Z: 2015.05.01"
        	            	
        	            	Diff:
        	            	--- Expected
        	            	+++ Actual
        	            	@@ -1 +1 @@
        	            	-2015-05-01T20:12:34.000Z: 2015.05.01
        	            	+2015-05-02T00:12:34.000Z: 2015.05.01
        	Test: TestEventFormatString
--- FAIL: TestTimestampFormatString (0.00s)
    formattimestamp_test.go:89: test(0): empty string
    formattimestamp_test.go:89: test(1): no fields configured
    formattimestamp_test.go:89: test(2): expand field
    formattimestamp_test.go:89: test(3): expand with default
    formattimestamp_test.go:89: test(4): expand nested field
    formattimestamp_test.go:89: test(5): test timestamp formatter
    formattimestamp_test.go:89: test(6): test timestamp formatter
    formattimestamp_test.go:106: 
        	Error Trace:	formattimestamp_test.go:106
        	Error: Not equal: 
        	            	expected: "2015-05-01T20:12:34.000Z: 2015.05.01"
        	            	actual : "2015-05-02T00:12:34.000Z: 2015.05.01"
        	            	
        	            	Diff:
        	            	--- Expected
        	            	+++ Actual
        	            	@@ -1 +1 @@
        	            	-2015-05-01T20:12:34.000Z: 2015.05.01
        	            	+2015-05-02T00:12:34.000Z: 2015.05.01
        	Test: TestTimestampFormatString
FAIL
coverage: 83.9% of statements
FAIL	github.com/elastic/beats/v7/libbeat/common/fmtstr	0.442s
FAIL

```

and

```auto

command [go test -cover -coverprofile /tmp/gotestcover-165778516 github.com/elastic/beats/v7/libbeat/common/fmtstr]: exit status 1
--- FAIL: TestTimestampFormatString (0.00s)
    formattimestamp_test.go:89: test(0): empty string
    formattimestamp_test.go:89: test(1): no fields configured
    formattimestamp_test.go:89: test(2): expand field
    formattimestamp_test.go:89: test(3): expand with default
    formattimestamp_test.go:89: test(4): expand nested field
    formattimestamp_test.go:89: test(5): test timestamp formatter
    formattimestamp_test.go:89: test(6): test timestamp formatter
    formattimestamp_test.go:106: 
        	Error Trace:	formattimestamp_test.go:106
        	Error: Not equal: 
        	            	expected: "2015-05-01T20:12:34.000Z: 2015.05.01"
        	            	actual : "2015-05-02T00:12:34.000Z: 2015.05.01"
        	            	
        	            	Diff:
        	            	--- Expected
        	            	+++ Actual
        	            	@@ -1 +1 @@
        	            	-2015-05-01T20:12:34.000Z: 2015.05.01
        	            	+2015-05-02T00:12:34.000Z: 2015.05.01
        	Test: TestTimestampFormatString
FAIL
coverage: 83.9% of statements
FAIL	github.com/elastic/beats/v7/libbeat/common/fmtstr	0.327s
FAIL

```

For all of these errors, the test code is using `time.Local`, but the comparing to a time that is in UTC. That seems like an error in the test suite? Changing to `time.UTC` seems to give correct test operation.

I'm happy to make a PR to fix these 4 unit tests. But the contributing guidelines say to create a discussion topic first.

---

<div class="post-metadata">

**Author:** ![hinchliff](https://avatars.discourse-cdn.com/v4/letter/h/e274bd/32.png) [@hinchliff](https://discuss.elastic.co/u/hinchliff)\
**Post date:** [October 15, 2021, 2:04pm UTC](https://discuss.elastic.co/t/test-suite-error-time-local-vs-time-utc/286735/2 "2021-10-15T14:04:11Z")

</div>

- GitHub issue: [libbeat fmtstr tests fail outside of UTC · Issue #28472 · elastic/beats · GitHub](https://github.com/elastic/beats/issues/28472)
- GitHub PR: [#28472 fix flaky tests in libbeat fmtstr to use time.UTC instead of time.Local by hinchliff · Pull Request #28473 · elastic/beats · GitHub](https://github.com/elastic/beats/pull/28473)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [November 12, 2021, 4:04pm UTC](https://discuss.elastic.co/t/test-suite-error-time-local-vs-time-utc/286735/3 "2021-11-12T16:04:39Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
