Skip to content

Commit 678a293

Browse files
committed
use fatalf
1 parent 2c6f4df commit 678a293

File tree

4 files changed

+5
-6
lines changed

4 files changed

+5
-6
lines changed

demo_01/main_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package main
22

33
import (
4-
"fmt"
54
"testing"
65
)
76

@@ -10,6 +9,6 @@ func TestAdd(t *testing.T) {
109
actual := AddTwoNumbers(2, 4)
1110

1211
if actual != expected {
13-
t.Fatal(fmt.Sprintf("expected %v, got %v", expected, actual))
12+
t.Fatalf("expected %v, got %v", expected, actual)
1413
}
1514
}

demo_02/bank.go

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ func (ca ChequingAccount) Withdraw(amount int, tm TransactionManger) error {
7070
if err != nil {
7171
return errors.New("failed to get balance for update")
7272
}
73+
// not thread safe
7374
if amount > balance {
7475
return errors.New("amount greated than balance")
7576
}

demo_02/bank_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package main
22

33
import (
44
"errors"
5-
"fmt"
65
"testing"
76
)
87

@@ -66,7 +65,7 @@ func TestReadBalance(t *testing.T) {
6665
}
6766

6867
if balance != 100 {
69-
t.Fatal(fmt.Sprintf("expected balance 100, got %v", balance))
68+
t.Fatalf("expected balance 100, got %v", balance)
7069
}
7170
}
7271

@@ -77,7 +76,7 @@ func TestDeposit(t *testing.T) {
7776
err := account.Deposit(100, tm)
7877

7978
if err != nil {
80-
t.Fatal(fmt.Sprintf("expected no error on deposit, got %v", err))
79+
t.Fatalf("expected no error on deposit, got %v", err)
8180
}
8281
}
8382

demo_04/bank_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func TestReadBalance(t *testing.T) {
3939
}
4040

4141
if balance < 100 {
42-
t.Fatal(fmt.Sprintf("expected balance 100, got %v", balance))
42+
t.Fatalf("expected balance 100, got %v", balance)
4343
}
4444
}
4545

0 commit comments

Comments
 (0)