Skip to content
This repository has been archived by the owner on Mar 16, 2024. It is now read-only.

Commit

Permalink
Add unit tests for event time bound parsing
Browse files Browse the repository at this point in the history
Signed-off-by: Nick Hale <[email protected]>
  • Loading branch information
njhale committed Jul 26, 2023
1 parent 69c7372 commit 9f9ff8d
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions pkg/server/registry/apigroups/acorn/events/strategy_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package events

import (
"testing"
"time"

internalv1 "github.com/acorn-io/runtime/pkg/apis/internal.acorn.io/v1"
"github.com/acorn-io/z"
"github.com/stretchr/testify/assert"
)

func TestParseTimeBound(t *testing.T) {
ts := internalv1.NowMicro()
type args struct {
raw string
now internalv1.MicroTime
}
type want struct {
parsed *internalv1.MicroTime
err assert.ErrorAssertionFunc
}
tests := []struct {
name string
args args
want want
}{
{
name: "Go duration",
args: args{
raw: "1m",
now: ts,
},
want: want{
parsed: z.Pointer(internalv1.NewMicroTime(ts.Add(-1 * time.Minute))),
err: assert.NoError,
},
},
{
name: "Without Z",
args: args{
raw: "2023-01-09T12:32:00",
},
want: want{
parsed: z.Pointer(internalv1.NewMicroTime(z.MustBe(time.Parse(time.RFC3339, "2023-01-09T12:32:00Z")))),
err: assert.NoError,
},
},
{
name: "With Z",
args: args{
raw: "2023-01-09T12:32:00Z",
},
want: want{
parsed: z.Pointer(internalv1.NewMicroTime(z.MustBe(time.Parse(time.RFC3339, "2023-01-09T12:32:00Z")))),
err: assert.NoError,
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
parsed, err := parseTimeBound(tt.args.raw, tt.args.now)
if !tt.want.err(t, err) {
return
}
assert.Equal(t, tt.want.parsed, parsed)
})
}
}

0 comments on commit 9f9ff8d

Please sign in to comment.