From 0f6aa981d2b1c46cf75927e5f4d51a0fbfa199f4 Mon Sep 17 00:00:00 2001 From: Nicolas Carlier Date: Thu, 4 Jan 2024 07:29:12 +0000 Subject: [PATCH] chore(): improve test lib and fix typos --- pkg/api/test/helper_test.go | 8 ++++---- pkg/assert/assert.go | 12 ++++++------ pkg/hook/job.go | 4 ++-- pkg/notification/http/http_notifier.go | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/pkg/api/test/helper_test.go b/pkg/api/test/helper_test.go index 55a26f5..4b2339d 100644 --- a/pkg/api/test/helper_test.go +++ b/pkg/api/test/helper_test.go @@ -15,8 +15,8 @@ func TestQueryParamsToShellVars(t *testing.T) { "list": []string{"foo", "bar"}, } values := api.HTTPParamsToShellVars(tc) - assert.ContainsStr(t, "string=foo", values, "") - assert.ContainsStr(t, "list=foo,bar", values, "") + assert.Contains(t, "string=foo", values, "") + assert.Contains(t, "list=foo,bar", values, "") } func TestHTTPHeadersToShellVars(t *testing.T) { @@ -25,6 +25,6 @@ func TestHTTPHeadersToShellVars(t *testing.T) { "X-Foo-Bar": []string{"foo", "bar"}, } values := api.HTTPParamsToShellVars(tc) - assert.ContainsStr(t, "content_type=text/plain", values, "") - assert.ContainsStr(t, "x_foo_bar=foo,bar", values, "") + assert.Contains(t, "content_type=text/plain", values, "") + assert.Contains(t, "x_foo_bar=foo,bar", values, "") } diff --git a/pkg/assert/assert.go b/pkg/assert/assert.go index 1edab0b..a7f667a 100644 --- a/pkg/assert/assert.go +++ b/pkg/assert/assert.go @@ -25,27 +25,27 @@ func NotNil(t *testing.T, actual interface{}, message string) { } // Equal assert that an object is equal to an expected value -func Equal(t *testing.T, expected, actual interface{}, message string) { +func Equal[K comparable](t *testing.T, expected, actual K, message string) { if message == "" { message = "Equal assertion failed" } if actual != expected { - t.Fatalf("%s - expected: %s, actual: %s", message, expected, actual) + t.Fatalf("%s - expected: %v, actual: %v", message, expected, actual) } } // NotEqual assert that an object is not equal to an expected value -func NotEqual(t *testing.T, expected, actual interface{}, message string) { +func NotEqual[K comparable](t *testing.T, expected, actual K, message string) { if message == "" { message = "Not equal assertion failed" } if actual == expected { - t.Fatalf("%s - unexpected: %s, actual: %s", message, expected, actual) + t.Fatalf("%s - unexpected: %v, actual: %v", message, expected, actual) } } // ContainsStr assert that an array contains an expected value -func ContainsStr(t *testing.T, expected string, array []string, message string) { +func Contains[K comparable](t *testing.T, expected K, array []K, message string) { if message == "" { message = "Array don't contains expected value" } @@ -54,7 +54,7 @@ func ContainsStr(t *testing.T, expected string, array []string, message string) return } } - t.Fatalf("%s - array: %v, expected value: %s", message, array, expected) + t.Fatalf("%s - array: %v, expected value: %v", message, array, expected) } // True assert that an expression is true diff --git a/pkg/hook/job.go b/pkg/hook/job.go index 10b39e0..7aa50bc 100644 --- a/pkg/hook/job.go +++ b/pkg/hook/job.go @@ -94,7 +94,7 @@ func (job *Job) Terminate(err error) error { "id", job.ID(), "status", "error", "err", err, - "took", time.Since(job.start).Microseconds(), + "took", time.Since(job.start).Milliseconds(), ) return err } @@ -103,7 +103,7 @@ func (job *Job) Terminate(err error) error { "hook", job.Name(), "id", job.ID(), "status", "success", - "took", time.Since(job.start).Microseconds(), + "took", time.Since(job.start).Milliseconds(), ) return nil } diff --git a/pkg/notification/http/http_notifier.go b/pkg/notification/http/http_notifier.go index a46bdab..303114c 100644 --- a/pkg/notification/http/http_notifier.go +++ b/pkg/notification/http/http_notifier.go @@ -27,7 +27,7 @@ type httpNotifier struct { } func newHTTPNotifier(uri *url.URL) (notification.Notifier, error) { - slog.Info("using HTTP notification system ", "üri", uri.Opaque) + slog.Info("using HTTP notification system ", "uri", uri.Opaque) return &httpNotifier{ URL: uri, PrefixFilter: helper.GetValueOrAlt(uri.Query(), "prefix", "notify:"),