-
Notifications
You must be signed in to change notification settings - Fork 3
/
options_test.go
68 lines (49 loc) · 1.27 KB
/
options_test.go
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
package pig_test
import (
"context"
"testing"
"time"
"github.com/alexeyco/pig"
)
type key int
const expectedContextKey key = 123
func TestCtx(t *testing.T) {
t.Parallel()
expectedValue := 234
ctx := context.Background()
ctx = context.WithValue(ctx, expectedContextKey, expectedValue)
var o pig.Options
if o.Context != nil {
t.Error(`should be nil`)
}
pig.Ctx(ctx)(&o)
v := o.Context.Value(expectedContextKey)
if v == nil {
t.Fatal(`should not be nil`)
}
if v.(int) != expectedValue {
t.Errorf(`should be %d, %d given`, expectedValue, v.(int))
}
}
func TestTransactionTimeout(t *testing.T) {
t.Parallel()
var o pig.Options
if o.TransactionTimeout != 0 {
t.Errorf(`should be %d, %d given`, 0, o.TransactionTimeout)
}
pig.TransactionTimeout(time.Second)(&o)
if o.TransactionTimeout != time.Second.Milliseconds() {
t.Errorf(`should be %d, %d given`, time.Second.Milliseconds(), o.TransactionTimeout)
}
}
func TestStatementTimeout(t *testing.T) {
t.Parallel()
var o pig.Options
if o.StatementTimeout != 0 {
t.Errorf(`should be %d, %d given`, 0, o.StatementTimeout)
}
pig.StatementTimeout(time.Second)(&o)
if o.StatementTimeout != time.Second.Milliseconds() {
t.Errorf(`should be %d, %d given`, time.Second.Milliseconds(), o.StatementTimeout)
}
}