add our first unit test
All checks were successful
Tests / test (pull_request) Successful in 22s

This commit is contained in:
Dan Anglin 2024-08-17 17:40:17 +01:00
parent 08981319e1
commit cdcca4cff6
Signed by: dananglin
GPG key ID: 0C1D44CFBEE68638
2 changed files with 39 additions and 2 deletions

View file

@ -1,11 +1,10 @@
--- ---
name: "Testing" name: "Testing"
description: "Performs unit and lint tests for Enbas with mage" description: "Performs tests for Enbas with mage"
runs: runs:
using: "docker" using: "docker"
image: "Dockerfile" image: "Dockerfile"
env: env:
ENBAS_TEST_VERBOSE: "1" ENBAS_TEST_VERBOSE: "1"
ENBAS_TEST_COVER: "1" ENBAS_TEST_COVER: "1"
pre-entrypoint: "go version"
entrypoint: "mage -v test" entrypoint: "mage -v test"

View file

@ -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)
}
}
}