Update Option interface

- Added `String()`, `Type()`, and `Value()` methods to the interface to
  aid with debugging and error handling.
This commit is contained in:
Ken Hibino
2020-10-10 06:46:47 -07:00
parent 50e7f38365
commit 8312515e64
5 changed files with 61 additions and 60 deletions

View File

@@ -5,7 +5,6 @@
package asynq
import (
"fmt"
"testing"
"time"
@@ -77,37 +76,3 @@ func TestScheduler(t *testing.T) {
}
}
}
func TestStringifyOptions(t *testing.T) {
now := time.Now()
oneHourFromNow := now.Add(1 * time.Hour)
twoHoursFromNow := now.Add(2 * time.Hour)
tests := []struct {
opts []Option
want string
}{
{
opts: []Option{MaxRetry(10)},
want: "MaxRetry(10)",
},
{
opts: []Option{Queue("custom"), Timeout(1 * time.Minute)},
want: `Queue("custom"), Timeout(1m0s)`,
},
{
opts: []Option{ProcessAt(oneHourFromNow), Deadline(twoHoursFromNow)},
want: fmt.Sprintf("ProcessAt(%v), Deadline(%v)", oneHourFromNow, twoHoursFromNow),
},
{
opts: []Option{ProcessIn(30 * time.Minute), Unique(1 * time.Hour)},
want: "ProcessIn(30m0s), Unique(1h0m0s)",
},
}
for _, tc := range tests {
got := stringifyOptions(tc.opts)
if got != tc.want {
t.Errorf("got %v, want %v", got, tc.want)
}
}
}