From 172fff0edbe25a4696f028e06997b8bd741a80eb Mon Sep 17 00:00:00 2001 From: Leon Richardt Date: Sun, 21 Aug 2022 20:30:07 +0200 Subject: [PATCH] ref!: use generics to simply testing logic Notably, this requires us to bump the Go version in order to use generics. We now use Go 1.19. --- config_test.go | 18 ++++++------------ go.mod | 2 +- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/config_test.go b/config_test.go index 5a0ef9b..d41f7f9 100644 --- a/config_test.go +++ b/config_test.go @@ -4,15 +4,9 @@ import ( "testing" ) -func assertEqualInt(have int, want int, t *testing.T) { +func assertEqual[S comparable](have S, want S, t *testing.T) { if have != want { - t.Errorf("have: %d, want: %d\n", have, want) - } -} - -func assertEqualString(have string, want string, t *testing.T) { - if have != want { - t.Errorf("have: %s, want: %s\n", have, want) + t.Error("have:", have, ", want:", want, "\n") } } @@ -22,8 +16,8 @@ func TestConfigFromFile(t *testing.T) { panic(err) } - assertEqualInt(config.Port, 4711, t) - assertEqualString(config.LinkPrefix, "https://jaf.example.com/", t) - assertEqualString(config.FileDir, "/var/www/jaf/", t) - assertEqualInt(config.LinkLength, 5, t) + assertEqual(config.Port, 4711, t) + assertEqual(config.LinkPrefix, "https://jaf.example.com/", t) + assertEqual(config.FileDir, "/var/www/jaf/", t) + assertEqual(config.LinkLength, 5, t) } diff --git a/go.mod b/go.mod index 7217a9c..45e0214 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ module github.com/leon-richardt/jaf -go 1.16 +go 1.19