Skip to content

Commit

Permalink
fix: use testify instead of t.Fatal or t.Error in contrib package
Browse files Browse the repository at this point in the history
Signed-off-by: Matthieu MOREL <[email protected]>
  • Loading branch information
mmorel-35 committed Dec 1, 2024
1 parent 3d46df1 commit 7f9efcf
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 16 deletions.
12 changes: 3 additions & 9 deletions contrib/raftexample/kvstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ func Test_kvstore_snapshot(t *testing.T) {
s := &kvstore{kvStore: tm}

v, _ := s.Lookup("foo")
if v != "bar" {
t.Fatalf("foo has unexpected value, got %s", v)
}
require.Equalf(t, "bar", v, "foo has unexpected value, got %s", v)

data, err := s.getSnapshot()
require.NoError(t, err)
Expand All @@ -37,10 +35,6 @@ func Test_kvstore_snapshot(t *testing.T) {
err = s.recoverFromSnapshot(data)
require.NoError(t, err)
v, _ = s.Lookup("foo")
if v != "bar" {
t.Fatalf("foo has unexpected value, got %s", v)
}
if !reflect.DeepEqual(s.kvStore, tm) {
t.Fatalf("store expected %+v, got %+v", tm, s.kvStore)
}
require.Equalf(t, "bar", v, "foo has unexpected value, got %s", v)
require.Truef(t, reflect.DeepEqual(s.kvStore, tm), "store expected %+v, got %+v", tm, s.kvStore)
}
7 changes: 3 additions & 4 deletions contrib/raftexample/raft_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
"reflect"
"testing"

"github.com/stretchr/testify/require"

"go.etcd.io/raft/v3/raftpb"
)

Expand Down Expand Up @@ -121,10 +123,7 @@ func TestProcessMessages(t *testing.T) {
}

outputMessages := rn.processMessages(tc.InputMessages)

if !reflect.DeepEqual(outputMessages, tc.ExpectedMessages) {
t.Fatalf("Unexpected messages, expected: %v, got %v", tc.ExpectedMessages, outputMessages)
}
require.Truef(t, reflect.DeepEqual(outputMessages, tc.ExpectedMessages), "Unexpected messages, expected: %v, got %v", tc.ExpectedMessages, outputMessages)
})
}
}
5 changes: 2 additions & 3 deletions contrib/raftexample/raftexample_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,8 @@ func TestPutAndGetKeyValue(t *testing.T) {
require.NoError(t, err)
defer resp.Body.Close()

if gotValue := string(data); wantValue != gotValue {
t.Fatalf("expect %s, got %s", wantValue, gotValue)
}
gotValue := string(data)
require.Equalf(t, wantValue, gotValue, "expect %s, got %s", wantValue, gotValue)
}

// TestAddNewNode tests adding new node to the existing cluster.
Expand Down

0 comments on commit 7f9efcf

Please sign in to comment.