Skip to content

Commit ea950a7

Browse files
feat(parser): add test for optional time.Time
1 parent 9711d5e commit ea950a7

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

parser_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,13 +444,15 @@ func generateTestKey(t *testing.T) (*rsa.PrivateKey, string) {
444444
}
445445

446446
func TestOptionalBasicTypes(t *testing.T) {
447+
now := time.Date(2025, 1, 1, 0, 0, 0, 0, time.UTC)
447448
tests := []struct {
448449
name string
449450
params types.ParamValues
450451
shouldErr bool
451452
expectInt int
452453
expectBool bool
453454
expectDur time.Duration
455+
expectTime time.Time
454456
}{
455457
{
456458
name: "no value for optional params",
@@ -463,6 +465,7 @@ func TestOptionalBasicTypes(t *testing.T) {
463465
expectInt: 42,
464466
expectBool: true,
465467
expectDur: time.Hour,
468+
expectTime: now,
466469
},
467470
{
468471
name: "empty string for optional params",
@@ -471,13 +474,15 @@ func TestOptionalBasicTypes(t *testing.T) {
471474
"i": "",
472475
"b": "",
473476
"d": "",
477+
"t": "",
474478
"req": "2",
475479
},
476480
},
477481
shouldErr: false,
478482
expectInt: 42,
479483
expectBool: true,
480484
expectDur: time.Hour,
485+
expectTime: now,
481486
},
482487
{
483488
name: "valid values for optional params",
@@ -486,13 +491,15 @@ func TestOptionalBasicTypes(t *testing.T) {
486491
"i": "123",
487492
"b": "false",
488493
"d": "10s",
494+
"t": "2024-01-01T00:00:00Z",
489495
"req": "3",
490496
},
491497
},
492498
shouldErr: false,
493499
expectInt: 123,
494500
expectBool: false,
495501
expectDur: 10 * time.Second,
502+
expectTime: time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC),
496503
},
497504
{
498505
name: "empty string for required param",
@@ -511,11 +518,13 @@ func TestOptionalBasicTypes(t *testing.T) {
511518
I int `param:",optional"`
512519
B bool `param:",optional"`
513520
D time.Duration `param:",optional"`
521+
T time.Time `param:",optional"`
514522
Req int
515523
}{
516524
I: 42,
517525
B: true,
518526
D: time.Hour,
527+
T: now,
519528
Req: 99,
520529
}
521530

@@ -531,6 +540,7 @@ func TestOptionalBasicTypes(t *testing.T) {
531540
assert.Equal(t, tt.expectInt, cfg.I)
532541
assert.Equal(t, tt.expectBool, cfg.B)
533542
assert.Equal(t, tt.expectDur, cfg.D)
543+
assert.EqualFn(t, tt.expectTime, cfg.T)
534544
}
535545
})
536546
}

0 commit comments

Comments
 (0)