Refactor test assertions
This commit is contained in:
@@ -6,17 +6,18 @@ func TestHello(t *testing.T) {
|
|||||||
t.Run("saying hello to people", func(t *testing.T) {
|
t.Run("saying hello to people", func(t *testing.T) {
|
||||||
got := Hello("Hoborg")
|
got := Hello("Hoborg")
|
||||||
want := "Hello, Hoborg"
|
want := "Hello, Hoborg"
|
||||||
|
assertMessage(t, got, want)
|
||||||
if got != want {
|
|
||||||
t.Errorf("got %q want %q", got, want)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
t.Run("say 'Hello, World' when an empty string is given", func(t *testing.T) {
|
t.Run("say 'Hello, World' when an empty string is given", func(t *testing.T) {
|
||||||
got := Hello("")
|
got := Hello("")
|
||||||
want := "Hello, World"
|
want := "Hello, Worldi"
|
||||||
|
assertMessage(t, got, want)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func assertMessage(t testing.TB, got, want string) {
|
||||||
|
t.Helper()
|
||||||
if got != want {
|
if got != want {
|
||||||
t.Errorf("got %q want %q", got, want)
|
t.Errorf("got %q want %q", got, want)
|
||||||
}
|
}
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user