-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions_test.go
More file actions
84 lines (67 loc) · 2.07 KB
/
Copy pathoptions_test.go
File metadata and controls
84 lines (67 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package durex_test
import (
"context"
"testing"
"time"
"github.com/simonovic86/durex"
"github.com/simonovic86/durex/storage"
)
func TestRetries_NegativeClampedToZero(t *testing.T) {
cmd := durex.NewFunc("test", func(ctx context.Context, cmd *durex.Instance) (durex.Result, error) {
return durex.Empty(), nil
}, durex.Retries(-5))
spec := cmd.Default()
if spec.Retries != 0 {
t.Errorf("expected retries clamped to 0, got %d", spec.Retries)
}
}
func TestPeriod_NegativeIgnored(t *testing.T) {
cmd := durex.NewFunc("test", func(ctx context.Context, cmd *durex.Instance) (durex.Result, error) {
return durex.Empty(), nil
}, durex.Period(-1*time.Second))
spec := cmd.Default()
if spec.Period != 0 {
t.Errorf("expected period to remain 0, got %v", spec.Period)
}
}
func TestDeadline_NegativeIgnored(t *testing.T) {
cmd := durex.NewFunc("test", func(ctx context.Context, cmd *durex.Instance) (durex.Result, error) {
return durex.Empty(), nil
}, durex.Deadline(-1*time.Second))
spec := cmd.Default()
if spec.Deadline != 0 {
t.Errorf("expected deadline to remain 0, got %v", spec.Deadline)
}
}
func TestWithRetries_NegativeClampedToZero(t *testing.T) {
type MyData struct {
Value string `json:"value"`
}
cmd := durex.NewTyped("test",
func(ctx context.Context, data MyData, cmd *durex.Instance) (durex.Result, error) {
return durex.Empty(), nil
},
durex.WithRetries[MyData](-3),
)
spec := cmd.Default()
if spec.Retries != 0 {
t.Errorf("expected retries clamped to 0, got %d", spec.Retries)
}
}
func TestWithDefaultRetries_NegativeClampedToZero(t *testing.T) {
store := storage.NewMemory()
executor := durex.New(store, durex.WithDefaultRetries(-10))
executor.HandleFunc("test", func(ctx context.Context, cmd *durex.Instance) (durex.Result, error) {
return durex.Empty(), nil
})
ctx := context.Background()
executor.Start(ctx)
inst, err := executor.Add(ctx, durex.Spec{Name: "test"})
if err != nil {
t.Fatalf("Add failed: %v", err)
}
if inst.Retries < 0 {
t.Errorf("expected non-negative retries, got %d", inst.Retries)
}
executor.Stop()
}