wallet: improve assertError function

This commit is contained in:
vinchent 2024-09-11 11:32:40 +02:00
parent 4be1d0d598
commit 9a2478f947

View File

@ -8,15 +8,18 @@ func TestWallet(t *testing.T) {
got := wallet.Balance()
if got != want {
t.Errorf("got %q want %q", got, want)
t.Errorf("got %q, want %q", got, want)
}
}
assertError := func(t testing.TB, err error) {
assertError := func(t testing.TB, got error, want string) {
t.Helper()
if err == nil {
t.Error("wanted an error but didn't get one")
if got == nil {
t.Fatal("didn't get an error but wanted one")
}
if got.Error() != want {
t.Errorf("got %q, want %q", got, want)
}
}
@ -37,7 +40,7 @@ func TestWallet(t *testing.T) {
wallet := Wallet{balance: startingBalance}
err := wallet.Withdraw(100)
assertError(t, err)
assertError(t, err, "not enough to withdraw")
assertBalance(t, wallet, startingBalance)
})
}