From 7319e13fde64eb6dd3489e5bf25c2a5792d11712 Mon Sep 17 00:00:00 2001 From: frairon Date: Fri, 6 Feb 2026 10:41:21 +0100 Subject: [PATCH] set tester default context timestamp to zero --- tester/tester.go | 10 +++------- tester/tester_test.go | 2 +- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/tester/tester.go b/tester/tester.go index 1831bf2d..98692193 100644 --- a/tester/tester.go +++ b/tester/tester.go @@ -29,7 +29,7 @@ func WithHeaders(headers goka.Headers) EmitOption { } // WithTime causes the tester to emit the message with passed timestamp. -// default is time.Now() +// default is a zero timestamp func WithTime(time time.Time) EmitOption { return func(opts *emitOption) { opts.time = time @@ -160,9 +160,7 @@ func (tt *Tester) EmitterProducerBuilder() goka.ProducerBuilder { // This takes care of queueing calls // to handled topics or putting the emitted messages in the emitted-messages-list func (tt *Tester) handleEmit(topic string, key string, value []byte, options ...EmitOption) *goka.Promise { - opts := &emitOption{ - time: time.Now(), - } + opts := new(emitOption) opts.applyOptions(options...) _, finisher := goka.NewPromiseWithFinisher() @@ -418,9 +416,7 @@ func (tt *Tester) GetTableKeys(table goka.Table) []string { func (tt *Tester) Consume(topic string, key string, msg interface{}, options ...EmitOption) { tt.waitStartup() - opts := &emitOption{ - time: time.Now(), - } + opts := new(emitOption) opts.applyOptions(options...) value := reflect.ValueOf(msg) if msg == nil || (value.Kind() == reflect.Ptr && value.IsNil()) { diff --git a/tester/tester_test.go b/tester/tester_test.go index 883558ac..487cf741 100644 --- a/tester/tester_test.go +++ b/tester/tester_test.go @@ -70,7 +70,7 @@ func TestTesterConsume(t *testing.T) { require.EqualValues(t, "some-key", key) require.EqualValues(t, "value", value) // the test should not take longer than 1 second - require.Truef(t, time.Since(timestamp).Seconds() < 1, "expected roughly %v, got %v", time.Now(), timestamp) + require.True(t, timestamp.IsZero()) // consume with timestamp option gkt.Consume("input", "anotherkey", "value", WithTime(time.Unix(123, 0)))