ci: add a workflow for tests
Some checks failed
Tests / test (pull_request) Successful in 15s
REUSE Compliance Check / check (push) Failing after 13s

- Added an action for running mage targets
- Added a workflow for running tests
- Add our first unit test

PR: #52
This commit is contained in:
Dan Anglin 2024-08-17 19:15:12 +01:00
parent 009515ddb4
commit 7fd93e8778
Signed by: dananglin
GPG key ID: 0C1D44CFBEE68638
4 changed files with 83 additions and 0 deletions

View file

@ -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"]

View file

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

View file

@ -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"

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