From 7fd93e877829808bc7479d9805b65e81b3489b54 Mon Sep 17 00:00:00 2001 From: Dan Anglin Date: Sat, 17 Aug 2024 19:15:12 +0100 Subject: [PATCH] ci: add a workflow for tests - Added an action for running mage targets - Added a workflow for running tests - Add our first unit test PR: https://codeflow.dananglin.me.uk/apollo/enbas/pulls/52 --- .forgejo/actions/mage/Dockerfile | 6 +++++ .forgejo/actions/mage/action.yaml | 16 ++++++++++++ .forgejo/workflows/Tests.yaml | 23 +++++++++++++++++ internal/utilities/utilities_test.go | 38 ++++++++++++++++++++++++++++ 4 files changed, 83 insertions(+) create mode 100644 .forgejo/actions/mage/Dockerfile create mode 100644 .forgejo/actions/mage/action.yaml create mode 100644 .forgejo/workflows/Tests.yaml create mode 100644 internal/utilities/utilities_test.go diff --git a/.forgejo/actions/mage/Dockerfile b/.forgejo/actions/mage/Dockerfile new file mode 100644 index 0000000..ac36f20 --- /dev/null +++ b/.forgejo/actions/mage/Dockerfile @@ -0,0 +1,6 @@ +# syntax=docker/dockerfile:1 +FROM golang:1.23.0 + +RUN go install github.com/magefile/mage@v1.15.0 + +ENTRYPOINT ["mage"] diff --git a/.forgejo/actions/mage/action.yaml b/.forgejo/actions/mage/action.yaml new file mode 100644 index 0000000..a2ca49b --- /dev/null +++ b/.forgejo/actions/mage/action.yaml @@ -0,0 +1,16 @@ +--- +name: "Enbas Mage Action" +description: "Runs a mage target in the Enbas project" + +inputs: + target: + description: "The mage target to run" + required: true + +runs: + using: "docker" + image: "Dockerfile" + entrypoint: "mage" + args: + - -v + - ${{ inputs.target }} diff --git a/.forgejo/workflows/Tests.yaml b/.forgejo/workflows/Tests.yaml new file mode 100644 index 0000000..07be59d --- /dev/null +++ b/.forgejo/workflows/Tests.yaml @@ -0,0 +1,23 @@ +--- +name: Tests + +on: + pull_request: + types: + - opened + - synchronize + +jobs: + test: + if: ${{ ! github.event.pull_request.draft }} + runs-on: docker + steps: + - name: Checkout Repository + uses: https://code.forgejo.org/actions/checkout@v4 + - name: Test + uses: ./.forgejo/actions/mage + with: + target: test + env: + ENBAS_TEST_VERBOSE: "1" + ENBAS_TEST_COVER: "1" 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) + } + } +}