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

Test: Replace t.error/fatal with assert/request in [/raftpb] #194

Merged
merged 1 commit into from
Apr 11, 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
6 changes: 3 additions & 3 deletions raftpb/confstate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ package raftpb

import (
"testing"

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

func TestConfState_Equivalent(t *testing.T) {
Expand Down Expand Up @@ -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)
})
}
}
27 changes: 11 additions & 16 deletions raftpb/raft_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
}
Loading