Skip to content

Commit

Permalink
added the CheckUntil function from ancla
Browse files Browse the repository at this point in the history
  • Loading branch information
maurafortino committed Jul 17, 2024
1 parent 9947a7d commit ffe3451
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 333 deletions.
29 changes: 29 additions & 0 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,3 +293,32 @@ func (noUntilOption) Validate(i any) error {
func (noUntilOption) String() string {
return "NoUntil()"
}

func Until(now func() time.Time, jitter, max time.Duration) Option {
return untilOption{
now: now,
jitter: jitter,
max: max,
}
}

type untilOption struct {
now func() time.Time
jitter time.Duration
max time.Duration
}

func (u untilOption) Validate(i any) error {
switch r := i.(type) {
case *RegistrationV1:
return r.CheckUntil(u.now, u.jitter, u.max)
case *RegistrationV2:
return fmt.Errorf("%w: RegistrationV2 does not use an Until field", ErrInvalidType)
default:
return ErrUknownType
}
}

func (u untilOption) String() string {
return fmt.Sprintf("untilOption(%v, %v, %v)", u.jitter.String(), u.max.String(), u.now().String())
}
16 changes: 16 additions & 0 deletions options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import (
"github.com/xmidt-org/urlegit"
)

var mockNow = func() time.Time {
return time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC)
}

type optionTest struct {
description string
in any
Expand Down Expand Up @@ -527,6 +531,18 @@ func TestNoUntil(t *testing.T) {
})
}

// func TestUntilOption(t *testing.T) {
// run_tests(t, []optionTest{
// {
// description: "success, until",
// in: &RegistrationV1{
// Until: time.Now(),
// },
// opt: Until(mockNow, time.Duration(1*time.Minute), time.Duration(5*time.Minute)),
// },
// })
// }

func run_tests(t *testing.T, tests []optionTest) {
for _, tc := range tests {
t.Run(tc.description, func(t *testing.T) {
Expand Down
109 changes: 0 additions & 109 deletions validationConfig.go

This file was deleted.

221 changes: 0 additions & 221 deletions validationConfig_test.go

This file was deleted.

Loading

0 comments on commit ffe3451

Please sign in to comment.