hello_test: create an assert function
This commit is contained in:
parent
5e32007c89
commit
f593fb28de
@ -6,16 +6,19 @@ func TestHello(t *testing.T) {
|
|||||||
t.Run("Hello someone", func(t *testing.T) {
|
t.Run("Hello someone", func(t *testing.T) {
|
||||||
got := Hello("Jason")
|
got := Hello("Jason")
|
||||||
exp := "Hello Jason"
|
exp := "Hello Jason"
|
||||||
if got != exp {
|
assertCorrectMsg(t, got, exp)
|
||||||
t.Errorf("got %q expected %q", got, exp)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Hello default", func(t *testing.T) {
|
t.Run("Hello default", func(t *testing.T) {
|
||||||
got := Hello("")
|
got := Hello("")
|
||||||
exp := "Hello world"
|
exp := "Hello world"
|
||||||
if got != exp {
|
assertCorrectMsg(t, got, exp)
|
||||||
t.Errorf("got %q expected %q", got, exp)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func assertCorrectMsg(t testing.TB, got, exp string) {
|
||||||
|
t.Helper()
|
||||||
|
if got != exp {
|
||||||
|
t.Errorf("got %q expected %q", got, exp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user