Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: enable gofumpt instead of gofmt linter in tests #18953

Merged
merged 1 commit into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions tests/common/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ import (
"go.etcd.io/etcd/tests/v3/framework/testutils"
)

var tokenTTL = time.Second * 3
var defaultAuthToken = fmt.Sprintf("jwt,pub-key=%s,priv-key=%s,sign-method=RS256,ttl=%s",
mustAbsPath("../fixtures/server.crt"), mustAbsPath("../fixtures/server.key.insecure"), tokenTTL)
var (
tokenTTL = time.Second * 3
defaultAuthToken = fmt.Sprintf("jwt,pub-key=%s,priv-key=%s,sign-method=RS256,ttl=%s",
mustAbsPath("../fixtures/server.crt"), mustAbsPath("../fixtures/server.key.insecure"), tokenTTL)
)

const (
PermissionDenied = "etcdserver: permission denied"
Expand Down
2 changes: 1 addition & 1 deletion tests/common/compact_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestCompact(t *testing.T) {
defer clus.Close()
cc := testutils.MustClient(clus.Client())
testutils.ExecuteUntil(ctx, t, func() {
var kvs = []testutils.KV{{Key: "key", Val: "val1"}, {Key: "key", Val: "val2"}, {Key: "key", Val: "val3"}}
kvs := []testutils.KV{{Key: "key", Val: "val1"}, {Key: "key", Val: "val2"}, {Key: "key", Val: "val3"}}
for i := range kvs {
err := cc.Put(ctx, kvs[i].Key, kvs[i].Val, config.PutOptions{})
require.NoErrorf(t, err, "compactTest #%d: put kv error", i)
Expand Down
2 changes: 1 addition & 1 deletion tests/common/defrag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestDefragOnline(t *testing.T) {
cc := testutils.MustClient(clus.Client())
testutils.ExecuteUntil(ctx, t, func() {
defer clus.Close()
var kvs = []testutils.KV{{Key: "key", Val: "val1"}, {Key: "key", Val: "val2"}, {Key: "key", Val: "val3"}}
kvs := []testutils.KV{{Key: "key", Val: "val1"}, {Key: "key", Val: "val2"}, {Key: "key", Val: "val3"}}
for i := range kvs {
if err := cc.Put(ctx, kvs[i].Key, kvs[i].Val, config.PutOptions{}); err != nil {
t.Fatalf("compactTest #%d: put kv error (%v)", i, err)
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/corrupt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func TestInPlaceRecovery(t *testing.T) {
})
t.Log("old cluster started.")

//Put some data into the old cluster, so that after recovering from a blank db, the hash diverges.
// Put some data into the old cluster, so that after recovering from a blank db, the hash diverges.
t.Log("putting 10 keys...")
oldCc, err := e2e.NewEtcdctl(epcOld.Cfg.Client, epcOld.EndpointsGRPC())
require.NoError(t, err)
Expand Down
2 changes: 2 additions & 0 deletions tests/e2e/ctl_v3_auth_no_proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ import (
func TestCtlV3AuthCertCN(t *testing.T) {
testCtl(t, authTestCertCN, withCfg(*e2e.NewConfigClientTLSCertAuth()))
}

func TestCtlV3AuthCertCNAndUsername(t *testing.T) {
testCtl(t, authTestCertCNAndUsername, withCfg(*e2e.NewConfigClientTLSCertAuth()))
}

func TestCtlV3AuthCertCNAndUsernameNoPassword(t *testing.T) {
testCtl(t, authTestCertCNAndUsernameNoPassword, withCfg(*e2e.NewConfigClientTLSCertAuth()))
}
Expand Down
1 change: 1 addition & 0 deletions tests/e2e/ctl_v3_auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func TestCtlV3AuthEndpointHealth(t *testing.T) {

// TestCtlV3AuthSnapshot TODO fill up common/maintenance_auth_test.go when Snapshot API is added in interfaces.Client
func TestCtlV3AuthSnapshot(t *testing.T) { testCtl(t, authTestSnapshot) }

func TestCtlV3AuthSnapshotJWT(t *testing.T) {
testCtl(t, authTestSnapshot, withCfg(*e2e.NewConfigJWT()))
}
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/ctl_v3_completion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func testShellCompletion(t *testing.T, binPath, shellName string) {
require.NoError(t, completionCmd.Run())

filename := fmt.Sprintf("etcdctl-%s.completion", shellName)
require.NoError(t, os.WriteFile(filename, stdout.Bytes(), 0644))
require.NoError(t, os.WriteFile(filename, stdout.Bytes(), 0o644))

shellCmd := exec.Command(shellName, "-c", "source "+filename)
require.NoError(t, shellCmd.Run())
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/ctl_v3_defrag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestCtlV3DefragOffline(t *testing.T) {
}

func maintenanceInitKeys(cx ctlCtx) {
var kvs = []kv{{"key", "val1"}, {"key", "val2"}, {"key", "val3"}}
kvs := []kv{{"key", "val1"}, {"key", "val2"}, {"key", "val3"}}
for i := range kvs {
if err := ctlV3Put(cx, kvs[i].key, kvs[i].val, ""); err != nil {
cx.t.Fatal(err)
Expand Down
18 changes: 7 additions & 11 deletions tests/e2e/ctl_v3_kv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,7 @@ func getFormatTest(cx ctlCtx) {
}

func getRevTest(cx ctlCtx) {
var (
kvs = []kv{{"key", "val1"}, {"key", "val2"}, {"key", "val3"}}
)
kvs := []kv{{"key", "val1"}, {"key", "val2"}, {"key", "val3"}}
for i := range kvs {
if err := ctlV3Put(cx, kvs[i].key, kvs[i].val, ""); err != nil {
cx.t.Fatalf("getRevTest #%d: ctlV3Put error (%v)", i, err)
Expand All @@ -218,14 +216,12 @@ func getRevTest(cx ctlCtx) {
}

func getMinMaxCreateModRevTest(cx ctlCtx) {
var (
kvs = []kv{ // revision: store | key create | key modify
{"key1", "val1"}, // 2 2 2
{"key2", "val2"}, // 3 3 3
{"key1", "val3"}, // 4 2 4
{"key4", "val4"}, // 5 5 5
}
)
kvs := []kv{ // revision: store | key create | key modify
{"key1", "val1"}, // 2 2 2
{"key2", "val2"}, // 3 3 3
{"key1", "val3"}, // 4 2 4
{"key4", "val4"}, // 5 5 5
}
for i := range kvs {
if err := ctlV3Put(cx, kvs[i].key, kvs[i].val, ""); err != nil {
cx.t.Fatalf("getRevTest #%d: ctlV3Put error (%v)", i, err)
Expand Down
3 changes: 3 additions & 0 deletions tests/e2e/ctl_v3_lease_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@ func TestCtlV3LeaseKeepAlive(t *testing.T) { testCtl(t, leaseTestKeepAlive) }
func TestCtlV3LeaseKeepAliveNoTLS(t *testing.T) {
testCtl(t, leaseTestKeepAlive, withCfg(*e2e.NewConfigNoTLS()))
}

func TestCtlV3LeaseKeepAliveClientTLS(t *testing.T) {
testCtl(t, leaseTestKeepAlive, withCfg(*e2e.NewConfigClientTLS()))
}

func TestCtlV3LeaseKeepAliveClientAutoTLS(t *testing.T) {
testCtl(t, leaseTestKeepAlive, withCfg(*e2e.NewConfigClientAutoTLS()))
}

func TestCtlV3LeaseKeepAlivePeerTLS(t *testing.T) {
testCtl(t, leaseTestKeepAlive, withCfg(*e2e.NewConfigPeerTLS()))
}
Expand Down
3 changes: 3 additions & 0 deletions tests/e2e/ctl_v3_member_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,15 @@ func TestCtlV3MemberUpdate(t *testing.T) { testCtl(t, memberUpdateTest) }
func TestCtlV3MemberUpdateNoTLS(t *testing.T) {
testCtl(t, memberUpdateTest, withCfg(*e2e.NewConfigNoTLS()))
}

func TestCtlV3MemberUpdateClientTLS(t *testing.T) {
testCtl(t, memberUpdateTest, withCfg(*e2e.NewConfigClientTLS()))
}

func TestCtlV3MemberUpdateClientAutoTLS(t *testing.T) {
testCtl(t, memberUpdateTest, withCfg(*e2e.NewConfigClientAutoTLS()))
}

func TestCtlV3MemberUpdatePeerTLS(t *testing.T) {
testCtl(t, memberUpdateTest, withCfg(*e2e.NewConfigPeerTLS()))
}
Expand Down
9 changes: 6 additions & 3 deletions tests/e2e/ctl_v3_snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ func testIssue6361(t *testing.T) {
"--initial-cluster", epc.Procs[0].Config().InitialCluster,
"--initial-cluster-token", epc.Procs[0].Config().InitialToken,
"--initial-advertise-peer-urls", epc.Procs[0].Config().PeerURL.String(),
"--data-dir", newDataDir},
"--data-dir", newDataDir,
},
expect.ExpectedResponse{Value: "added member"})
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -264,10 +265,12 @@ func testIssue6361(t *testing.T) {
t.Log("Starting the new member")
// start the new member
var nepc *expect.ExpectProcess
nepc, err = e2e.SpawnCmd([]string{epc.Procs[0].Config().ExecPath, "--name", name2,
nepc, err = e2e.SpawnCmd([]string{
epc.Procs[0].Config().ExecPath, "--name", name2,
"--listen-client-urls", clientURL, "--advertise-client-urls", clientURL,
"--listen-peer-urls", peerURL, "--initial-advertise-peer-urls", peerURL,
"--initial-cluster", initialCluster2, "--initial-cluster-state", "existing", "--data-dir", newDataDir2}, nil)
"--initial-cluster", initialCluster2, "--initial-cluster-state", "existing", "--data-dir", newDataDir2,
}, nil)
if err != nil {
t.Fatal(err)
}
Expand Down
3 changes: 3 additions & 0 deletions tests/e2e/ctl_v3_watch_no_cov_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@ func TestCtlV3WatchTimeout(t *testing.T) { testCtl(t, watchTest, withDefaultDi
func TestCtlV3WatchInteractive(t *testing.T) {
testCtl(t, watchTest, withInteractive())
}

func TestCtlV3WatchInteractiveNoTLS(t *testing.T) {
testCtl(t, watchTest, withInteractive(), withCfg(*e2e.NewConfigNoTLS()))
}

func TestCtlV3WatchInteractiveClientTLS(t *testing.T) {
testCtl(t, watchTest, withInteractive(), withCfg(*e2e.NewConfigClientTLS()))
}

func TestCtlV3WatchInteractivePeerTLS(t *testing.T) {
testCtl(t, watchTest, withInteractive(), withCfg(*e2e.NewConfigPeerTLS()))
}
Expand Down
4 changes: 4 additions & 0 deletions tests/e2e/discovery_v3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,23 @@ import (
func TestClusterOf1UsingV3Discovery_1endpoint(t *testing.T) {
testClusterUsingV3Discovery(t, 1, 1, e2e.ClientNonTLS, false)
}

func TestClusterOf3UsingV3Discovery_1endpoint(t *testing.T) {
testClusterUsingV3Discovery(t, 1, 3, e2e.ClientTLS, true)
}

func TestTLSClusterOf5UsingV3Discovery_1endpoint(t *testing.T) {
testClusterUsingV3Discovery(t, 1, 5, e2e.ClientTLS, false)
}

func TestClusterOf1UsingV3Discovery_3endpoints(t *testing.T) {
testClusterUsingV3Discovery(t, 3, 1, e2e.ClientNonTLS, false)
}

func TestClusterOf3UsingV3Discovery_3endpoints(t *testing.T) {
testClusterUsingV3Discovery(t, 3, 3, e2e.ClientTLS, true)
}

func TestTLSClusterOf5UsingV3Discovery_3endpoints(t *testing.T) {
testClusterUsingV3Discovery(t, 3, 5, e2e.ClientTLS, false)
}
Expand Down
6 changes: 4 additions & 2 deletions tests/e2e/etcd_grpcproxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ func TestGrpcProxyAutoSync(t *testing.T) {
)

// Run independent grpc-proxy instance
proxyProc, err := e2e.SpawnCmd([]string{e2e.BinPath.Etcd, "grpc-proxy", "start",
proxyProc, err := e2e.SpawnCmd([]string{
e2e.BinPath.Etcd, "grpc-proxy", "start",
"--advertise-client-url", proxyClientURL, "--listen-addr", proxyClientURL,
"--endpoints", node1ClientURL,
"--endpoints-auto-sync-interval", "1s",
Expand Down Expand Up @@ -107,7 +108,8 @@ func TestGrpcProxyTLSVersions(t *testing.T) {
)

// Run independent grpc-proxy instance
proxyProc, err := e2e.SpawnCmd([]string{e2e.BinPath.Etcd, "grpc-proxy", "start",
proxyProc, err := e2e.SpawnCmd([]string{
e2e.BinPath.Etcd, "grpc-proxy", "start",
"--advertise-client-url", proxyClientURL,
"--listen-addr", proxyClientURL,
"--endpoints", node1ClientURL,
Expand Down
1 change: 0 additions & 1 deletion tests/e2e/etcd_release_upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ func TestReleaseUpgradeWithRestart(t *testing.T) {
e2e.WithSnapshotCount(10),
e2e.WithBasePeerScheme("unix"),
)

if err != nil {
t.Fatalf("could not start etcd process cluster (%v)", err)
}
Expand Down
4 changes: 1 addition & 3 deletions tests/e2e/gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ import (
"go.etcd.io/etcd/tests/v3/framework/e2e"
)

var (
defaultGatewayEndpoint = "127.0.0.1:23790"
)
var defaultGatewayEndpoint = "127.0.0.1:23790"

func TestGateway(t *testing.T) {
ec, err := e2e.NewEtcdProcessCluster(context.TODO(), t)
Expand Down
50 changes: 24 additions & 26 deletions tests/e2e/http_health_check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,33 +172,31 @@ func TestHTTPHealthHandler(t *testing.T) {
}
}

var (
defaultHealthCheckConfigs = []healthCheckConfig{
{
url: "/livez",
expectedStatusCode: http.StatusOK,
expectedRespSubStrings: []string{`ok`},
},
{
url: "/readyz",
expectedStatusCode: http.StatusOK,
expectedRespSubStrings: []string{`ok`},
var defaultHealthCheckConfigs = []healthCheckConfig{
{
url: "/livez",
expectedStatusCode: http.StatusOK,
expectedRespSubStrings: []string{`ok`},
},
{
url: "/readyz",
expectedStatusCode: http.StatusOK,
expectedRespSubStrings: []string{`ok`},
},
{
url: "/livez?verbose=true",
expectedStatusCode: http.StatusOK,
expectedRespSubStrings: []string{`[+]serializable_read ok`},
},
{
url: "/readyz?verbose=true",
expectedStatusCode: http.StatusOK,
expectedRespSubStrings: []string{
`[+]serializable_read ok`,
`[+]data_corruption ok`,
},
{
url: "/livez?verbose=true",
expectedStatusCode: http.StatusOK,
expectedRespSubStrings: []string{`[+]serializable_read ok`},
},
{
url: "/readyz?verbose=true",
expectedStatusCode: http.StatusOK,
expectedRespSubStrings: []string{
`[+]serializable_read ok`,
`[+]data_corruption ok`,
},
},
}
)
},
}

func TestHTTPLivezReadyzHandler(t *testing.T) {
e2e.BeforeTest(t)
Expand Down
5 changes: 3 additions & 2 deletions tests/e2e/v2store_deprecation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ func writeCustomV2Data(t testing.TB, epc *e2e.EtcdProcessCluster, count int) {
for i := 0; i < count; i++ {
if err := e2e.CURLPut(epc, e2e.CURLReq{
Endpoint: "/v2/keys/foo", Value: "bar" + fmt.Sprint(i),
Expected: expect.ExpectedResponse{Value: `{"action":"set","node":{"key":"/foo","value":"bar` + fmt.Sprint(i)}}); err != nil {
Expected: expect.ExpectedResponse{Value: `{"action":"set","node":{"key":"/foo","value":"bar` + fmt.Sprint(i)},
}); err != nil {
t.Fatalf("failed put with curl (%v)", err)
}
}
Expand Down Expand Up @@ -276,7 +277,7 @@ func assertMembershipEqual(t testing.TB, firstStore v2store.Store, secondStore v
rc2.SetStore(secondStore)
rc2.Recover(func(lg *zap.Logger, v *semver.Version) { return })

//membership should match
// membership should match
if !reflect.DeepEqual(rc1.Members(), rc2.Members()) {
t.Logf("memberids_from_last_version = %+v, member_ids_from_current_version = %+v", rc1.MemberIDs(), rc2.MemberIDs())
t.Errorf("members_from_last_version_snapshot = %+v, members_from_current_version_snapshot %+v", rc1.Members(), rc2.Members())
Expand Down
7 changes: 3 additions & 4 deletions tests/e2e/v3_curl_auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
func TestCurlV3Auth(t *testing.T) {
testCtl(t, testCurlV3Auth)
}

func TestCurlV3AuthClientTLSCertAuth(t *testing.T) {
testCtl(t, testCurlV3Auth, withCfg(*e2e.NewConfigClientTLSCertAuthWithNoCN()))
}
Expand Down Expand Up @@ -88,7 +89,7 @@ func testCurlV3Auth(cx ctlCtx) {
cx.t.Fatalf("testCurlV3Auth failed to create role (%v)", err)
}

//grant root role
// grant root role
for i := 0; i < len(usernames); i++ {
grantroleroot, merr := json.Marshal(&pb.AuthUserGrantRoleRequest{User: usernames[i], Role: "root"})
require.NoError(cx.t, merr)
Expand Down Expand Up @@ -377,9 +378,7 @@ func testCurlV3AuthRoleBasicOperations(cx ctlCtx) {
}

func testCurlV3AuthRoleManagePermission(cx ctlCtx) {
var (
rolename = "role1"
)
rolename := "role1"

// create a role
role, err := json.Marshal(&pb.AuthRoleAddRequest{Name: rolename})
Expand Down
3 changes: 3 additions & 0 deletions tests/e2e/v3_curl_lease_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@ import (
func TestCurlV3LeaseGrantNoTLS(t *testing.T) {
testCtl(t, testCurlV3LeaseGrant, withCfg(*e2e.NewConfigNoTLS()))
}

func TestCurlV3LeaseRevokeNoTLS(t *testing.T) {
testCtl(t, testCurlV3LeaseRevoke, withCfg(*e2e.NewConfigNoTLS()))
}

func TestCurlV3LeaseLeasesNoTLS(t *testing.T) {
testCtl(t, testCurlV3LeaseLeases, withCfg(*e2e.NewConfigNoTLS()))
}

func TestCurlV3LeaseKeepAliveNoTLS(t *testing.T) {
testCtl(t, testCurlV3LeaseKeepAlive, withCfg(*e2e.NewConfigNoTLS()))
}
Expand Down
4 changes: 1 addition & 3 deletions tests/framework/e2e/curl.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ func CURLPrefixArgsCluster(cfg *EtcdProcessClusterConfig, member EtcdProcess, me
}

func CURLPrefixArgs(clientURL string, cfg ClientConfig, CN bool, method string, req CURLReq) []string {
var (
cmdArgs = []string{"curl"}
)
cmdArgs := []string{"curl"}
if req.HTTPVersion != "" {
cmdArgs = append(cmdArgs, "--http"+req.HTTPVersion)
}
Expand Down
6 changes: 2 additions & 4 deletions tests/framework/e2e/etcd_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ import (
"go.etcd.io/etcd/tests/v3/framework/config"
)

var (
EtcdServerReadyLines = []string{"ready to serve client requests"}
)
var EtcdServerReadyLines = []string{"ready to serve client requests"}

// EtcdProcess is a process that serves etcd requests.
type EtcdProcess interface {
Expand Down Expand Up @@ -112,7 +110,7 @@ func NewEtcdServerProcess(t testing.TB, cfg *EtcdServerProcessConfig) (*EtcdServ
if err := os.RemoveAll(cfg.DataDirPath); err != nil {
return nil, err
}
if err := os.Mkdir(cfg.DataDirPath, 0700); err != nil {
if err := os.Mkdir(cfg.DataDirPath, 0o700); err != nil {
return nil, err
}
}
Expand Down
Loading