This repository has been archived by the owner on Dec 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapi_test.go
73 lines (61 loc) · 1.77 KB
/
api_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
69
70
71
72
73
package vshard_router // nolint: revive
import (
"context"
"fmt"
"sync/atomic"
"testing"
"time"
mockpool "github.com/KaymeKaydex/go-vshard-router/mocks/pool"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
"github.com/tarantool/go-tarantool/v2"
)
var emptyRouter = &Router{
cfg: Config{
TotalBucketCount: uint64(10),
Loggerf: emptyLogfProvider,
Metrics: emptyMetricsProvider,
},
}
func TestVshardMode_String_NotEmpty(t *testing.T) {
t.Parallel()
require.NotEmpty(t, ReadMode.String())
require.NotEmpty(t, WriteMode.String())
}
func TestRouter_RouterRouteAll(t *testing.T) {
t.Parallel()
m := emptyRouter.RouterRouteAll()
require.Empty(t, m)
}
func TestRouter_RouterCallImpl(t *testing.T) {
t.Parallel()
ctx := context.TODO()
t.Run("bucket id is out of range", func(t *testing.T) {
t.Parallel()
_, _, err := emptyRouter.RouterCallImpl(ctx, 100, CallOpts{}, "test", []byte("test"))
require.Errorf(t, err, "bucket id is out of range")
})
t.Run("future error when router call impl", func(t *testing.T) {
t.Parallel()
r := &Router{
cfg: Config{
TotalBucketCount: uint64(10),
Loggerf: emptyLogfProvider,
Metrics: emptyMetricsProvider,
},
view: &consistentView{
routeMap: make([]atomic.Pointer[Replicaset], 11),
},
}
futureError := fmt.Errorf("testErr")
errFuture := tarantool.NewFuture(tarantool.NewCallRequest("test"))
errFuture.SetError(futureError)
mPool := mockpool.NewPool(t)
mPool.On("Do", mock.Anything, mock.Anything).Return(errFuture)
r.view.routeMap[5].Store(&Replicaset{
conn: mPool,
})
_, _, err := r.RouterCallImpl(ctx, 5, CallOpts{Timeout: time.Second, VshardMode: ReadMode}, "test", []byte("test"))
require.ErrorIs(t, err, futureError)
})
}