Skip to content

Commit 4f09a23

Browse files
committed
testing that no error is returned
1 parent 2015d60 commit 4f09a23

File tree

1 file changed

+30
-22
lines changed

1 file changed

+30
-22
lines changed

pointers/wallet_test.go

+30-22
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,17 @@ import (
66

77
func TestWallet(t *testing.T) {
88

9-
assertBalance := func(t *testing.T, wallet Wallet, want Bitcoin) {
10-
t.Helper()
11-
got := wallet.Balance()
12-
13-
if got != want {
14-
t.Errorf("got %s want %s", got, want)
15-
}
16-
}
17-
18-
assertError := func(t *testing.T, got error, want error) {
19-
t.Helper()
20-
if got == nil {
21-
t.Fatal("wanted an error but didn't get one")
22-
}
23-
24-
if got != want {
25-
t.Errorf("got %q, want %q", got, want)
26-
}
27-
}
28-
299
t.Run("Deposit", func(t *testing.T) {
3010
wallet := Wallet{}
3111
wallet.Deposit(Bitcoin(10))
3212
assertBalance(t, wallet, Bitcoin(10))
3313
})
3414

35-
t.Run("Withdraw", func(t *testing.T) {
15+
t.Run("Withdraw with funds", func(t *testing.T) {
3616
wallet := Wallet{balance: Bitcoin(20)}
37-
wallet.Withdraw(Bitcoin(10))
17+
err := wallet.Withdraw(Bitcoin(10))
3818
assertBalance(t, wallet, Bitcoin(10))
19+
assertNoError(t, err)
3920
})
4021

4122
t.Run("Withdraw insufficient funds", func(t *testing.T) {
@@ -46,3 +27,30 @@ func TestWallet(t *testing.T) {
4627
assertError(t, err, ErrInsufficientFunds)
4728
})
4829
}
30+
31+
func assertBalance(t *testing.T, wallet Wallet, want Bitcoin) {
32+
t.Helper()
33+
got := wallet.Balance()
34+
35+
if got != want {
36+
t.Errorf("got %s want %s", got, want)
37+
}
38+
}
39+
40+
func assertNoError(t *testing.T, got error) {
41+
t.Helper()
42+
if got != nil {
43+
t.Fatal("got an error but didn't want one")
44+
}
45+
}
46+
47+
func assertError(t *testing.T, got error, want error) {
48+
t.Helper()
49+
if got == nil {
50+
t.Fatal("wanted an error but didn't get one")
51+
}
52+
53+
if got != want {
54+
t.Errorf("got %q, want %q", got, want)
55+
}
56+
}

0 commit comments

Comments
 (0)