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 require-error rule from testifylint #18814

Merged
merged 1 commit into from
Nov 3, 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
4 changes: 2 additions & 2 deletions server/etcdserver/api/v2store/store_ttl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func TestStoreUpdateValueTTL(t *testing.T) {
e, err = s.Get("/foo", false, false)
assert.Nil(t, e)
var v2Err *v2error.Error
assert.ErrorAs(t, err, &v2Err)
require.ErrorAs(t, err, &v2Err)
assert.Equal(t, v2error.EcodeKeyNotFound, v2Err.ErrorCode)
}

Expand Down Expand Up @@ -140,7 +140,7 @@ func TestStoreUpdateDirTTL(t *testing.T) {
e, err = s.Get("/foo/bar", false, false)
assert.Nil(t, e)
var v2Err *v2error.Error
assert.ErrorAs(t, err, &v2Err)
require.ErrorAs(t, err, &v2Err)
assert.Equal(t, v2error.EcodeKeyNotFound, v2Err.ErrorCode)
}

Expand Down
8 changes: 4 additions & 4 deletions tests/e2e/cluster_downgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ func verifySnapshot(t *testing.T, epc *e2e.EtcdProcessCluster) {
t.Logf("Verifying snapshot for member %d", i)
ss := snap.New(epc.Cfg.Logger, datadir.ToSnapDir(epc.Procs[i].Config().DataDirPath))
_, err := ss.Load()
assert.NoError(t, err)
require.NoError(t, err)
}
t.Logf("All members have a valid snapshot")
}
Expand All @@ -329,10 +329,10 @@ func verifySnapshotMembers(t *testing.T, epc *e2e.EtcdProcessCluster, expectedMe
require.NoError(t, err)
st := v2store.New(etcdserver.StoreClusterPrefix, etcdserver.StoreKeysPrefix)
err = st.Recovery(snap.Data)
assert.NoError(t, err)
require.NoError(t, err)
for _, m := range expectedMembers.Members {
_, err := st.Get(membership.MemberStoreKey(types.ID(m.ID)), true, true)
assert.NoError(t, err)
require.NoError(t, err)
}
t.Logf("Verifed snapshot for member %d", i)
}
Expand All @@ -344,7 +344,7 @@ func getMembersAndKeys(t *testing.T, cc *e2e.EtcdctlV3) (*clientv3.MemberListRes
defer cancel()

kvs, err := cc.Get(ctx, "", config.GetOptions{Prefix: true})
assert.NoError(t, err)
require.NoError(t, err)

members, err := cc.MemberList(ctx, false)
assert.NoError(t, err)
Expand Down
30 changes: 15 additions & 15 deletions tests/e2e/corrupt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,10 @@ func TestInPlaceRecovery(t *testing.T) {
//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())
assert.NoError(t, err)
require.NoError(t, err)
for i := 0; i < 10; i++ {
err = oldCc.Put(ctx, testutil.PickKey(int64(i)), fmt.Sprint(i), config.PutOptions{})
assert.NoErrorf(t, err, "error on put")
require.NoErrorf(t, err, "error on put")
}

// Create a new cluster config, but with the same port numbers. In this way the new servers can stay in
Expand All @@ -148,7 +148,7 @@ func TestInPlaceRecovery(t *testing.T) {
})

newCc, err := e2e.NewEtcdctl(epcNew.Cfg.Client, epcNew.EndpointsGRPC())
assert.NoError(t, err)
require.NoError(t, err)

// Rolling recovery of the servers.
wg := sync.WaitGroup{}
Expand Down Expand Up @@ -178,7 +178,7 @@ func TestInPlaceRecovery(t *testing.T) {
t.Log("new cluster started.")

alarmResponse, err := newCc.AlarmList(ctx)
assert.NoErrorf(t, err, "error on alarm list")
require.NoErrorf(t, err, "error on alarm list")
for _, alarm := range alarmResponse.Alarms {
if alarm.Alarm == etcdserverpb.AlarmType_CORRUPT {
t.Fatalf("there is no corruption after in-place recovery, but corruption reported.")
Expand Down Expand Up @@ -208,22 +208,22 @@ func TestPeriodicCheckDetectsCorruption(t *testing.T) {
cc := epc.Etcdctl()
for i := 0; i < 10; i++ {
err = cc.Put(ctx, testutil.PickKey(int64(i)), fmt.Sprint(i), config.PutOptions{})
assert.NoErrorf(t, err, "error on put")
require.NoErrorf(t, err, "error on put")
}

memberID, found, err := getMemberIDByName(ctx, cc, epc.Procs[0].Config().Name)
assert.NoErrorf(t, err, "error on member list")
require.NoErrorf(t, err, "error on member list")
assert.Truef(t, found, "member not found")

epc.Procs[0].Stop()
err = testutil.CorruptBBolt(datadir.ToBackendFileName(epc.Procs[0].Config().DataDirPath))
assert.NoError(t, err)
require.NoError(t, err)

err = epc.Procs[0].Restart(context.TODO())
assert.NoError(t, err)
require.NoError(t, err)
time.Sleep(checkTime * 11 / 10)
alarmResponse, err := cc.AlarmList(ctx)
assert.NoErrorf(t, err, "error on alarm list")
require.NoErrorf(t, err, "error on alarm list")
assert.Equal(t, []*etcdserverpb.AlarmMember{{Alarm: etcdserverpb.AlarmType_CORRUPT, MemberID: memberID}}, alarmResponse.Alarms)
}

Expand All @@ -249,23 +249,23 @@ func TestCompactHashCheckDetectCorruption(t *testing.T) {
cc := epc.Etcdctl()
for i := 0; i < 10; i++ {
err = cc.Put(ctx, testutil.PickKey(int64(i)), fmt.Sprint(i), config.PutOptions{})
assert.NoErrorf(t, err, "error on put")
require.NoErrorf(t, err, "error on put")
}
memberID, found, err := getMemberIDByName(ctx, cc, epc.Procs[0].Config().Name)
assert.NoErrorf(t, err, "error on member list")
require.NoErrorf(t, err, "error on member list")
assert.Truef(t, found, "member not found")

epc.Procs[0].Stop()
err = testutil.CorruptBBolt(datadir.ToBackendFileName(epc.Procs[0].Config().DataDirPath))
assert.NoError(t, err)
require.NoError(t, err)

err = epc.Procs[0].Restart(ctx)
assert.NoError(t, err)
require.NoError(t, err)
_, err = cc.Compact(ctx, 5, config.CompactOption{})
assert.NoError(t, err)
require.NoError(t, err)
time.Sleep(checkTime * 11 / 10)
alarmResponse, err := cc.AlarmList(ctx)
assert.NoErrorf(t, err, "error on alarm list")
require.NoErrorf(t, err, "error on alarm list")
assert.Equal(t, []*etcdserverpb.AlarmMember{{Alarm: etcdserverpb.AlarmType_CORRUPT, MemberID: memberID}}, alarmResponse.Alarms)
}

Expand Down
3 changes: 2 additions & 1 deletion tests/e2e/ctl_v3_grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"go.etcd.io/etcd/pkg/v3/expect"
"go.etcd.io/etcd/tests/v3/framework/config"
Expand Down Expand Up @@ -132,7 +133,7 @@ func TestAuthority(t *testing.T) {

endpoints := templateEndpoints(t, tc.clientURLPattern, epc)
client, err := e2e.NewEtcdctl(cfg.Client, endpoints)
assert.NoError(t, err)
require.NoError(t, err)
for i := 0; i < 100; i++ {
err = client.Put(ctx, "foo", "bar", config.PutOptions{})
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/ctl_v3_member_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,12 +299,12 @@ func TestRemoveNonExistingMember(t *testing.T) {

cfg := e2e.ConfigStandalone(*e2e.NewConfig())
epc, err := e2e.NewEtcdProcessCluster(ctx, t, e2e.WithConfig(cfg))
assert.NoError(t, err)
require.NoError(t, err)
defer epc.Close()
c := epc.Etcdctl()

_, err = c.MemberRemove(ctx, 1)
assert.Error(t, err)
require.Error(t, err)

// Ensure that membership is properly bootstrapped.
err = epc.Restart(ctx)
Expand Down
14 changes: 7 additions & 7 deletions tests/e2e/ctl_v3_snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,26 +468,26 @@ func TestBreakConsistentIndexNewerThanSnapshot(t *testing.T) {

t.Log("Stop member and copy out the db file to tmp directory")
err = member.Stop()
assert.NoError(t, err)
require.NoError(t, err)
dbPath := path.Join(member.Config().DataDirPath, "member", "snap", "db")
tmpFile := path.Join(t.TempDir(), "db")
err = copyFile(dbPath, tmpFile)
assert.NoError(t, err)
require.NoError(t, err)

t.Log("Ensure snapshot there is a newer snapshot")
err = member.Start(ctx)
assert.NoError(t, err)
require.NoError(t, err)
generateSnapshot(t, snapshotCount, member.Etcdctl())
_, err = member.Logs().ExpectWithContext(ctx, expect.ExpectedResponse{Value: "saved snapshot"})
assert.NoError(t, err)
require.NoError(t, err)
err = member.Stop()
assert.NoError(t, err)
require.NoError(t, err)

t.Log("Start etcd with older db file")
err = copyFile(tmpFile, dbPath)
assert.NoError(t, err)
require.NoError(t, err)
err = member.Start(ctx)
assert.Error(t, err)
require.Error(t, err)
_, err = member.Logs().ExpectWithContext(ctx, expect.ExpectedResponse{Value: "failed to find database snapshot file (snap: snapshot file doesn't exist)"})
assert.NoError(t, err)
}
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/leader_snapshot_no_proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func TestRecoverSnapshotBackend(t *testing.T) {
err = blackholedMember.Start(ctx)
require.NoError(t, err)
_, err = blackholedMember.Logs().ExpectWithContext(ctx, expect.ExpectedResponse{Value: "Recovering from snapshot backend"})
assert.NoError(t, err)
require.NoError(t, err)
err = blackholedMember.Etcdctl().Put(ctx, "a", "1", config.PutOptions{})
assert.NoError(t, err)
}
6 changes: 3 additions & 3 deletions tests/e2e/promote_experimental_flag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"go.etcd.io/etcd/tests/v3/framework/config"
"go.etcd.io/etcd/tests/v3/framework/e2e"
Expand All @@ -43,7 +43,7 @@ func TestWarningApplyDuration(t *testing.T) {

cc := epc.Etcdctl()
err = cc.Put(context.TODO(), "foo", "bar", config.PutOptions{})
assert.NoErrorf(t, err, "error on put")
require.NoErrorf(t, err, "error on put")

// verify warning
e2e.AssertProcessLogs(t, epc.Procs[0], "request stats")
Expand All @@ -70,7 +70,7 @@ func TestExperimentalWarningApplyDuration(t *testing.T) {

cc := epc.Etcdctl()
err = cc.Put(context.TODO(), "foo", "bar", config.PutOptions{})
assert.NoErrorf(t, err, "error on put")
require.NoErrorf(t, err, "error on put")

// verify warning
e2e.AssertProcessLogs(t, epc.Procs[0], "request stats")
Expand Down
39 changes: 20 additions & 19 deletions tests/e2e/v2store_deprecation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

"github.com/coreos/go-semver/semver"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
"go.uber.org/zap/zaptest"

Expand Down Expand Up @@ -52,7 +53,7 @@ func TestV2DeprecationNotYet(t *testing.T) {
e2e.BeforeTest(t)
t.Log("Verify its infeasible to start etcd with --v2-deprecation=not-yet mode")
proc, err := e2e.SpawnCmd([]string{e2e.BinPath.Etcd, "--v2-deprecation=not-yet"}, nil)
assert.NoError(t, err)
require.NoError(t, err)

_, err = proc.Expect(`invalid value "not-yet" for flag -v2-deprecation: invalid value "not-yet"`)
assert.NoError(t, err)
Expand All @@ -71,16 +72,16 @@ func TestV2DeprecationWriteOnlyWAL(t *testing.T) {
e2e.WithDataDirPath(dataDirPath),
))
epc, err := e2e.NewEtcdProcessCluster(context.TODO(), t, e2e.WithConfig(cfg))
assert.NoError(t, err)
require.NoError(t, err)
memberDataDir := epc.Procs[0].Config().DataDirPath

writeCustomV2Data(t, epc, 1)

assert.NoError(t, epc.Stop())
require.NoError(t, epc.Stop())

t.Log("Verify its infeasible to start etcd with --v2-deprecation=write-only mode")
proc, err := e2e.SpawnCmd([]string{e2e.BinPath.Etcd, "--v2-deprecation=write-only", "--data-dir=" + memberDataDir}, nil)
assert.NoError(t, err)
require.NoError(t, err)

_, err = proc.Expect("detected disallowed v2 WAL for stage --v2-deprecation=write-only")
assert.NoError(t, err)
Expand All @@ -100,17 +101,17 @@ func TestV2DeprecationWriteOnlySnapshot(t *testing.T) {
e2e.WithSnapshotCount(10),
))
epc, err := e2e.NewEtcdProcessCluster(context.TODO(), t, e2e.WithConfig(cfg))
assert.NoError(t, err)
require.NoError(t, err)
memberDataDir := epc.Procs[0].Config().DataDirPath

// We need to exceed 'SnapshotCount' such that v2 snapshot is dumped.
writeCustomV2Data(t, epc, 10)

assert.NoError(t, epc.Stop())
require.NoError(t, epc.Stop())

t.Log("Verify its infeasible to start etcd with --v2-deprecation=write-only mode")
proc, err := e2e.SpawnCmd([]string{e2e.BinPath.Etcd, "--v2-deprecation=write-only", "--data-dir=" + memberDataDir}, nil)
assert.NoError(t, err)
require.NoError(t, err)
defer proc.Close()

_, err = proc.Expect("detected disallowed custom content in v2store for stage --v2-deprecation=write-only")
Expand All @@ -132,12 +133,12 @@ func TestV2DeprecationSnapshotMatches(t *testing.T) {
oldMemberDataDir := epc.Procs[0].Config().DataDirPath
cc1 := epc.Etcdctl()
members1 := addAndRemoveKeysAndMembers(ctx, t, cc1, snapshotCount)
assert.NoError(t, epc.Close())
require.NoError(t, epc.Close())
epc = runEtcdAndCreateSnapshot(t, e2e.CurrentVersion, currentReleaseData, snapshotCount)
newMemberDataDir := epc.Procs[0].Config().DataDirPath
cc2 := epc.Etcdctl()
members2 := addAndRemoveKeysAndMembers(ctx, t, cc2, snapshotCount)
assert.NoError(t, epc.Close())
require.NoError(t, epc.Close())

assertSnapshotsMatch(t, oldMemberDataDir, newMemberDataDir, func(data []byte) []byte {
// Patch members ids
Expand All @@ -164,7 +165,7 @@ func TestV2DeprecationSnapshotRecover(t *testing.T) {

cc := epc.Etcdctl()
lastReleaseGetResponse, err := cc.Get(ctx, "", config.GetOptions{Prefix: true})
assert.NoError(t, err)
require.NoError(t, err)

lastReleaseMemberListResponse, err := cc.MemberList(ctx, false)
assert.NoError(t, err)
Expand All @@ -175,14 +176,14 @@ func TestV2DeprecationSnapshotRecover(t *testing.T) {
e2e.WithDataDirPath(dataDir),
))
epc, err = e2e.NewEtcdProcessCluster(context.TODO(), t, e2e.WithConfig(cfg))
assert.NoError(t, err)
require.NoError(t, err)

cc = epc.Etcdctl()
currentReleaseGetResponse, err := cc.Get(ctx, "", config.GetOptions{Prefix: true})
assert.NoError(t, err)
require.NoError(t, err)

currentReleaseMemberListResponse, err := cc.MemberList(ctx, false)
assert.NoError(t, err)
require.NoError(t, err)

assert.Equal(t, lastReleaseGetResponse.Kvs, currentReleaseGetResponse.Kvs)
assert.Equal(t, lastReleaseMemberListResponse.Members, currentReleaseMemberListResponse.Members)
Expand All @@ -206,25 +207,25 @@ func addAndRemoveKeysAndMembers(ctx context.Context, t testing.TB, cc *e2e.Etcdc
var i uint64
for i = 0; i < snapshotCount*3; i++ {
err := cc.Put(ctx, fmt.Sprintf("%d", i), "1", config.PutOptions{})
assert.NoError(t, err)
require.NoError(t, err)
}
member1, err := cc.MemberAddAsLearner(ctx, "member1", []string{"http://127.0.0.1:2000"})
assert.NoError(t, err)
require.NoError(t, err)
members = append(members, member1.Member.ID)

for i = 0; i < snapshotCount*2; i++ {
_, err = cc.Delete(ctx, fmt.Sprintf("%d", i), config.DeleteOptions{})
assert.NoError(t, err)
require.NoError(t, err)
}
_, err = cc.MemberRemove(ctx, member1.Member.ID)
assert.NoError(t, err)
require.NoError(t, err)

for i = 0; i < snapshotCount; i++ {
err = cc.Put(ctx, fmt.Sprintf("%d", i), "2", config.PutOptions{})
assert.NoError(t, err)
require.NoError(t, err)
}
member2, err := cc.MemberAddAsLearner(ctx, "member2", []string{"http://127.0.0.1:2001"})
assert.NoError(t, err)
require.NoError(t, err)
members = append(members, member2.Member.ID)

for i = 0; i < snapshotCount/2; i++ {
Expand Down
Loading