Skip to content

Commit

Permalink
Address issues reported by golangci-lint after bumping the version to…
Browse files Browse the repository at this point in the history
… v1.64.5

Signed-off-by: Chun-Hung Tseng <[email protected]>
  • Loading branch information
Chun-Hung Tseng committed Feb 24, 2025
1 parent 022b9b2 commit 43df62f
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 59 deletions.
20 changes: 10 additions & 10 deletions tests/integration/clientv3/examples/example_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ import (
clientv3 "go.etcd.io/etcd/client/v3"
)

func mockCluster_memberList() {
func mockClusterMemberList() {
fmt.Println("members: 3")
}

func ExampleCluster_memberList() {
forUnitTestsRunInMockedContext(mockCluster_memberList, func() {
forUnitTestsRunInMockedContext(mockClusterMemberList, func() {
cli, err := clientv3.New(clientv3.Config{
Endpoints: exampleEndpoints(),
DialTimeout: dialTimeout,
Expand All @@ -46,13 +46,13 @@ func ExampleCluster_memberList() {
// Output: members: 3
}

func mockCluster_memberAdd() {
func mockClusterMemberAdd() {
fmt.Println("added member.PeerURLs: [http://localhost:32380]")
fmt.Println("members count: 4")
}

func ExampleCluster_memberAdd() {
forUnitTestsRunInMockedContext(mockCluster_memberAdd, func() {
forUnitTestsRunInMockedContext(mockClusterMemberAdd, func() {
cli, err := clientv3.New(clientv3.Config{
Endpoints: exampleEndpoints(),
DialTimeout: dialTimeout,
Expand Down Expand Up @@ -81,13 +81,13 @@ func ExampleCluster_memberAdd() {
// members count: 4
}

func mockCluster_memberAddAsLearner() {
func mockClusterMemberAddAsLearner() {
fmt.Println("members count: 4")
fmt.Println("added member.IsLearner: true")
}

func ExampleCluster_memberAddAsLearner() {
forUnitTestsRunInMockedContext(mockCluster_memberAddAsLearner, func() {
forUnitTestsRunInMockedContext(mockClusterMemberAddAsLearner, func() {
cli, err := clientv3.New(clientv3.Config{
Endpoints: exampleEndpoints(),
DialTimeout: dialTimeout,
Expand Down Expand Up @@ -116,10 +116,10 @@ func ExampleCluster_memberAddAsLearner() {
// added member.IsLearner: true
}

func mockCluster_memberRemove() {}
func mockClusterMemberRemove() {}

func ExampleCluster_memberRemove() {
forUnitTestsRunInMockedContext(mockCluster_memberRemove, func() {
forUnitTestsRunInMockedContext(mockClusterMemberRemove, func() {
cli, err := clientv3.New(clientv3.Config{
Endpoints: exampleEndpoints(),
DialTimeout: dialTimeout,
Expand Down Expand Up @@ -147,10 +147,10 @@ func ExampleCluster_memberRemove() {
})
}

func mockCluster_memberUpdate() {}
func mockClusterMemberUpdate() {}

func ExampleCluster_memberUpdate() {
forUnitTestsRunInMockedContext(mockCluster_memberUpdate, func() {
forUnitTestsRunInMockedContext(mockClusterMemberUpdate, func() {
cli, err := clientv3.New(clientv3.Config{
Endpoints: exampleEndpoints(),
DialTimeout: dialTimeout,
Expand Down
46 changes: 23 additions & 23 deletions tests/integration/clientv3/examples/example_kv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,18 @@ package clientv3_test

import (
"context"
"errors"
"fmt"
"log"

"go.etcd.io/etcd/api/v3/v3rpc/rpctypes"
clientv3 "go.etcd.io/etcd/client/v3"
)

func mockKV_put() {}
func mockKVPut() {}

func ExampleKV_put() {
forUnitTestsRunInMockedContext(mockKV_put, func() {
forUnitTestsRunInMockedContext(mockKVPut, func() {
cli, err := clientv3.New(clientv3.Config{
Endpoints: exampleEndpoints(),
DialTimeout: dialTimeout,
Expand All @@ -46,12 +47,12 @@ func ExampleKV_put() {
// Output:
}

func mockKV_putErrorHandling() {
func mockKVPutErrorHandling() {
fmt.Println("client-side error: etcdserver: key is not provided")
}

func ExampleKV_putErrorHandling() {
forUnitTestsRunInMockedContext(mockKV_putErrorHandling, func() {
forUnitTestsRunInMockedContext(mockKVPutErrorHandling, func() {
cli, err := clientv3.New(clientv3.Config{
Endpoints: exampleEndpoints(),
DialTimeout: dialTimeout,
Expand All @@ -65,27 +66,26 @@ func ExampleKV_putErrorHandling() {
_, err = cli.Put(ctx, "", "sample_value")
cancel()
if err != nil {
switch err {
case context.Canceled:
if errors.Is(err, context.Canceled) {
fmt.Printf("ctx is canceled by another routine: %v\n", err)
case context.DeadlineExceeded:
} else if errors.Is(err, context.DeadlineExceeded) {
fmt.Printf("ctx is attached with a deadline is exceeded: %v\n", err)
case rpctypes.ErrEmptyKey:
} else if errors.Is(err, rpctypes.ErrEmptyKey) {
fmt.Printf("client-side error: %v\n", err)
default:
} else {
fmt.Printf("bad cluster endpoints, which are not etcd servers: %v\n", err)
}
}
})
// Output: client-side error: etcdserver: key is not provided
}

func mockKV_get() {
func mockKVGet() {
fmt.Println("foo : bar")
}

func ExampleKV_get() {
forUnitTestsRunInMockedContext(mockKV_get, func() {
forUnitTestsRunInMockedContext(mockKVGet, func() {
cli, err := clientv3.New(clientv3.Config{
Endpoints: exampleEndpoints(),
DialTimeout: dialTimeout,
Expand Down Expand Up @@ -113,12 +113,12 @@ func ExampleKV_get() {
// Output: foo : bar
}

func mockKV_getWithRev() {
func mockKVGetWithRev() {
fmt.Println("foo : bar1")
}

func ExampleKV_getWithRev() {
forUnitTestsRunInMockedContext(mockKV_getWithRev, func() {
forUnitTestsRunInMockedContext(mockKVGetWithRev, func() {
cli, err := clientv3.New(clientv3.Config{
Endpoints: exampleEndpoints(),
DialTimeout: dialTimeout,
Expand Down Expand Up @@ -150,14 +150,14 @@ func ExampleKV_getWithRev() {
// Output: foo : bar1
}

func mockKV_getSortedPrefix() {
func mockKVGetSortedPrefix() {
fmt.Println(`key_2 : value`)
fmt.Println(`key_1 : value`)
fmt.Println(`key_0 : value`)
}

func ExampleKV_getSortedPrefix() {
forUnitTestsRunInMockedContext(mockKV_getSortedPrefix, func() {
forUnitTestsRunInMockedContext(mockKVGetSortedPrefix, func() {
cli, err := clientv3.New(clientv3.Config{
Endpoints: exampleEndpoints(),
DialTimeout: dialTimeout,
Expand Down Expand Up @@ -192,12 +192,12 @@ func ExampleKV_getSortedPrefix() {
// key_0 : value
}

func mockKV_delete() {
func mockKVDelete() {
fmt.Println("Deleted all keys: true")
}

func ExampleKV_delete() {
forUnitTestsRunInMockedContext(mockKV_delete, func() {
forUnitTestsRunInMockedContext(mockKVDelete, func() {
cli, err := clientv3.New(clientv3.Config{
Endpoints: exampleEndpoints(),
DialTimeout: dialTimeout,
Expand Down Expand Up @@ -228,10 +228,10 @@ func ExampleKV_delete() {
// Deleted all keys: true
}

func mockKV_compact() {}
func mockKVCompact() {}

func ExampleKV_compact() {
forUnitTestsRunInMockedContext(mockKV_compact, func() {
forUnitTestsRunInMockedContext(mockKVCompact, func() {
cli, err := clientv3.New(clientv3.Config{
Endpoints: exampleEndpoints(),
DialTimeout: dialTimeout,
Expand Down Expand Up @@ -259,12 +259,12 @@ func ExampleKV_compact() {
// Output:
}

func mockKV_txn() {
func mockKVTxn() {
fmt.Println("key : XYZ")
}

func ExampleKV_txn() {
forUnitTestsRunInMockedContext(mockKV_txn, func() {
forUnitTestsRunInMockedContext(mockKVTxn, func() {
cli, err := clientv3.New(clientv3.Config{
Endpoints: exampleEndpoints(),
DialTimeout: dialTimeout,
Expand Down Expand Up @@ -306,10 +306,10 @@ func ExampleKV_txn() {
// Output: key : XYZ
}

func mockKV_do() {}
func mockKVDo() {}

func ExampleKV_do() {
forUnitTestsRunInMockedContext(mockKV_do, func() {
forUnitTestsRunInMockedContext(mockKVDo, func() {
cli, err := clientv3.New(clientv3.Config{
Endpoints: exampleEndpoints(),
DialTimeout: dialTimeout,
Expand Down
16 changes: 8 additions & 8 deletions tests/integration/clientv3/examples/example_lease_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ import (
clientv3 "go.etcd.io/etcd/client/v3"
)

func mockLease_grant() {
func mockLeaseGrant() {
}

func ExampleLease_grant() {
forUnitTestsRunInMockedContext(mockLease_grant, func() {
forUnitTestsRunInMockedContext(mockLeaseGrant, func() {
cli, err := clientv3.New(clientv3.Config{
Endpoints: exampleEndpoints(),
DialTimeout: dialTimeout,
Expand All @@ -51,12 +51,12 @@ func ExampleLease_grant() {
// Output:
}

func mockLease_revoke() {
func mockLeaseRevoke() {
fmt.Println("number of keys: 0")
}

func ExampleLease_revoke() {
forUnitTestsRunInMockedContext(mockLease_revoke, func() {
forUnitTestsRunInMockedContext(mockLeaseRevoke, func() {
cli, err := clientv3.New(clientv3.Config{
Endpoints: exampleEndpoints(),
DialTimeout: dialTimeout,
Expand Down Expand Up @@ -91,12 +91,12 @@ func ExampleLease_revoke() {
// Output: number of keys: 0
}

func mockLease_keepAlive() {
func mockLeaseKeepAlive() {
fmt.Println("ttl: 5")
}

func ExampleLease_keepAlive() {
forUnitTestsRunInMockedContext(mockLease_keepAlive, func() {
forUnitTestsRunInMockedContext(mockLeaseKeepAlive, func() {
cli, err := clientv3.New(clientv3.Config{
Endpoints: exampleEndpoints(),
DialTimeout: dialTimeout,
Expand Down Expand Up @@ -132,12 +132,12 @@ func ExampleLease_keepAlive() {
// Output: ttl: 5
}

func mockLease_keepAliveOnce() {
func mockLeaseKeepAliveOnce() {
fmt.Println("ttl: 5")
}

func ExampleLease_keepAliveOnce() {
forUnitTestsRunInMockedContext(mockLease_keepAliveOnce, func() {
forUnitTestsRunInMockedContext(mockLeaseKeepAliveOnce, func() {
cli, err := clientv3.New(clientv3.Config{
Endpoints: exampleEndpoints(),
DialTimeout: dialTimeout,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ import (
clientv3 "go.etcd.io/etcd/client/v3"
)

func mockMaintenance_status() {}
func mockMaintenanceStatus() {}

func ExampleMaintenance_status() {
forUnitTestsRunInMockedContext(mockMaintenance_status, func() {
forUnitTestsRunInMockedContext(mockMaintenanceStatus, func() {
for _, ep := range exampleEndpoints() {
cli, err := clientv3.New(clientv3.Config{
Endpoints: []string{ep},
Expand All @@ -44,10 +44,10 @@ func ExampleMaintenance_status() {
// Output:
}

func mockMaintenance_defragment() {}
func mockMaintenanceDefragment() {}

func ExampleMaintenance_defragment() {
forUnitTestsRunInMockedContext(mockMaintenance_defragment, func() {
forUnitTestsRunInMockedContext(mockMaintenanceDefragment, func() {
for _, ep := range exampleEndpoints() {
cli, err := clientv3.New(clientv3.Config{
Endpoints: []string{ep},
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/clientv3/examples/example_metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ import (
clientv3 "go.etcd.io/etcd/client/v3"
)

func mockClient_metrics() {
func mockClientMetrics() {
fmt.Println(`grpc_client_started_total{grpc_method="Range",grpc_service="etcdserverpb.KV",grpc_type="unary"} 1`)
}

func ExampleClient_metrics() {
forUnitTestsRunInMockedContext(mockClient_metrics, func() {
forUnitTestsRunInMockedContext(mockClientMetrics, func() {
clientMetrics := grpcprom.NewClientMetrics()
prometheus.Register(clientMetrics)
cli, err := clientv3.New(clientv3.Config{
Expand Down
8 changes: 4 additions & 4 deletions tests/integration/clientv3/examples/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import (
clientv3 "go.etcd.io/etcd/client/v3"
)

func mockConfig_insecure() {}
func mockConfigInsecure() {}

func ExampleConfig_insecure() {
forUnitTestsRunInMockedContext(mockConfig_insecure, func() {
forUnitTestsRunInMockedContext(mockConfigInsecure, func() {
cli, err := clientv3.New(clientv3.Config{
Endpoints: exampleEndpoints(),
DialTimeout: dialTimeout,
Expand All @@ -46,10 +46,10 @@ func ExampleConfig_insecure() {
// Output:
}

func mockConfig_withTLS() {}
func mockConfigWithTLS() {}

func ExampleConfig_withTLS() {
forUnitTestsRunInMockedContext(mockConfig_withTLS, func() {
forUnitTestsRunInMockedContext(mockConfigWithTLS, func() {
tlsInfo := transport.TLSInfo{
CertFile: "/tmp/test-certs/test-name-1.pem",
KeyFile: "/tmp/test-certs/test-name-1-key.pem",
Expand Down
Loading

0 comments on commit 43df62f

Please sign in to comment.