wallet: extract assertError helper function
This commit is contained in:
parent
f6b17eaff3
commit
4be1d0d598
@ -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) {
|
t.Run("deposit", func(t *testing.T) {
|
||||||
wallet := Wallet{}
|
wallet := Wallet{}
|
||||||
wallet.Deposit(10)
|
wallet.Deposit(10)
|
||||||
@ -28,10 +36,8 @@ func TestWallet(t *testing.T) {
|
|||||||
startingBalance := Bitcoin(20)
|
startingBalance := Bitcoin(20)
|
||||||
wallet := Wallet{balance: startingBalance}
|
wallet := Wallet{balance: startingBalance}
|
||||||
err := wallet.Withdraw(100)
|
err := wallet.Withdraw(100)
|
||||||
assertBalance(t, wallet, startingBalance)
|
|
||||||
|
|
||||||
if err == nil {
|
assertError(t, err)
|
||||||
t.Error("wanted an error but didn't get one")
|
assertBalance(t, wallet, startingBalance)
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user