From 3cae1bd3d75d00d3fc2741f4e7af5a2af9c7f053 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krejczinger=20=C3=81rp=C3=A1d?= Date: Sun, 15 Mar 2026 22:41:15 +0100 Subject: [PATCH] Refactor test assertions --- hello_test.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/hello_test.go b/hello_test.go index c8a873a..4836cf6 100644 --- a/hello_test.go +++ b/hello_test.go @@ -6,17 +6,18 @@ func TestHello(t *testing.T) { t.Run("saying hello to people", func(t *testing.T) { got := Hello("Hoborg") want := "Hello, Hoborg" - - if got != want { - t.Errorf("got %q want %q", got, want) - } + assertMessage(t, got, want) }) t.Run("say 'Hello, World' when an empty string is given", func(t *testing.T) { got := Hello("") - want := "Hello, World" - - if got != want { - t.Errorf("got %q want %q", got, want) - } + want := "Hello, Worldi" + assertMessage(t, got, want) }) } + +func assertMessage(t testing.TB, got, want string) { + t.Helper() + if got != want { + t.Errorf("got %q want %q", got, want) + } +}