From e1a5550a275cbf46aca66368548cb4ebf3ea2ae4 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Sat, 22 Nov 2025 22:10:46 +0100 Subject: [PATCH] test: use generics in Equal function signature This simplifies comparing a typed value against nil. Previously it was necessary to case nil into the proper type. --- internal/backend/location/location_test.go | 2 +- internal/backend/util/defaults_test.go | 2 +- internal/test/helpers.go | 2 +- internal/ui/termstatus/status_test.go | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/backend/location/location_test.go b/internal/backend/location/location_test.go index fe550a586..ccb1db6ae 100644 --- a/internal/backend/location/location_test.go +++ b/internal/backend/location/location_test.go @@ -29,7 +29,7 @@ func TestParse(t *testing.T) { u, err := location.Parse(registry, path) test.OK(t, err) test.Equals(t, "local", u.Scheme) - test.Equals(t, &testConfig{loc: path}, u.Config) + test.Equals(t, any(&testConfig{loc: path}), u.Config) } func TestParseFallback(t *testing.T) { diff --git a/internal/backend/util/defaults_test.go b/internal/backend/util/defaults_test.go index b0efc336f..6cdd058f8 100644 --- a/internal/backend/util/defaults_test.go +++ b/internal/backend/util/defaults_test.go @@ -37,7 +37,7 @@ func TestDefaultLoad(t *testing.T) { return rd, nil }, func(ird io.Reader) error { - rtest.Equals(t, rd, ird) + rtest.Equals(t, io.Reader(rd), ird) return nil }) rtest.OK(t, err) diff --git a/internal/test/helpers.go b/internal/test/helpers.go index 3387d36df..e3fded66e 100644 --- a/internal/test/helpers.go +++ b/internal/test/helpers.go @@ -48,7 +48,7 @@ func OKs(tb testing.TB, errs []error) { // Equals fails the test if exp is not equal to act. // msg is optional message to be printed, first param being format string and rest being arguments. -func Equals(tb testing.TB, exp, act interface{}, msgs ...string) { +func Equals[T any](tb testing.TB, exp, act T, msgs ...string) { tb.Helper() if !reflect.DeepEqual(exp, act) { var msgString string diff --git a/internal/ui/termstatus/status_test.go b/internal/ui/termstatus/status_test.go index f65bb096f..b19e00557 100644 --- a/internal/ui/termstatus/status_test.go +++ b/internal/ui/termstatus/status_test.go @@ -128,7 +128,7 @@ func TestRawInputOutput(t *testing.T) { defer cancel() rtest.Equals(t, input, term.InputRaw()) rtest.Equals(t, false, term.InputIsTerminal()) - rtest.Equals(t, &output, term.OutputRaw()) + rtest.Equals(t, io.Writer(&output), term.OutputRaw()) rtest.Equals(t, false, term.OutputIsTerminal()) rtest.Equals(t, false, term.CanUpdateStatus()) }