Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,13 +444,15 @@ func generateTestKey(t *testing.T) (*rsa.PrivateKey, string) {
}

func TestOptionalBasicTypes(t *testing.T) {
now := time.Date(2025, 1, 1, 0, 0, 0, 0, time.UTC)
tests := []struct {
name string
params types.ParamValues
shouldErr bool
expectInt int
expectBool bool
expectDur time.Duration
expectTime time.Time
}{
{
name: "no value for optional params",
Expand All @@ -463,6 +465,7 @@ func TestOptionalBasicTypes(t *testing.T) {
expectInt: 42,
expectBool: true,
expectDur: time.Hour,
expectTime: now,
},
{
name: "empty string for optional params",
Expand All @@ -471,13 +474,15 @@ func TestOptionalBasicTypes(t *testing.T) {
"i": "",
"b": "",
"d": "",
"t": "",
"req": "2",
},
},
shouldErr: false,
expectInt: 42,
expectBool: true,
expectDur: time.Hour,
expectTime: now,
},
{
name: "valid values for optional params",
Expand All @@ -486,13 +491,15 @@ func TestOptionalBasicTypes(t *testing.T) {
"i": "123",
"b": "false",
"d": "10s",
"t": "2024-01-01T00:00:00Z",
"req": "3",
},
},
shouldErr: false,
expectInt: 123,
expectBool: false,
expectDur: 10 * time.Second,
expectTime: time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC),
},
{
name: "empty string for required param",
Expand All @@ -511,11 +518,13 @@ func TestOptionalBasicTypes(t *testing.T) {
I int `param:",optional"`
B bool `param:",optional"`
D time.Duration `param:",optional"`
T time.Time `param:",optional"`
Req int
}{
I: 42,
B: true,
D: time.Hour,
T: now,
Req: 99,
}

Expand All @@ -531,6 +540,7 @@ func TestOptionalBasicTypes(t *testing.T) {
assert.Equal(t, tt.expectInt, cfg.I)
assert.Equal(t, tt.expectBool, cfg.B)
assert.Equal(t, tt.expectDur, cfg.D)
assert.EqualFn(t, tt.expectTime, cfg.T)
}
})
}
Expand Down