hello_test: create an assert function

This commit is contained in:
vinchent 2024-09-10 11:20:52 +02:00
parent 5e32007c89
commit f593fb28de

View File

@ -6,16 +6,19 @@ func TestHello(t *testing.T) {
t.Run("Hello someone", func(t *testing.T) {
got := Hello("Jason")
exp := "Hello Jason"
if got != exp {
t.Errorf("got %q expected %q", got, exp)
}
assertCorrectMsg(t, got, exp)
})
t.Run("Hello default", func(t *testing.T) {
got := Hello("")
exp := "Hello world"
if got != exp {
t.Errorf("got %q expected %q", got, exp)
}
assertCorrectMsg(t, got, exp)
})
}
func assertCorrectMsg(t testing.TB, got, exp string) {
t.Helper()
if got != exp {
t.Errorf("got %q expected %q", got, exp)
}
}