Skip to content

Commit 815d3f6

Browse files
committed
specific error message
1 parent facdfe6 commit 815d3f6

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

pointers/wallet.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func (w *Wallet) Balance() Bitcoin {
2626

2727
func (w *Wallet) Withdraw(amount Bitcoin) error {
2828
if amount > w.balance {
29-
return errors.New("oh no")
29+
return errors.New("cannot withdraw, insufficient funds")
3030
}
3131
w.balance -= amount
3232
return nil

pointers/wallet_test.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,14 @@ func TestWallet(t *testing.T) {
1515
}
1616
}
1717

18-
assertError := func(t *testing.T, err error) {
18+
assertError := func(t *testing.T, got error, want string) {
1919
t.Helper()
20-
if err == nil {
21-
t.Error("wanted an error but didn't get one")
20+
if got == nil {
21+
t.Fatal("wanted an error but didn't get one")
22+
}
23+
24+
if got.Error() != want {
25+
t.Errorf("got %q, want %q", got, want)
2226
}
2327
}
2428

@@ -39,6 +43,6 @@ func TestWallet(t *testing.T) {
3943
err := wallet.Withdraw(Bitcoin(100))
4044

4145
assertBalance(t, wallet, Bitcoin(20))
42-
assertError(t, err)
46+
assertError(t, err, "cannot withdraw, insufficient funds")
4347
})
4448
}

0 commit comments

Comments
 (0)