From 98290b9ed7bef61d448a1c04a3dc2e30e075e12d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julio=20L=C3=B3pez?= <1953782+julio-lopez@users.noreply.github.com> Date: Fri, 18 Oct 2024 16:12:18 -0700 Subject: [PATCH] refactor: make toJSON a test helper (#4184) --- repo/maintenance/maintenance_schedule_test.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/repo/maintenance/maintenance_schedule_test.go b/repo/maintenance/maintenance_schedule_test.go index cac0bf91f0c..fbf7badd3f0 100644 --- a/repo/maintenance/maintenance_schedule_test.go +++ b/repo/maintenance/maintenance_schedule_test.go @@ -34,7 +34,7 @@ func (s *formatSpecificTestSuite) TestMaintenanceSchedule(t *testing.T) { s2, err := maintenance.GetSchedule(ctx, env.RepositoryWriter) require.NoError(t, err, "unable to get schedule") - got, want := toJSON(s2), toJSON(sch) + got, want := toJSON(t, s2), toJSON(t, sch) require.Equal(t, want, got, "unexpected schedule") } @@ -116,7 +116,12 @@ func TestTimeToAttemptNextMaintenance(t *testing.T) { } } -func toJSON(v interface{}) string { - b, _ := json.MarshalIndent(v, "", " ") +func toJSON(t *testing.T, v interface{}) string { + t.Helper() + + b, err := json.MarshalIndent(v, "", " ") + + require.NoError(t, err, "json marshal") + return string(b) }