This repository has been archived by the owner on Mar 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit tests for event time bound parsing
Signed-off-by: Nick Hale <[email protected]>
- Loading branch information
Showing
1 changed file
with
68 additions
and
0 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
pkg/server/registry/apigroups/acorn/events/strategy_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) | ||
} | ||
} |