wallet: extract assertError helper function

This commit is contained in:
vinchent 2024-09-11 11:28:45 +02:00
parent f6b17eaff3
commit 4be1d0d598

View File

@ -12,6 +12,14 @@ func TestWallet(t *testing.T) {
}
}
assertError := func(t testing.TB, err error) {
t.Helper()
if err == nil {
t.Error("wanted an error but didn't get one")
}
}
t.Run("deposit", func(t *testing.T) {
wallet := Wallet{}
wallet.Deposit(10)
@ -28,10 +36,8 @@ func TestWallet(t *testing.T) {
startingBalance := Bitcoin(20)
wallet := Wallet{balance: startingBalance}
err := wallet.Withdraw(100)
assertBalance(t, wallet, startingBalance)
if err == nil {
t.Error("wanted an error but didn't get one")
}
assertError(t, err)
assertBalance(t, wallet, startingBalance)
})
}