diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..8f71b3d --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,51 @@ +name: Run Tests + +on: + push: + branches: + - main + pull_request: + branches: + - main +env: + AWS_REGION: eu-west-1 + AWS_DEFAULT_REGION: eu-west-1 + AWS_ACCESS_KEY_ID: DUMMYIDEXAMPLE + AWS_SECRET_ACCESS_KEY: DUMMYEXAMPLEKEY + AWS_SESSION_TOKEN: dummy + +jobs: + test: + runs-on: ubuntu-latest + services: + dynamodb: + image: amazon/dynamodb-local + ports: + - 8000:8000 + steps: + - name: Check out repository + uses: actions/checkout@v2 + - name: Install Task + uses: arduino/setup-task@v2 + with: + version: 3.x + repo-token: ${{ secrets.GITHUB_TOKEN }} + - name: Create DynamoDB table + run: | + ./docker/wait-for-db.sh + aws dynamodb create-table \ + --region eu-west-1 \ + --table-name clients \ + --attribute-definitions AttributeName=clientId,AttributeType=S \ + --key-schema AttributeName=clientId,KeyType=HASH \ + --provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5 \ + --endpoint-url http://localhost:8000 \ + --no-cli-pager + - name: Set up gotestfmt + uses: gotesttools/gotestfmt-action@v2 + with: + token: ${{ secrets.GITHUB_TOKEN }} + - name: Run tests + run: | + set -euo pipefail + go test -json -v ./... 2>&1 | tee /tmp/gotest.log | gotestfmt diff --git a/Taskfile.yaml b/Taskfile.yaml index fbb5bf5..7290877 100644 --- a/Taskfile.yaml +++ b/Taskfile.yaml @@ -6,5 +6,4 @@ tasks: cmds: [go build -o build/server/idp-server cmd/server/main.go] test: desc: test project - cmds: [go test ./...] - + cmds: [go test -v ./...] diff --git a/docker/wait-for-db.sh b/docker/wait-for-db.sh new file mode 100755 index 0000000..279c9fd --- /dev/null +++ b/docker/wait-for-db.sh @@ -0,0 +1,10 @@ +#!/bin/bash +export AWS_ACCESS_KEY_ID="DUMMYIDEXAMPLE" +export AWS_SECRET_ACCESS_KEY="DUMMYEXAMPLEKEY" +export AWS_SESSION_TOKEN="dummy" +until aws --region us-east-1 --endpoint-url=http://localhost:8000 dynamodb list-tables; do + >&2 echo "DynamoDB is unavailable - sleeping" + sleep 1 +done + +echo "DynamoDB is available" \ No newline at end of file