From b7488d4355853813084e7628d25a8b3ba976e611 Mon Sep 17 00:00:00 2001 From: Ivan Valdes Date: Fri, 22 Mar 2024 15:59:40 -0700 Subject: [PATCH] tests/framework: address golangci var-naming issues Signed-off-by: Ivan Valdes --- tests/e2e/cmux_test.go | 12 +-- tests/e2e/watch_delay_test.go | 6 +- tests/framework/e2e/cluster.go | 36 ++++---- tests/framework/e2e/cluster_proxy.go | 16 ++-- tests/framework/e2e/curl.go | 6 +- tests/framework/e2e/etcd_process.go | 14 +-- tests/framework/e2e/etcdctl.go | 48 +++++----- tests/framework/integration/cluster.go | 87 ++++++++++--------- tests/framework/integration/cluster_direct.go | 4 +- tests/framework/integration/cluster_proxy.go | 6 +- tests/framework/integration/testing.go | 10 +-- tests/integration/grpc_test.go | 4 +- 12 files changed, 125 insertions(+), 124 deletions(-) diff --git a/tests/e2e/cmux_test.go b/tests/e2e/cmux_test.go index 01829d3b861..9281705ee04 100644 --- a/tests/e2e/cmux_test.go +++ b/tests/e2e/cmux_test.go @@ -72,7 +72,7 @@ func TestConnectionMultiplexing(t *testing.T) { ctx := context.Background() cfg := e2e.NewConfig(e2e.WithClusterSize(1)) cfg.Client.ConnectionType = tc.serverTLS - cfg.ClientHttpSeparate = tc.separateHTTPPort + cfg.ClientHTTPSeparate = tc.separateHTTPPort clus, err := e2e.NewEtcdProcessCluster(ctx, t, e2e.WithConfig(cfg)) require.NoError(t, err) defer clus.Close() @@ -146,7 +146,7 @@ func fetchGRPCGateway(endpoint string, httpVersion string, connType e2e.ClientCo if err != nil { return err } - req := e2e.CURLReq{Endpoint: "/v3/kv/range", Value: string(rangeData), Timeout: 5, HttpVersion: httpVersion} + req := e2e.CURLReq{Endpoint: "/v3/kv/range", Value: string(rangeData), Timeout: 5, HTTPVersion: httpVersion} respData, err := curl(endpoint, "POST", req, connType) if err != nil { return err @@ -178,7 +178,7 @@ func fetchMetrics(t *testing.T, endpoint string, httpVersion string, connType e2 tmpDir := t.TempDir() metricFile := filepath.Join(tmpDir, "metrics") - req := e2e.CURLReq{Endpoint: "/metrics", Timeout: 5, HttpVersion: httpVersion, OutputFile: metricFile} + req := e2e.CURLReq{Endpoint: "/metrics", Timeout: 5, HTTPVersion: httpVersion, OutputFile: metricFile} if _, err := curl(endpoint, "GET", req, connType); err != nil { return err } @@ -195,7 +195,7 @@ func fetchMetrics(t *testing.T, endpoint string, httpVersion string, connType e2 } func fetchVersion(endpoint string, httpVersion string, connType e2e.ClientConnType) error { - req := e2e.CURLReq{Endpoint: "/version", Timeout: 5, HttpVersion: httpVersion} + req := e2e.CURLReq{Endpoint: "/version", Timeout: 5, HTTPVersion: httpVersion} respData, err := curl(endpoint, "GET", req, connType) if err != nil { return err @@ -205,7 +205,7 @@ func fetchVersion(endpoint string, httpVersion string, connType e2e.ClientConnTy } func fetchHealth(endpoint string, httpVersion string, connType e2e.ClientConnType) error { - req := e2e.CURLReq{Endpoint: "/health", Timeout: 5, HttpVersion: httpVersion} + req := e2e.CURLReq{Endpoint: "/health", Timeout: 5, HTTPVersion: httpVersion} respData, err := curl(endpoint, "GET", req, connType) if err != nil { return err @@ -215,7 +215,7 @@ func fetchHealth(endpoint string, httpVersion string, connType e2e.ClientConnTyp } func fetchDebugVars(endpoint string, httpVersion string, connType e2e.ClientConnType) error { - req := e2e.CURLReq{Endpoint: "/debug/vars", Timeout: 5, HttpVersion: httpVersion} + req := e2e.CURLReq{Endpoint: "/debug/vars", Timeout: 5, HTTPVersion: httpVersion} respData, err := curl(endpoint, "GET", req, connType) if err != nil { return err diff --git a/tests/e2e/watch_delay_test.go b/tests/e2e/watch_delay_test.go index e6a126fddd8..c50ebef8922 100644 --- a/tests/e2e/watch_delay_test.go +++ b/tests/e2e/watch_delay_test.go @@ -89,7 +89,7 @@ func TestWatchDelayForPeriodicProgressNotification(t *testing.T) { cfg.ClusterSize = 1 cfg.ServerConfig.ExperimentalWatchProgressNotifyInterval = watchResponsePeriod cfg.Client = tc.client - cfg.ClientHttpSeparate = tc.clientHTTPSeparate + cfg.ClientHTTPSeparate = tc.clientHTTPSeparate t.Run(tc.name, func(t *testing.T) { clus, err := e2e.NewEtcdProcessCluster(context.Background(), t, e2e.WithConfig(cfg)) require.NoError(t, err) @@ -114,7 +114,7 @@ func TestWatchDelayForManualProgressNotification(t *testing.T) { cfg := e2e.DefaultConfig() cfg.ClusterSize = 1 cfg.Client = tc.client - cfg.ClientHttpSeparate = tc.clientHTTPSeparate + cfg.ClientHTTPSeparate = tc.clientHTTPSeparate t.Run(tc.name, func(t *testing.T) { clus, err := e2e.NewEtcdProcessCluster(context.Background(), t, e2e.WithConfig(cfg)) require.NoError(t, err) @@ -151,7 +151,7 @@ func TestWatchDelayForEvent(t *testing.T) { cfg := e2e.DefaultConfig() cfg.ClusterSize = 1 cfg.Client = tc.client - cfg.ClientHttpSeparate = tc.clientHTTPSeparate + cfg.ClientHTTPSeparate = tc.clientHTTPSeparate t.Run(tc.name, func(t *testing.T) { clus, err := e2e.NewEtcdProcessCluster(context.Background(), t, e2e.WithConfig(cfg)) require.NoError(t, err) diff --git a/tests/framework/e2e/cluster.go b/tests/framework/e2e/cluster.go index ec177e72333..8f3a102c305 100644 --- a/tests/framework/e2e/cluster.go +++ b/tests/framework/e2e/cluster.go @@ -167,7 +167,7 @@ type EtcdProcessClusterConfig struct { BaseClientScheme string MetricsURLScheme string Client ClientConfig - ClientHttpSeparate bool + ClientHTTPSeparate bool IsPeerTLS bool IsPeerAutoTLS bool CN bool @@ -486,7 +486,7 @@ func (cfg *EtcdProcessClusterConfig) EtcdServerProcessConfig(tb testing.TB, i in peerPort := port + 1 metricsPort := port + 2 peer2Port := port + 3 - clientHttpPort := port + 4 + clientHTTPPort := port + 4 if cfg.Client.ConnectionType == ClientTLSAndNonTLS { curl = clientURL(cfg.ClientScheme(), clientPort, ClientNonTLS) @@ -496,18 +496,18 @@ func (cfg *EtcdProcessClusterConfig) EtcdServerProcessConfig(tb testing.TB, i in curls = []string{curl} } - peerListenUrl := url.URL{Scheme: cfg.PeerScheme(), Host: fmt.Sprintf("localhost:%d", peerPort)} - peerAdvertiseUrl := url.URL{Scheme: cfg.PeerScheme(), Host: fmt.Sprintf("localhost:%d", peerPort)} + peerListenURL := url.URL{Scheme: cfg.PeerScheme(), Host: fmt.Sprintf("localhost:%d", peerPort)} + peerAdvertiseURL := url.URL{Scheme: cfg.PeerScheme(), Host: fmt.Sprintf("localhost:%d", peerPort)} var proxyCfg *proxy.ServerConfig if cfg.PeerProxy { if !cfg.IsPeerTLS { panic("Can't use peer proxy without peer TLS as it can result in malformed packets") } - peerAdvertiseUrl.Host = fmt.Sprintf("localhost:%d", peer2Port) + peerAdvertiseURL.Host = fmt.Sprintf("localhost:%d", peer2Port) proxyCfg = &proxy.ServerConfig{ Logger: zap.NewNop(), - To: peerListenUrl, - From: peerAdvertiseUrl, + To: peerListenURL, + From: peerAdvertiseURL, } } @@ -529,16 +529,16 @@ func (cfg *EtcdProcessClusterConfig) EtcdServerProcessConfig(tb testing.TB, i in "--name=" + name, "--listen-client-urls=" + strings.Join(curls, ","), "--advertise-client-urls=" + strings.Join(curls, ","), - "--listen-peer-urls=" + peerListenUrl.String(), - "--initial-advertise-peer-urls=" + peerAdvertiseUrl.String(), + "--listen-peer-urls=" + peerListenURL.String(), + "--initial-advertise-peer-urls=" + peerAdvertiseURL.String(), "--initial-cluster-token=" + cfg.ServerConfig.InitialClusterToken, "--data-dir", dataDirPath, "--snapshot-count=" + fmt.Sprintf("%d", cfg.ServerConfig.SnapshotCount), } - var clientHttpUrl string - if cfg.ClientHttpSeparate { - clientHttpUrl = clientURL(cfg.ClientScheme(), clientHttpPort, cfg.Client.ConnectionType) - args = append(args, "--listen-client-http-urls="+clientHttpUrl) + var clientHTTPURL string + if cfg.ClientHTTPSeparate { + clientHTTPURL = clientURL(cfg.ClientScheme(), clientHTTPPort, cfg.Client.ConnectionType) + args = append(args, "--listen-client-http-urls="+clientHTTPURL) } if cfg.ServerConfig.ForceNewCluster { @@ -564,7 +564,7 @@ func (cfg *EtcdProcessClusterConfig) EtcdServerProcessConfig(tb testing.TB, i in args = append(args, "--listen-metrics-urls="+murl) } - args = append(args, cfg.TlsArgs()...) + args = append(args, cfg.TLSArgs()...) if cfg.Discovery != "" { args = append(args, "--discovery="+cfg.Discovery) @@ -618,14 +618,14 @@ func (cfg *EtcdProcessClusterConfig) EtcdServerProcessConfig(tb testing.TB, i in ExecPath: execPath, Args: args, EnvVars: envVars, - TlsArgs: cfg.TlsArgs(), + TLSArgs: cfg.TLSArgs(), Client: cfg.Client, DataDirPath: dataDirPath, KeepDataDir: cfg.KeepDataDir, Name: name, - PeerURL: peerAdvertiseUrl, + PeerURL: peerAdvertiseURL, ClientURL: curl, - ClientHTTPURL: clientHttpUrl, + ClientHTTPURL: clientHTTPURL, MetricsURL: murl, InitialToken: cfg.ServerConfig.InitialClusterToken, GoFailPort: gofailPort, @@ -661,7 +661,7 @@ func clientURL(scheme string, port int, connType ClientConnType) string { } } -func (cfg *EtcdProcessClusterConfig) TlsArgs() (args []string) { +func (cfg *EtcdProcessClusterConfig) TLSArgs() (args []string) { if cfg.Client.ConnectionType != ClientNonTLS { if cfg.Client.AutoTLS { args = append(args, "--auto-tls") diff --git a/tests/framework/e2e/cluster_proxy.go b/tests/framework/e2e/cluster_proxy.go index 53e3232070c..ed859858ba9 100644 --- a/tests/framework/e2e/cluster_proxy.go +++ b/tests/framework/e2e/cluster_proxy.go @@ -196,7 +196,7 @@ func newProxyV2Proc(cfg *EtcdServerProcessConfig) *proxyV2Proc { name: cfg.Name, lg: cfg.lg, execPath: cfg.ExecPath, - args: append(args, cfg.TlsArgs...), + args: append(args, cfg.TLSArgs...), ep: listenAddr, donec: make(chan struct{}), }, @@ -225,16 +225,16 @@ func newProxyV3Proc(cfg *EtcdServerProcessConfig) *proxyV3Proc { args = append(args, "--metrics-addr", murl) } tlsArgs := []string{} - for i := 0; i < len(cfg.TlsArgs); i++ { - switch cfg.TlsArgs[i] { + for i := 0; i < len(cfg.TLSArgs); i++ { + switch cfg.TLSArgs[i] { case "--cert-file": - tlsArgs = append(tlsArgs, "--cert-file", cfg.TlsArgs[i+1]) + tlsArgs = append(tlsArgs, "--cert-file", cfg.TLSArgs[i+1]) i++ case "--key-file": - tlsArgs = append(tlsArgs, "--key-file", cfg.TlsArgs[i+1]) + tlsArgs = append(tlsArgs, "--key-file", cfg.TLSArgs[i+1]) i++ case "--trusted-ca-file": - tlsArgs = append(tlsArgs, "--trusted-ca-file", cfg.TlsArgs[i+1]) + tlsArgs = append(tlsArgs, "--trusted-ca-file", cfg.TLSArgs[i+1]) i++ case "--auto-tls": tlsArgs = append(tlsArgs, "--auto-tls", "--insecure-skip-tls-verify") @@ -242,10 +242,10 @@ func newProxyV3Proc(cfg *EtcdServerProcessConfig) *proxyV3Proc { i++ // skip arg case "--client-cert-auth", "--peer-auto-tls": default: - tlsArgs = append(tlsArgs, cfg.TlsArgs[i]) + tlsArgs = append(tlsArgs, cfg.TLSArgs[i]) } } - if len(cfg.TlsArgs) > 0 { + if len(cfg.TLSArgs) > 0 { // Configure certificates for connection proxy ---> server. // This certificate must NOT have CN set. tlsArgs = append(tlsArgs, diff --git a/tests/framework/e2e/curl.go b/tests/framework/e2e/curl.go index 3639bc3a970..16c2c39cf3f 100644 --- a/tests/framework/e2e/curl.go +++ b/tests/framework/e2e/curl.go @@ -38,7 +38,7 @@ type CURLReq struct { Header string Ciphers string - HttpVersion string + HTTPVersion string OutputFile string } @@ -62,8 +62,8 @@ func CURLPrefixArgs(clientURL string, cfg ClientConfig, CN bool, method string, var ( cmdArgs = []string{"curl"} ) - if req.HttpVersion != "" { - cmdArgs = append(cmdArgs, "--http"+req.HttpVersion) + if req.HTTPVersion != "" { + cmdArgs = append(cmdArgs, "--http"+req.HTTPVersion) } if req.IsTLS { if cfg.ConnectionType != ClientTLSAndNonTLS { diff --git a/tests/framework/e2e/etcd_process.go b/tests/framework/e2e/etcd_process.go index aa2638ee5f2..1e3de2a7f28 100644 --- a/tests/framework/e2e/etcd_process.go +++ b/tests/framework/e2e/etcd_process.go @@ -81,7 +81,7 @@ type EtcdServerProcessConfig struct { lg *zap.Logger ExecPath string Args []string - TlsArgs []string + TLSArgs []string EnvVars map[string]string Client ClientConfig @@ -354,12 +354,12 @@ func (f *BinaryFailpoints) SetupEnv(failpoint, payload string) error { func (f *BinaryFailpoints) SetupHTTP(ctx context.Context, failpoint, payload string) error { host := fmt.Sprintf("127.0.0.1:%d", f.member.Config().GoFailPort) - failpointUrl := url.URL{ + failpointURL := url.URL{ Scheme: "http", Host: host, Path: failpoint, } - r, err := http.NewRequestWithContext(ctx, "PUT", failpointUrl.String(), bytes.NewBuffer([]byte(payload))) + r, err := http.NewRequestWithContext(ctx, "PUT", failpointURL.String(), bytes.NewBuffer([]byte(payload))) if err != nil { return err } @@ -382,12 +382,12 @@ func (f *BinaryFailpoints) SetupHTTP(ctx context.Context, failpoint, payload str func (f *BinaryFailpoints) DeactivateHTTP(ctx context.Context, failpoint string) error { host := fmt.Sprintf("127.0.0.1:%d", f.member.Config().GoFailPort) - failpointUrl := url.URL{ + failpointURL := url.URL{ Scheme: "http", Host: host, Path: failpoint, } - r, err := http.NewRequestWithContext(ctx, "DELETE", failpointUrl.String(), nil) + r, err := http.NewRequestWithContext(ctx, "DELETE", failpointURL.String(), nil) if err != nil { return err } @@ -439,11 +439,11 @@ func failpoints(member EtcdProcess) (map[string]string, error) { func fetchFailpointsBody(member EtcdProcess) (io.ReadCloser, error) { address := fmt.Sprintf("127.0.0.1:%d", member.Config().GoFailPort) - failpointUrl := url.URL{ + failpointURL := url.URL{ Scheme: "http", Host: address, } - resp, err := http.Get(failpointUrl.String()) + resp, err := http.Get(failpointURL.String()) if err != nil { return nil, err } diff --git a/tests/framework/e2e/etcdctl.go b/tests/framework/e2e/etcdctl.go index 32589684e44..0d6bb3a5dcd 100644 --- a/tests/framework/e2e/etcdctl.go +++ b/tests/framework/e2e/etcdctl.go @@ -148,7 +148,7 @@ func (ctl *EtcdctlV3) Get(ctx context.Context, key string, o config.GetOptions) _, err = cmd.ExpectWithContext(ctx, expect.ExpectedResponse{Value: "Count"}) return &resp, err } - err := ctl.spawnJsonCmd(ctx, &resp, args...) + err := ctl.spawnJSONCmd(ctx, &resp, args...) return &resp, err } @@ -177,7 +177,7 @@ func (ctl *EtcdctlV3) Delete(ctx context.Context, key string, o config.DeleteOpt args = append(args, "--from-key") } var resp clientv3.DeleteResponse - err := ctl.spawnJsonCmd(ctx, &resp, args...) + err := ctl.spawnJSONCmd(ctx, &resp, args...) return &resp, err } @@ -284,31 +284,31 @@ func (ctl *EtcdctlV3) MemberList(ctx context.Context, serializable bool) (*clien if serializable { args = append(args, "--consistency", "s") } - err := ctl.spawnJsonCmd(ctx, &resp, args...) + err := ctl.spawnJSONCmd(ctx, &resp, args...) return &resp, err } func (ctl *EtcdctlV3) MemberAdd(ctx context.Context, name string, peerAddrs []string) (*clientv3.MemberAddResponse, error) { var resp clientv3.MemberAddResponse - err := ctl.spawnJsonCmd(ctx, &resp, "member", "add", name, "--peer-urls", strings.Join(peerAddrs, ",")) + err := ctl.spawnJSONCmd(ctx, &resp, "member", "add", name, "--peer-urls", strings.Join(peerAddrs, ",")) return &resp, err } func (ctl *EtcdctlV3) MemberAddAsLearner(ctx context.Context, name string, peerAddrs []string) (*clientv3.MemberAddResponse, error) { var resp clientv3.MemberAddResponse - err := ctl.spawnJsonCmd(ctx, &resp, "member", "add", name, "--learner", "--peer-urls", strings.Join(peerAddrs, ",")) + err := ctl.spawnJSONCmd(ctx, &resp, "member", "add", name, "--learner", "--peer-urls", strings.Join(peerAddrs, ",")) return &resp, err } func (ctl *EtcdctlV3) MemberRemove(ctx context.Context, id uint64) (*clientv3.MemberRemoveResponse, error) { var resp clientv3.MemberRemoveResponse - err := ctl.spawnJsonCmd(ctx, &resp, "member", "remove", fmt.Sprintf("%x", id)) + err := ctl.spawnJSONCmd(ctx, &resp, "member", "remove", fmt.Sprintf("%x", id)) return &resp, err } func (ctl *EtcdctlV3) MemberPromote(ctx context.Context, id uint64) (*clientv3.MemberPromoteResponse, error) { var resp clientv3.MemberPromoteResponse - err := ctl.spawnJsonCmd(ctx, &resp, "member", "promote", fmt.Sprintf("%x", id)) + err := ctl.spawnJSONCmd(ctx, &resp, "member", "promote", fmt.Sprintf("%x", id)) return &resp, err } @@ -361,7 +361,7 @@ func (ctl *EtcdctlV3) Status(ctx context.Context) ([]*clientv3.StatusResponse, e Endpoint string Status *clientv3.StatusResponse } - err := ctl.spawnJsonCmd(ctx, &epStatus, "endpoint", "status") + err := ctl.spawnJSONCmd(ctx, &epStatus, "endpoint", "status") if err != nil { return nil, err } @@ -377,7 +377,7 @@ func (ctl *EtcdctlV3) HashKV(ctx context.Context, rev int64) ([]*clientv3.HashKV Endpoint string HashKV *clientv3.HashKVResponse } - err := ctl.spawnJsonCmd(ctx, &epHashKVs, "endpoint", "hashkv", "--rev", fmt.Sprint(rev)) + err := ctl.spawnJSONCmd(ctx, &epHashKVs, "endpoint", "hashkv", "--rev", fmt.Sprint(rev)) if err != nil { return nil, err } @@ -483,13 +483,13 @@ func (ctl *EtcdctlV3) KeepAliveOnce(ctx context.Context, id clientv3.LeaseID) (* func (ctl *EtcdctlV3) Revoke(ctx context.Context, id clientv3.LeaseID) (*clientv3.LeaseRevokeResponse, error) { var resp clientv3.LeaseRevokeResponse - err := ctl.spawnJsonCmd(ctx, &resp, "lease", "revoke", strconv.FormatInt(int64(id), 16)) + err := ctl.spawnJSONCmd(ctx, &resp, "lease", "revoke", strconv.FormatInt(int64(id), 16)) return &resp, err } func (ctl *EtcdctlV3) AlarmList(ctx context.Context) (*clientv3.AlarmResponse, error) { var resp clientv3.AlarmResponse - err := ctl.spawnJsonCmd(ctx, &resp, "alarm", "list") + err := ctl.spawnJSONCmd(ctx, &resp, "alarm", "list") return &resp, err } @@ -536,7 +536,7 @@ func (ctl *EtcdctlV3) AuthDisable(ctx context.Context) error { func (ctl *EtcdctlV3) AuthStatus(ctx context.Context) (*clientv3.AuthStatusResponse, error) { var resp clientv3.AuthStatusResponse - err := ctl.spawnJsonCmd(ctx, &resp, "auth", "status") + err := ctl.spawnJSONCmd(ctx, &resp, "auth", "status") return &resp, err } @@ -581,19 +581,19 @@ func (ctl *EtcdctlV3) UserAdd(ctx context.Context, name, password string, opts c func (ctl *EtcdctlV3) UserGet(ctx context.Context, name string) (*clientv3.AuthUserGetResponse, error) { var resp clientv3.AuthUserGetResponse - err := ctl.spawnJsonCmd(ctx, &resp, "user", "get", name) + err := ctl.spawnJSONCmd(ctx, &resp, "user", "get", name) return &resp, err } func (ctl *EtcdctlV3) UserList(ctx context.Context) (*clientv3.AuthUserListResponse, error) { var resp clientv3.AuthUserListResponse - err := ctl.spawnJsonCmd(ctx, &resp, "user", "list") + err := ctl.spawnJSONCmd(ctx, &resp, "user", "list") return &resp, err } func (ctl *EtcdctlV3) UserDelete(ctx context.Context, name string) (*clientv3.AuthUserDeleteResponse, error) { var resp clientv3.AuthUserDeleteResponse - err := ctl.spawnJsonCmd(ctx, &resp, "user", "delete", name) + err := ctl.spawnJSONCmd(ctx, &resp, "user", "delete", name) return &resp, err } @@ -616,54 +616,54 @@ func (ctl *EtcdctlV3) UserChangePass(ctx context.Context, user, newPass string) func (ctl *EtcdctlV3) UserGrantRole(ctx context.Context, user string, role string) (*clientv3.AuthUserGrantRoleResponse, error) { var resp clientv3.AuthUserGrantRoleResponse - err := ctl.spawnJsonCmd(ctx, &resp, "user", "grant-role", user, role) + err := ctl.spawnJSONCmd(ctx, &resp, "user", "grant-role", user, role) return &resp, err } func (ctl *EtcdctlV3) UserRevokeRole(ctx context.Context, user string, role string) (*clientv3.AuthUserRevokeRoleResponse, error) { var resp clientv3.AuthUserRevokeRoleResponse - err := ctl.spawnJsonCmd(ctx, &resp, "user", "revoke-role", user, role) + err := ctl.spawnJSONCmd(ctx, &resp, "user", "revoke-role", user, role) return &resp, err } func (ctl *EtcdctlV3) RoleAdd(ctx context.Context, name string) (*clientv3.AuthRoleAddResponse, error) { var resp clientv3.AuthRoleAddResponse - err := ctl.spawnJsonCmd(ctx, &resp, "role", "add", name) + err := ctl.spawnJSONCmd(ctx, &resp, "role", "add", name) return &resp, err } func (ctl *EtcdctlV3) RoleGrantPermission(ctx context.Context, name string, key, rangeEnd string, permType clientv3.PermissionType) (*clientv3.AuthRoleGrantPermissionResponse, error) { permissionType := authpb.Permission_Type_name[int32(permType)] var resp clientv3.AuthRoleGrantPermissionResponse - err := ctl.spawnJsonCmd(ctx, &resp, "role", "grant-permission", name, permissionType, key, rangeEnd) + err := ctl.spawnJSONCmd(ctx, &resp, "role", "grant-permission", name, permissionType, key, rangeEnd) return &resp, err } func (ctl *EtcdctlV3) RoleGet(ctx context.Context, role string) (*clientv3.AuthRoleGetResponse, error) { var resp clientv3.AuthRoleGetResponse - err := ctl.spawnJsonCmd(ctx, &resp, "role", "get", role) + err := ctl.spawnJSONCmd(ctx, &resp, "role", "get", role) return &resp, err } func (ctl *EtcdctlV3) RoleList(ctx context.Context) (*clientv3.AuthRoleListResponse, error) { var resp clientv3.AuthRoleListResponse - err := ctl.spawnJsonCmd(ctx, &resp, "role", "list") + err := ctl.spawnJSONCmd(ctx, &resp, "role", "list") return &resp, err } func (ctl *EtcdctlV3) RoleRevokePermission(ctx context.Context, role string, key, rangeEnd string) (*clientv3.AuthRoleRevokePermissionResponse, error) { var resp clientv3.AuthRoleRevokePermissionResponse - err := ctl.spawnJsonCmd(ctx, &resp, "role", "revoke-permission", role, key, rangeEnd) + err := ctl.spawnJSONCmd(ctx, &resp, "role", "revoke-permission", role, key, rangeEnd) return &resp, err } func (ctl *EtcdctlV3) RoleDelete(ctx context.Context, role string) (*clientv3.AuthRoleDeleteResponse, error) { var resp clientv3.AuthRoleDeleteResponse - err := ctl.spawnJsonCmd(ctx, &resp, "role", "delete", role) + err := ctl.spawnJSONCmd(ctx, &resp, "role", "delete", role) return &resp, err } -func (ctl *EtcdctlV3) spawnJsonCmd(ctx context.Context, output any, args ...string) error { +func (ctl *EtcdctlV3) spawnJSONCmd(ctx context.Context, output any, args ...string) error { args = append(args, "-w", "json") cmd, err := SpawnCmd(append(ctl.cmdArgs(), args...), nil) if err != nil { diff --git a/tests/framework/integration/cluster.go b/tests/framework/integration/cluster.go index caeabac261b..0a545217245 100644 --- a/tests/framework/integration/cluster.go +++ b/tests/framework/integration/cluster.go @@ -275,9 +275,9 @@ func (c *Cluster) mustNewMember(t testutil.TB) *Member { MaxRequestBytes: c.Cfg.MaxRequestBytes, SnapshotCount: c.Cfg.SnapshotCount, SnapshotCatchUpEntries: c.Cfg.SnapshotCatchUpEntries, - GrpcKeepAliveMinTime: c.Cfg.GRPCKeepAliveMinTime, - GrpcKeepAliveInterval: c.Cfg.GRPCKeepAliveInterval, - GrpcKeepAliveTimeout: c.Cfg.GRPCKeepAliveTimeout, + GRPCKeepAliveMinTime: c.Cfg.GRPCKeepAliveMinTime, + GRPCKeepAliveInterval: c.Cfg.GRPCKeepAliveInterval, + GRPCKeepAliveTimeout: c.Cfg.GRPCKeepAliveTimeout, ClientMaxCallSendMsgSize: c.Cfg.ClientMaxCallSendMsgSize, ClientMaxCallRecvMsgSize: c.Cfg.ClientMaxCallRecvMsgSize, UseIP: c.Cfg.UseIP, @@ -551,7 +551,7 @@ type Member struct { MemberNumber int Port string PeerListeners, ClientListeners []net.Listener - GrpcListener net.Listener + GRPCListener net.Listener // PeerTLSInfo enables peer TLS when set PeerTLSInfo *transport.TLSInfo // ClientTLSInfo enables client TLS when set @@ -562,10 +562,11 @@ type Member struct { Server *etcdserver.EtcdServer ServerClosers []func() - GrpcServerOpts []grpc.ServerOption - GrpcServer *grpc.Server - GrpcURL string - GrpcBridge *bridge + GRPCServerOpts []grpc.ServerOption + GRPCServer *grpc.Server + //revive:disable-next-line:var-naming + GrpcURL string + GRPCBridge *bridge // ServerClient is a clientv3 that directly calls the etcdserver. ServerClient *clientv3.Client @@ -582,7 +583,7 @@ type Member struct { IsLearner bool Closed bool - GrpcServerRecorder *grpctesting.GRPCRecorder + GRPCServerRecorder *grpctesting.GRPCRecorder LogObserver *testutils.LogObserver } @@ -602,9 +603,9 @@ type MemberConfig struct { MaxRequestBytes uint SnapshotCount uint64 SnapshotCatchUpEntries uint64 - GrpcKeepAliveMinTime time.Duration - GrpcKeepAliveInterval time.Duration - GrpcKeepAliveTimeout time.Duration + GRPCKeepAliveMinTime time.Duration + GRPCKeepAliveInterval time.Duration + GRPCKeepAliveTimeout time.Duration ClientMaxCallSendMsgSize int ClientMaxCallRecvMsgSize int UseIP bool @@ -697,18 +698,18 @@ func MustNewMember(t testutil.TB, mcfg MemberConfig) *Member { m.BcryptCost = uint(bcrypt.MinCost) // use min bcrypt cost to speedy up integration testing - m.GrpcServerOpts = []grpc.ServerOption{} - if mcfg.GrpcKeepAliveMinTime > time.Duration(0) { - m.GrpcServerOpts = append(m.GrpcServerOpts, grpc.KeepaliveEnforcementPolicy(keepalive.EnforcementPolicy{ - MinTime: mcfg.GrpcKeepAliveMinTime, + m.GRPCServerOpts = []grpc.ServerOption{} + if mcfg.GRPCKeepAliveMinTime > time.Duration(0) { + m.GRPCServerOpts = append(m.GRPCServerOpts, grpc.KeepaliveEnforcementPolicy(keepalive.EnforcementPolicy{ + MinTime: mcfg.GRPCKeepAliveMinTime, PermitWithoutStream: false, })) } - if mcfg.GrpcKeepAliveInterval > time.Duration(0) && - mcfg.GrpcKeepAliveTimeout > time.Duration(0) { - m.GrpcServerOpts = append(m.GrpcServerOpts, grpc.KeepaliveParams(keepalive.ServerParameters{ - Time: mcfg.GrpcKeepAliveInterval, - Timeout: mcfg.GrpcKeepAliveTimeout, + if mcfg.GRPCKeepAliveInterval > time.Duration(0) && + mcfg.GRPCKeepAliveTimeout > time.Duration(0) { + m.GRPCServerOpts = append(m.GRPCServerOpts, grpc.KeepaliveParams(keepalive.ServerParameters{ + Time: mcfg.GRPCKeepAliveInterval, + Timeout: mcfg.GRPCKeepAliveTimeout, })) } m.ClientMaxCallSendMsgSize = mcfg.ClientMaxCallSendMsgSize @@ -734,7 +735,7 @@ func MustNewMember(t testutil.TB, mcfg MemberConfig) *Member { m.ExperimentalMaxLearners = mcfg.ExperimentalMaxLearners } m.V2Deprecation = config.V2_DEPR_DEFAULT - m.GrpcServerRecorder = &grpctesting.GRPCRecorder{} + m.GRPCServerRecorder = &grpctesting.GRPCRecorder{} m.Logger, m.LogObserver = memberLogger(t, mcfg.Name) @@ -801,7 +802,7 @@ func (m *Member) listenGRPC() error { return err } } - m.GrpcListener = grpcListener + m.GRPCListener = grpcListener return nil } @@ -833,19 +834,19 @@ func (m *Member) addBridge() (*bridge, error) { if err != nil { return nil, fmt.Errorf("listen failed on bridge socket %s (%v)", bridgeAddr, err) } - m.GrpcBridge = newBridge(dialer{network: network, addr: grpcAddr}, bridgeListener) + m.GRPCBridge = newBridge(dialer{network: network, addr: grpcAddr}, bridgeListener) addr := bridgeListener.Addr().String() m.Logger.Info("LISTEN BRIDGE SUCCESS", zap.String("grpc-address", addr), zap.String("member", m.Name)) m.GrpcURL = m.clientScheme() + "://" + addr - return m.GrpcBridge, nil + return m.GRPCBridge, nil } func (m *Member) Bridge() *bridge { if !m.UseBridge { m.Logger.Panic("Bridge not available. Please configure using bridge before creating Cluster.") } - return m.GrpcBridge + return m.GRPCBridge } func (m *Member) grpcAddr() (network, host, port string) { @@ -871,7 +872,7 @@ func (m *Member) grpcAddr() (network, host, port string) { return network, host, port } -func (m *Member) GrpcPortNumber() string { +func (m *Member) GRPCPortNumber() string { return m.Port } @@ -975,7 +976,7 @@ func (m *Member) Launch() error { } } - if m.GrpcListener != nil { + if m.GRPCListener != nil { var ( tlscfg *tls.Config ) @@ -985,17 +986,17 @@ func (m *Member) Launch() error { return err } } - m.GrpcServer = v3rpc.Server(m.Server, tlscfg, m.GrpcServerRecorder.UnaryInterceptor(), m.GrpcServerOpts...) + m.GRPCServer = v3rpc.Server(m.Server, tlscfg, m.GRPCServerRecorder.UnaryInterceptor(), m.GRPCServerOpts...) m.ServerClient = v3client.New(m.Server) - lockpb.RegisterLockServer(m.GrpcServer, v3lock.NewLockServer(m.ServerClient)) - epb.RegisterElectionServer(m.GrpcServer, v3election.NewElectionServer(m.ServerClient)) - go m.GrpcServer.Serve(m.GrpcListener) + lockpb.RegisterLockServer(m.GRPCServer, v3lock.NewLockServer(m.ServerClient)) + epb.RegisterElectionServer(m.GRPCServer, v3election.NewElectionServer(m.ServerClient)) + go m.GRPCServer.Serve(m.GRPCListener) } m.RaftHandler = &testutil.PauseableHandler{Next: etcdhttp.NewPeerHandler(m.Logger, m.Server)} h := (http.Handler)(m.RaftHandler) - if m.GrpcListener != nil { + if m.GRPCListener != nil { h = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { m.RaftHandler.ServeHTTP(w, r) }) @@ -1119,7 +1120,7 @@ func (m *Member) Launch() error { } func (m *Member) RecordedRequests() []grpctesting.RequestInfo { - return m.GrpcServerRecorder.RecordedRequests() + return m.GRPCServerRecorder.RecordedRequests() } func (m *Member) WaitOK(t testutil.TB) { @@ -1177,21 +1178,21 @@ func (m *Member) Resume() { // Close stops the member'Server etcdserver and closes its connections func (m *Member) Close() { - if m.GrpcBridge != nil { - m.GrpcBridge.Close() - m.GrpcBridge = nil + if m.GRPCBridge != nil { + m.GRPCBridge.Close() + m.GRPCBridge = nil } if m.ServerClient != nil { m.ServerClient.Close() m.ServerClient = nil } - if m.GrpcServer != nil { + if m.GRPCServer != nil { ch := make(chan struct{}) go func() { defer close(ch) // close listeners to stop accepting new connections, // will block on any existing transports - m.GrpcServer.GracefulStop() + m.GRPCServer.GracefulStop() }() // wait until all pending RPCs are finished select { @@ -1199,10 +1200,10 @@ func (m *Member) Close() { case <-time.After(2 * time.Second): // took too long, manually close open transports // e.g. watch streams - m.GrpcServer.Stop() + m.GRPCServer.Stop() <-ch } - m.GrpcServer = nil + m.GRPCServer = nil } if m.Server != nil { m.Server.HardStop() @@ -1276,7 +1277,7 @@ func (m *Member) Restart(t testutil.TB) error { } m.ClientListeners = newClientListeners - if m.GrpcListener != nil { + if m.GRPCListener != nil { if err := m.listenGRPC(); err != nil { t.Fatal(err) } @@ -1545,7 +1546,7 @@ func CloseClients(t testutil.TB, clients []*clientv3.Client) { } } -type GrpcAPI struct { +type GRPCAPI struct { // Cluster is the Cluster API for the client'Server connection. Cluster pb.ClusterClient // KV is the keyvalue API for the client'Server connection. diff --git a/tests/framework/integration/cluster_direct.go b/tests/framework/integration/cluster_direct.go index 3bd8e5a5b01..71c2de5a5fa 100644 --- a/tests/framework/integration/cluster_direct.go +++ b/tests/framework/integration/cluster_direct.go @@ -25,8 +25,8 @@ import ( const ThroughProxy = false -func ToGRPC(c *clientv3.Client) GrpcAPI { - return GrpcAPI{ +func ToGRPC(c *clientv3.Client) GRPCAPI { + return GRPCAPI{ pb.NewClusterClient(c.ActiveConnection()), pb.NewKVClient(c.ActiveConnection()), pb.NewLeaseClient(c.ActiveConnection()), diff --git a/tests/framework/integration/cluster_proxy.go b/tests/framework/integration/cluster_proxy.go index a70499070b4..0ba8b59d02f 100644 --- a/tests/framework/integration/cluster_proxy.go +++ b/tests/framework/integration/cluster_proxy.go @@ -38,13 +38,13 @@ const proxyNamespace = "proxy-namespace" type grpcClientProxy struct { ctx context.Context ctxCancel func() - grpc GrpcAPI + grpc GRPCAPI wdonec <-chan struct{} kvdonec <-chan struct{} lpdonec <-chan struct{} } -func ToGRPC(c *clientv3.Client) GrpcAPI { +func ToGRPC(c *clientv3.Client) GRPCAPI { pmu.Lock() defer pmu.Unlock() @@ -73,7 +73,7 @@ func ToGRPC(c *clientv3.Client) GrpcAPI { lockp := grpcproxy.NewLockProxy(c) electp := grpcproxy.NewElectionProxy(c) - grpc := GrpcAPI{ + grpc := GRPCAPI{ adapter.ClusterServerToClusterClient(clp), adapter.KvServerToKvClient(kvp), adapter.LeaseServerToLeaseClient(lp), diff --git a/tests/framework/integration/testing.go b/tests/framework/integration/testing.go index 97450e7c9be..a211973ddc7 100644 --- a/tests/framework/integration/testing.go +++ b/tests/framework/integration/testing.go @@ -18,7 +18,7 @@ import ( "os" "testing" - grpc_logsettable "github.com/grpc-ecosystem/go-grpc-middleware/logging/settable" + grpclogsettable "github.com/grpc-ecosystem/go-grpc-middleware/logging/settable" "github.com/stretchr/testify/require" "go.uber.org/zap/zapcore" "go.uber.org/zap/zapgrpc" @@ -31,11 +31,11 @@ import ( gofail "go.etcd.io/gofail/runtime" ) -var grpc_logger grpc_logsettable.SettableLoggerV2 +var grpcLogger grpclogsettable.SettableLoggerV2 var insideTestContext bool func init() { - grpc_logger = grpc_logsettable.ReplaceGrpcLoggerV2() + grpcLogger = grpclogsettable.ReplaceGrpcLoggerV2() } type testOptions struct { @@ -118,13 +118,13 @@ func BeforeTest(t testutil.TB, opts ...TestOption) { // Registering cleanup early, such it will get executed even if the helper fails. t.Cleanup(func() { - grpc_logger.Reset() + grpcLogger.Reset() insideTestContext = previousInsideTestContext os.Chdir(previousWD) revertFunc() }) - grpc_logger.Set(zapgrpc.NewLogger(zaptest.NewLogger(t).Named("grpc"))) + grpcLogger.Set(zapgrpc.NewLogger(zaptest.NewLogger(t).Named("grpc"))) insideTestContext = true os.Chdir(t.TempDir()) diff --git a/tests/integration/grpc_test.go b/tests/integration/grpc_test.go index fcd56fbc1d9..7061ed61e63 100644 --- a/tests/integration/grpc_test.go +++ b/tests/integration/grpc_test.go @@ -149,7 +149,7 @@ func templateEndpoints(t *testing.T, pattern string, clus *integration.Cluster) var endpoints []string for _, m := range clus.Members { ent := pattern - ent = strings.ReplaceAll(ent, "${MEMBER_PORT}", m.GrpcPortNumber()) + ent = strings.ReplaceAll(ent, "${MEMBER_PORT}", m.GRPCPortNumber()) ent = strings.ReplaceAll(ent, "${MEMBER_NAME}", m.Name) endpoints = append(endpoints, ent) } @@ -159,7 +159,7 @@ func templateEndpoints(t *testing.T, pattern string, clus *integration.Cluster) func templateAuthority(t *testing.T, pattern string, m *integration.Member) string { t.Helper() authority := pattern - authority = strings.ReplaceAll(authority, "${MEMBER_PORT}", m.GrpcPortNumber()) + authority = strings.ReplaceAll(authority, "${MEMBER_PORT}", m.GRPCPortNumber()) authority = strings.ReplaceAll(authority, "${MEMBER_NAME}", m.Name) return authority }