From 5ca4bd43bad317093d49f8e4ded6c70ed95132f4 Mon Sep 17 00:00:00 2001 From: viktorstrate Date: Fri, 23 Apr 2021 20:52:55 +0200 Subject: [PATCH] Setup databases for github actions tests --- .github/mysql.testing.env | 2 ++ .github/postgres.testing.env | 2 ++ .github/sqlite.testing.env | 2 ++ .github/workflows/tests.yml | 51 +++++++++++++++++++++++++++++++++--- 4 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 .github/mysql.testing.env create mode 100644 .github/postgres.testing.env create mode 100644 .github/sqlite.testing.env diff --git a/.github/mysql.testing.env b/.github/mysql.testing.env new file mode 100644 index 00000000..4b66e67e --- /dev/null +++ b/.github/mysql.testing.env @@ -0,0 +1,2 @@ +PHOTOVIEW_DATABASE_DRIVER=mysql +PHOTOVIEW_MYSQL_URL='photoview:photosecret@tcp(mariadb)/photoview_test' diff --git a/.github/postgres.testing.env b/.github/postgres.testing.env new file mode 100644 index 00000000..f8bdbe23 --- /dev/null +++ b/.github/postgres.testing.env @@ -0,0 +1,2 @@ +PHOTOVIEW_DATABASE_DRIVER=postgres +PHOTOVIEW_POSTGRES_URL='photoview:photosecret@tcp(postgres)/photoview_test' diff --git a/.github/sqlite.testing.env b/.github/sqlite.testing.env new file mode 100644 index 00000000..a24802ed --- /dev/null +++ b/.github/sqlite.testing.env @@ -0,0 +1,2 @@ +PHOTOVIEW_DATABASE_DRIVER=sqlite +PHOTOVIEW_SQLITE_PATH=photoview_test.db diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 58528670..83edc15f 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -11,15 +11,44 @@ jobs: name: Test API runs-on: ubuntu-20.04 + strategy: + matrix: + database: ['mysql', 'postgres', 'sqlite'] + + services: + mariadb: + image: mariadb:10.5 + env: + MYSQL_DATABASE: photoview_test + MYSQL_USER: photoview + MYSQL_PASSWORD: photosecret + options: >- + --health-cmd="mysqladmin ping" + --health-interval=10s + --health-timeout=5s + --health-retries=5 + + postgres: + images: postgres:13.2 + env: + POSTGRES_USER: photoview + POSTGRES_PASSWORD: photosecret + POSTGRES_DB: photoview_test + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + defaults: run: working-directory: api steps: - - name: Set up Go 1.x + - name: Set up Go uses: actions/setup-go@v2 with: - go-version: ^1.13 + go-version: ^1.16 id: go - name: Check out code into the Go module directory @@ -43,8 +72,24 @@ jobs: - name: Build run: go build -v . + - name: Configure MySQL + if: ${{ matrix.database == 'mysql' }} + run: | + cp ../.github/mysql.testing.env testing.env + + - name: Configure Postgres + if: ${{ matrix.database == 'postgres' }} + run: | + cp ../.github/postgres.testing.env testing.env + + - name: Configure Sqlite + if: ${{ matrix.database == 'sqlite' }} + run: | + touch photoview_test.db + cp ../.github/sqlite.testing.env testing.env + - name: Test - run: go test -v ./... + run: go test ./... -v -database -filesystem -p 1 test-ui: name: Test UI