wallet: improve assertError function
This commit is contained in:
parent
4be1d0d598
commit
9a2478f947
@ -8,15 +8,18 @@ func TestWallet(t *testing.T) {
|
|||||||
|
|
||||||
got := wallet.Balance()
|
got := wallet.Balance()
|
||||||
if got != want {
|
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()
|
t.Helper()
|
||||||
|
|
||||||
if err == nil {
|
if got == nil {
|
||||||
t.Error("wanted an error but didn't get one")
|
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}
|
wallet := Wallet{balance: startingBalance}
|
||||||
err := wallet.Withdraw(100)
|
err := wallet.Withdraw(100)
|
||||||
|
|
||||||
assertError(t, err)
|
assertError(t, err, "not enough to withdraw")
|
||||||
assertBalance(t, wallet, startingBalance)
|
assertBalance(t, wallet, startingBalance)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user