@@ -36,6 +36,7 @@ func TestAfter(t *testing.T) {
|
||||
if err == nil {
|
||||
t.Fatal("expected validation error")
|
||||
}
|
||||
|
||||
if err.Code != ErrorCodeOutOfRange {
|
||||
t.Errorf("expected error code %s, got %s", ErrorCodeOutOfRange, err.Code)
|
||||
}
|
||||
@@ -50,6 +51,7 @@ func TestAfter(t *testing.T) {
|
||||
|
||||
t.Run("nil pointer", func(t *testing.T) {
|
||||
var timeVal *time.Time
|
||||
|
||||
err := After(now)(timeVal)
|
||||
if err != nil {
|
||||
t.Errorf("expected no error for nil, got: %v", err)
|
||||
@@ -74,6 +76,7 @@ func TestBefore(t *testing.T) {
|
||||
if err == nil {
|
||||
t.Fatal("expected validation error")
|
||||
}
|
||||
|
||||
if err.Code != ErrorCodeOutOfRange {
|
||||
t.Errorf("expected error code %s, got %s", ErrorCodeOutOfRange, err.Code)
|
||||
}
|
||||
@@ -88,6 +91,7 @@ func TestBefore(t *testing.T) {
|
||||
|
||||
t.Run("nil pointer", func(t *testing.T) {
|
||||
var timeVal *time.Time
|
||||
|
||||
err := Before(now)(timeVal)
|
||||
if err != nil {
|
||||
t.Errorf("expected no error for nil, got: %v", err)
|
||||
@@ -101,6 +105,7 @@ func TestRangeDuration(t *testing.T) {
|
||||
|
||||
t.Run("duration within range", func(t *testing.T) {
|
||||
duration := 30 * time.Minute
|
||||
|
||||
err := RangeDuration(minDuration, maxDuration)(&duration)
|
||||
if err != nil {
|
||||
t.Errorf("expected no error, got: %v", err)
|
||||
@@ -109,6 +114,7 @@ func TestRangeDuration(t *testing.T) {
|
||||
|
||||
t.Run("duration at minimum", func(t *testing.T) {
|
||||
duration := 10 * time.Minute
|
||||
|
||||
err := RangeDuration(minDuration, maxDuration)(&duration)
|
||||
if err != nil {
|
||||
t.Errorf("expected no error, got: %v", err)
|
||||
@@ -117,6 +123,7 @@ func TestRangeDuration(t *testing.T) {
|
||||
|
||||
t.Run("duration at maximum", func(t *testing.T) {
|
||||
duration := 1 * time.Hour
|
||||
|
||||
err := RangeDuration(minDuration, maxDuration)(&duration)
|
||||
if err != nil {
|
||||
t.Errorf("expected no error, got: %v", err)
|
||||
@@ -125,10 +132,12 @@ func TestRangeDuration(t *testing.T) {
|
||||
|
||||
t.Run("duration below minimum", func(t *testing.T) {
|
||||
duration := 5 * time.Minute
|
||||
|
||||
err := RangeDuration(minDuration, maxDuration)(&duration)
|
||||
if err == nil {
|
||||
t.Fatal("expected validation error")
|
||||
}
|
||||
|
||||
if err.Code != ErrorCodeOutOfRange {
|
||||
t.Errorf("expected error code %s, got %s", ErrorCodeOutOfRange, err.Code)
|
||||
}
|
||||
@@ -136,10 +145,12 @@ func TestRangeDuration(t *testing.T) {
|
||||
|
||||
t.Run("duration above maximum", func(t *testing.T) {
|
||||
duration := 2 * time.Hour
|
||||
|
||||
err := RangeDuration(minDuration, maxDuration)(&duration)
|
||||
if err == nil {
|
||||
t.Fatal("expected validation error")
|
||||
}
|
||||
|
||||
if err.Code != ErrorCodeOutOfRange {
|
||||
t.Errorf("expected error code %s, got %s", ErrorCodeOutOfRange, err.Code)
|
||||
}
|
||||
@@ -147,6 +158,7 @@ func TestRangeDuration(t *testing.T) {
|
||||
|
||||
t.Run("nil pointer", func(t *testing.T) {
|
||||
var duration *time.Duration
|
||||
|
||||
err := RangeDuration(minDuration, maxDuration)(duration)
|
||||
if err != nil {
|
||||
t.Errorf("expected no error for nil, got: %v", err)
|
||||
|
||||
Reference in New Issue
Block a user