From cdcca4cff65c22bfa285be530a01bf94300b9875 Mon Sep 17 00:00:00 2001 From: Dan Anglin Date: Sat, 17 Aug 2024 17:40:17 +0100 Subject: [PATCH] add our first unit test --- .forgejo/actions/tests/action.yaml | 3 +-- internal/utilities/utilities_test.go | 38 ++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 internal/utilities/utilities_test.go diff --git a/.forgejo/actions/tests/action.yaml b/.forgejo/actions/tests/action.yaml index 020e42f..f89c4f5 100644 --- a/.forgejo/actions/tests/action.yaml +++ b/.forgejo/actions/tests/action.yaml @@ -1,11 +1,10 @@ --- name: "Testing" -description: "Performs unit and lint tests for Enbas with mage" +description: "Performs tests for Enbas with mage" runs: using: "docker" image: "Dockerfile" env: ENBAS_TEST_VERBOSE: "1" ENBAS_TEST_COVER: "1" - pre-entrypoint: "go version" entrypoint: "mage -v test" diff --git a/internal/utilities/utilities_test.go b/internal/utilities/utilities_test.go new file mode 100644 index 0000000..b947314 --- /dev/null +++ b/internal/utilities/utilities_test.go @@ -0,0 +1,38 @@ +package utilities_test + +import ( + "testing" + + "codeflow.dananglin.me.uk/apollo/enbas/internal/utilities" +) + +func TestGetFQDN(t *testing.T) { + t.Parallel() + + cases := []struct { + instance string + want string + }{ + { + instance: "https://gts.red-crow.private", + want: "gts.red-crow.private", + }, + { + instance: "http://gotosocial.yellow-desert.social", + want: "gotosocial.yellow-desert.social", + }, + { + instance: "fedi.blue-mammoth.party", + want: "fedi.blue-mammoth.party", + }, + } + + for _, c := range cases { + got := utilities.GetFQDN(c.instance) + if c.want != got { + t.Errorf("Unexpected result: want %s, got %s", c.want, got) + } else { + t.Logf("Expected result: got %s", got) + } + } +}