wallet: extract assertError helper function
This commit is contained in:
		@ -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)
 | 
			
		||||
	})
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user