...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package clientv3
16
17 import (
18 "reflect"
19 "testing"
20
21 pb "go.etcd.io/etcd/api/v3/etcdserverpb"
22 )
23
24
25
26
27 func TestOpWithSort(t *testing.T) {
28 opReq := OpGet("foo", WithSort(SortByKey, SortAscend), WithLimit(10)).toRequestOp().Request
29 q, ok := opReq.(*pb.RequestOp_RequestRange)
30 if !ok {
31 t.Fatalf("expected range request, got %v", reflect.TypeOf(opReq))
32 }
33 req := q.RequestRange
34 wreq := &pb.RangeRequest{Key: []byte("foo"), SortOrder: pb.RangeRequest_NONE, Limit: 10}
35 if !reflect.DeepEqual(req, wreq) {
36 t.Fatalf("expected %+v, got %+v", wreq, req)
37 }
38 }
39
40 func TestIsOptsWithPrefix(t *testing.T) {
41 optswithprefix := []OpOption{WithPrefix()}
42 if !IsOptsWithPrefix(optswithprefix) {
43 t.Errorf("IsOptsWithPrefix = false, expected true")
44 }
45
46 optswithfromkey := []OpOption{WithFromKey()}
47 if IsOptsWithPrefix(optswithfromkey) {
48 t.Errorf("IsOptsWithPrefix = true, expected false")
49 }
50 }
51
52 func TestIsOptsWithFromKey(t *testing.T) {
53 optswithfromkey := []OpOption{WithFromKey()}
54 if !IsOptsWithFromKey(optswithfromkey) {
55 t.Errorf("IsOptsWithFromKey = false, expected true")
56 }
57
58 optswithprefix := []OpOption{WithPrefix()}
59 if IsOptsWithFromKey(optswithprefix) {
60 t.Errorf("IsOptsWithFromKey = true, expected false")
61 }
62 }
63
View as plain text