@@ -16,17 +16,18 @@ package clientv3_test
16
16
17
17
import (
18
18
"context"
19
+ "errors"
19
20
"fmt"
20
21
"log"
21
22
22
23
"go.etcd.io/etcd/api/v3/v3rpc/rpctypes"
23
24
clientv3 "go.etcd.io/etcd/client/v3"
24
25
)
25
26
26
- func mockKV_put () {}
27
+ func mockKVPut () {}
27
28
28
29
func ExampleKV_put () {
29
- forUnitTestsRunInMockedContext (mockKV_put , func () {
30
+ forUnitTestsRunInMockedContext (mockKVPut , func () {
30
31
cli , err := clientv3 .New (clientv3.Config {
31
32
Endpoints : exampleEndpoints (),
32
33
DialTimeout : dialTimeout ,
@@ -46,12 +47,12 @@ func ExampleKV_put() {
46
47
// Output:
47
48
}
48
49
49
- func mockKV_putErrorHandling () {
50
+ func mockKVPutErrorHandling () {
50
51
fmt .Println ("client-side error: etcdserver: key is not provided" )
51
52
}
52
53
53
54
func ExampleKV_putErrorHandling () {
54
- forUnitTestsRunInMockedContext (mockKV_putErrorHandling , func () {
55
+ forUnitTestsRunInMockedContext (mockKVPutErrorHandling , func () {
55
56
cli , err := clientv3 .New (clientv3.Config {
56
57
Endpoints : exampleEndpoints (),
57
58
DialTimeout : dialTimeout ,
@@ -65,27 +66,26 @@ func ExampleKV_putErrorHandling() {
65
66
_ , err = cli .Put (ctx , "" , "sample_value" )
66
67
cancel ()
67
68
if err != nil {
68
- switch err {
69
- case context .Canceled :
69
+ if errors .Is (err , context .Canceled ) {
70
70
fmt .Printf ("ctx is canceled by another routine: %v\n " , err )
71
- case context .DeadlineExceeded :
71
+ } else if errors . Is ( err , context .DeadlineExceeded ) {
72
72
fmt .Printf ("ctx is attached with a deadline is exceeded: %v\n " , err )
73
- case rpctypes .ErrEmptyKey :
73
+ } else if errors . Is ( err , rpctypes .ErrEmptyKey ) {
74
74
fmt .Printf ("client-side error: %v\n " , err )
75
- default :
75
+ } else {
76
76
fmt .Printf ("bad cluster endpoints, which are not etcd servers: %v\n " , err )
77
77
}
78
78
}
79
79
})
80
80
// Output: client-side error: etcdserver: key is not provided
81
81
}
82
82
83
- func mockKV_get () {
83
+ func mockKVGet () {
84
84
fmt .Println ("foo : bar" )
85
85
}
86
86
87
87
func ExampleKV_get () {
88
- forUnitTestsRunInMockedContext (mockKV_get , func () {
88
+ forUnitTestsRunInMockedContext (mockKVGet , func () {
89
89
cli , err := clientv3 .New (clientv3.Config {
90
90
Endpoints : exampleEndpoints (),
91
91
DialTimeout : dialTimeout ,
@@ -113,12 +113,12 @@ func ExampleKV_get() {
113
113
// Output: foo : bar
114
114
}
115
115
116
- func mockKV_getWithRev () {
116
+ func mockKVGetWithRev () {
117
117
fmt .Println ("foo : bar1" )
118
118
}
119
119
120
120
func ExampleKV_getWithRev () {
121
- forUnitTestsRunInMockedContext (mockKV_getWithRev , func () {
121
+ forUnitTestsRunInMockedContext (mockKVGetWithRev , func () {
122
122
cli , err := clientv3 .New (clientv3.Config {
123
123
Endpoints : exampleEndpoints (),
124
124
DialTimeout : dialTimeout ,
@@ -150,14 +150,14 @@ func ExampleKV_getWithRev() {
150
150
// Output: foo : bar1
151
151
}
152
152
153
- func mockKV_getSortedPrefix () {
153
+ func mockKVGetSortedPrefix () {
154
154
fmt .Println (`key_2 : value` )
155
155
fmt .Println (`key_1 : value` )
156
156
fmt .Println (`key_0 : value` )
157
157
}
158
158
159
159
func ExampleKV_getSortedPrefix () {
160
- forUnitTestsRunInMockedContext (mockKV_getSortedPrefix , func () {
160
+ forUnitTestsRunInMockedContext (mockKVGetSortedPrefix , func () {
161
161
cli , err := clientv3 .New (clientv3.Config {
162
162
Endpoints : exampleEndpoints (),
163
163
DialTimeout : dialTimeout ,
@@ -192,12 +192,12 @@ func ExampleKV_getSortedPrefix() {
192
192
// key_0 : value
193
193
}
194
194
195
- func mockKV_delete () {
195
+ func mockKVDelete () {
196
196
fmt .Println ("Deleted all keys: true" )
197
197
}
198
198
199
199
func ExampleKV_delete () {
200
- forUnitTestsRunInMockedContext (mockKV_delete , func () {
200
+ forUnitTestsRunInMockedContext (mockKVDelete , func () {
201
201
cli , err := clientv3 .New (clientv3.Config {
202
202
Endpoints : exampleEndpoints (),
203
203
DialTimeout : dialTimeout ,
@@ -228,10 +228,10 @@ func ExampleKV_delete() {
228
228
// Deleted all keys: true
229
229
}
230
230
231
- func mockKV_compact () {}
231
+ func mockKVCompact () {}
232
232
233
233
func ExampleKV_compact () {
234
- forUnitTestsRunInMockedContext (mockKV_compact , func () {
234
+ forUnitTestsRunInMockedContext (mockKVCompact , func () {
235
235
cli , err := clientv3 .New (clientv3.Config {
236
236
Endpoints : exampleEndpoints (),
237
237
DialTimeout : dialTimeout ,
@@ -259,12 +259,12 @@ func ExampleKV_compact() {
259
259
// Output:
260
260
}
261
261
262
- func mockKV_txn () {
262
+ func mockKVTxn () {
263
263
fmt .Println ("key : XYZ" )
264
264
}
265
265
266
266
func ExampleKV_txn () {
267
- forUnitTestsRunInMockedContext (mockKV_txn , func () {
267
+ forUnitTestsRunInMockedContext (mockKVTxn , func () {
268
268
cli , err := clientv3 .New (clientv3.Config {
269
269
Endpoints : exampleEndpoints (),
270
270
DialTimeout : dialTimeout ,
@@ -306,10 +306,10 @@ func ExampleKV_txn() {
306
306
// Output: key : XYZ
307
307
}
308
308
309
- func mockKV_do () {}
309
+ func mockKVDo () {}
310
310
311
311
func ExampleKV_do () {
312
- forUnitTestsRunInMockedContext (mockKV_do , func () {
312
+ forUnitTestsRunInMockedContext (mockKVDo , func () {
313
313
cli , err := clientv3 .New (clientv3.Config {
314
314
Endpoints : exampleEndpoints (),
315
315
DialTimeout : dialTimeout ,
0 commit comments