From 4be1d0d59829f5f8018b8bece0253636788875a6 Mon Sep 17 00:00:00 2001 From: vinchent Date: Wed, 11 Sep 2024 11:28:45 +0200 Subject: [PATCH] wallet: extract assertError helper function --- wallet/wallet_test.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/wallet/wallet_test.go b/wallet/wallet_test.go index 2e26f58..cc66fa6 100644 --- a/wallet/wallet_test.go +++ b/wallet/wallet_test.go @@ -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) }) }