-
Notifications
You must be signed in to change notification settings - Fork 108
Expand file tree
/
Copy pathdriver_test.go
More file actions
37 lines (29 loc) · 1020 Bytes
/
driver_test.go
File metadata and controls
37 lines (29 loc) · 1020 Bytes
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
package ydb_test
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/ydb-platform/ydb-go-sdk/v3"
"github.com/ydb-platform/ydb-go-sdk/v3/trace"
)
func TestOpen(t *testing.T) {
t.Run("context already canceled", func(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
cancel()
_, err := ydb.Open(ctx, "grpc://localhost:2136/local")
require.ErrorIs(t, err, context.Canceled)
assert.Regexp(t, "^context canceled at", err.Error())
})
t.Run("context canceled at internal connect()", func(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
_, err := ydb.Open(ctx, "grpc://localhost:2136/local", ydb.WithTraceDriver(trace.Driver{
OnInit: func(disi trace.DriverInitStartInfo) func(trace.DriverInitDoneInfo) {
cancel()
return func(didi trace.DriverInitDoneInfo) {}
},
}))
require.ErrorIs(t, err, context.Canceled)
assert.Regexp(t, "^context canceled at", err.Error())
})
}