From 362995e7175a3d43945b0d5a9bea3143bc88de2e Mon Sep 17 00:00:00 2001 From: Xinyuan Du Date: Tue, 9 Apr 2024 16:35:38 +0800 Subject: [PATCH] replace t.error/fatal with assert/request (/raftpb) Signed-off-by: Xinyuan Du --- raftpb/confstate_test.go | 6 +++--- raftpb/raft_test.go | 27 +++++++++++---------------- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/raftpb/confstate_test.go b/raftpb/confstate_test.go index 712d7158..cf5877ea 100644 --- a/raftpb/confstate_test.go +++ b/raftpb/confstate_test.go @@ -16,6 +16,8 @@ package raftpb import ( "testing" + + "github.com/stretchr/testify/require" ) func TestConfState_Equivalent(t *testing.T) { @@ -50,9 +52,7 @@ func TestConfState_Equivalent(t *testing.T) { for _, tc := range testCases { t.Run("", func(t *testing.T) { - if err := tc.cs.Equivalent(tc.cs2); (err == nil) != tc.ok { - t.Fatalf("wanted error: %t, got:\n%s", tc.ok, err) - } + require.Equal(t, tc.ok, tc.cs.Equivalent(tc.cs2) == nil) }) } } diff --git a/raftpb/raft_test.go b/raftpb/raft_test.go index 704ff94f..a369aad6 100644 --- a/raftpb/raft_test.go +++ b/raftpb/raft_test.go @@ -18,16 +18,11 @@ import ( "math/bits" "testing" "unsafe" + + "github.com/stretchr/testify/assert" ) func TestProtoMemorySizes(t *testing.T) { - assert := func(size, exp uintptr, name string) { - t.Helper() - if size != exp { - t.Errorf("expected size of %s proto to be %d bytes, found %d bytes", name, exp, size) - } - } - if64Bit := func(yes, no uintptr) uintptr { if bits.UintSize == 64 { return yes @@ -36,29 +31,29 @@ func TestProtoMemorySizes(t *testing.T) { } var e Entry - assert(unsafe.Sizeof(e), if64Bit(48, 32), "Entry") + assert.Equal(t, if64Bit(48, 32), unsafe.Sizeof(e), "Entry size check") var sm SnapshotMetadata - assert(unsafe.Sizeof(sm), if64Bit(120, 68), "SnapshotMetadata") + assert.Equal(t, if64Bit(120, 68), unsafe.Sizeof(sm), "SnapshotMetadata size check") var s Snapshot - assert(unsafe.Sizeof(s), if64Bit(144, 80), "Snapshot") + assert.Equal(t, if64Bit(144, 80), unsafe.Sizeof(s), "Snapshot size check") var m Message - assert(unsafe.Sizeof(m), if64Bit(160, 112), "Message") + assert.Equal(t, if64Bit(160, 112), unsafe.Sizeof(m), "Message size check") var hs HardState - assert(unsafe.Sizeof(hs), 24, "HardState") + assert.Equal(t, uintptr(24), unsafe.Sizeof(hs), "HardState size check") var cs ConfState - assert(unsafe.Sizeof(cs), if64Bit(104, 52), "ConfState") + assert.Equal(t, if64Bit(104, 52), unsafe.Sizeof(cs), "ConfState size check") var cc ConfChange - assert(unsafe.Sizeof(cc), if64Bit(48, 32), "ConfChange") + assert.Equal(t, if64Bit(48, 32), unsafe.Sizeof(cc), "ConfChange size check") var ccs ConfChangeSingle - assert(unsafe.Sizeof(ccs), if64Bit(16, 12), "ConfChangeSingle") + assert.Equal(t, if64Bit(16, 12), unsafe.Sizeof(ccs), "ConfChangeSingle size check") var ccv2 ConfChangeV2 - assert(unsafe.Sizeof(ccv2), if64Bit(56, 28), "ConfChangeV2") + assert.Equal(t, if64Bit(56, 28), unsafe.Sizeof(ccv2), "ConfChangeV2 size check") }