From ddf99ab706ebb098b707274bff4fd452aa72c5c8 Mon Sep 17 00:00:00 2001 From: Nicola Murino Date: Mon, 22 Jun 2020 20:02:51 +0200 Subject: [PATCH] workflow: execute test cases on MySQL too --- .github/workflows/development.yml | 54 +++++++++++++++++++++++-------- README.md | 2 +- httpd/httpd_test.go | 22 +++++++++---- 3 files changed, 56 insertions(+), 22 deletions(-) diff --git a/.github/workflows/development.yml b/.github/workflows/development.yml index 180b4553..3e715331 100644 --- a/.github/workflows/development.yml +++ b/.github/workflows/development.yml @@ -17,7 +17,7 @@ jobs: version: v1.27 tests-upload-unix: - name: Run tests and upload build artifacts on Linux and macOS + name: Run tests and upload build artifacts runs-on: ${{ matrix.os }} strategy: matrix: @@ -118,16 +118,9 @@ jobs: name: sftpgo-windows path: output - tests-postgresql: - name: Run test cases using PostgreSQL as data provider + tests-postgresql-mysql: + name: Run test cases using PostgreSQL/MySQL data providers runs-on: ubuntu-latest - env: - SFTPGO_DATA_PROVIDER__DRIVER: postgresql - SFTPGO_DATA_PROVIDER__NAME: sftpgo - SFTPGO_DATA_PROVIDER__HOST: localhost - SFTPGO_DATA_PROVIDER__PORT: 5432 - SFTPGO_DATA_PROVIDER__USERNAME: postgres - SFTPGO_DATA_PROVIDER__PASSWORD: postgres services: postgres: @@ -143,6 +136,21 @@ jobs: ports: - 5432:5432 + mariadb: + image: mariadb:latest + env: + MYSQL_ROOT_PASSWORD: mysql + MYSQL_DATABASE: sftpgo + MYSQL_USER: sftpgo + MYSQL_PASSWORD: sftpgo + options: >- + --health-cmd "mysqladmin status -h 127.0.0.1 -P 3306 -u root -p$MYSQL_ROOT_PASSWORD" + --health-interval 10s + --health-timeout 5s + --health-retries 6 + ports: + - 3307:3306 + steps: - uses: actions/checkout@v2 @@ -154,8 +162,26 @@ jobs: - name: Build run: go build -i -ldflags "-s -w -X github.com/drakkan/sftpgo/version.commit=`git describe --always --dirty` -X github.com/drakkan/sftpgo/version.date=`date -u +%FT%TZ`" -o sftpgo - - name: Initialize data provider - run: ./sftpgo initprovider - - name: Run tests using PostgreSQL provider - run: go test -v ./... -covermode=atomic + run: | + ./sftpgo initprovider + go test -v ./... -covermode=atomic + env: + SFTPGO_DATA_PROVIDER__DRIVER: postgresql + SFTPGO_DATA_PROVIDER__NAME: sftpgo + SFTPGO_DATA_PROVIDER__HOST: localhost + SFTPGO_DATA_PROVIDER__PORT: 5432 + SFTPGO_DATA_PROVIDER__USERNAME: postgres + SFTPGO_DATA_PROVIDER__PASSWORD: postgres + + - name: Run tests using MySQL provider + run: | + ./sftpgo initprovider + go test -v ./... -covermode=atomic + env: + SFTPGO_DATA_PROVIDER__DRIVER: mysql + SFTPGO_DATA_PROVIDER__NAME: sftpgo + SFTPGO_DATA_PROVIDER__HOST: localhost + SFTPGO_DATA_PROVIDER__PORT: 3307 + SFTPGO_DATA_PROVIDER__USERNAME: sftpgo + SFTPGO_DATA_PROVIDER__PASSWORD: sftpgo diff --git a/README.md b/README.md index 233d77e5..d405e798 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ Some Linux distro packages are available: - [sftpgo-bin](https://aur.archlinux.org/packages/sftpgo-bin/). This package follows stable releases downloading the prebuilt linux binary from GitHub. It does not require `git`, `gcc` and `go` to build. - [sftpgo-git](https://aur.archlinux.org/packages/sftpgo-git/). This package builds and installs the latest git master. It requires `git`, `gcc` and `go` to build. -You can easily test new features selecting a commit from the [Actions](./actions) page and downloading the matching build artifacts for Linux, macOS or Windows. GitHub stores artifacts for 90 days. +You can easily test new features selecting a commit from the [Actions](https://github.com/drakkan/sftpgo/actions) page and downloading the matching build artifacts for Linux, macOS or Windows. GitHub stores artifacts for 90 days. Alternately, you can [build from source](./docs/build-from-source.md). diff --git a/httpd/httpd_test.go b/httpd/httpd_test.go index 7b433d1b..6f4d09e7 100644 --- a/httpd/httpd_test.go +++ b/httpd/httpd_test.go @@ -1091,6 +1091,16 @@ func TestStartQuotaScan(t *testing.T) { assert.NoError(t, err) _, err = httpd.StartFolderQuotaScan(folder, http.StatusCreated) assert.NoError(t, err) + for { + quotaScan, _, err := httpd.GetFoldersQuotaScans(http.StatusOK) + if !assert.NoError(t, err, "Error getting active scans") { + break + } + if len(quotaScan) == 0 { + break + } + time.Sleep(100 * time.Millisecond) + } _, err = httpd.RemoveFolder(folder, http.StatusOK) assert.NoError(t, err) } @@ -1875,14 +1885,13 @@ func TestStartQuotaScanMock(t *testing.T) { rr = executeRequest(req) checkResponseCode(t, http.StatusCreated, rr.Code) - var scans []sftpd.ActiveQuotaScan for { + var scans []sftpd.ActiveQuotaScan req, _ = http.NewRequest(http.MethodGet, quotaScanPath, nil) rr = executeRequest(req) checkResponseCode(t, http.StatusOK, rr.Code) err = render.DecodeJSON(rr.Body, &scans) - if !assert.NoError(t, err) { - assert.Fail(t, err.Error(), "Error get active scans") + if !assert.NoError(t, err, "Error getting active scans") { break } if len(scans) == 0 { @@ -1899,14 +1908,14 @@ func TestStartQuotaScanMock(t *testing.T) { rr = executeRequest(req) checkResponseCode(t, http.StatusCreated, rr.Code) - scans = nil for { + var scans []sftpd.ActiveQuotaScan req, _ = http.NewRequest(http.MethodGet, quotaScanPath, nil) rr = executeRequest(req) checkResponseCode(t, http.StatusOK, rr.Code) err = render.DecodeJSON(rr.Body, &scans) if !assert.NoError(t, err) { - assert.Fail(t, err.Error(), "Error get active scans") + assert.Fail(t, err.Error(), "Error getting active scans") break } if len(scans) == 0 { @@ -2017,8 +2026,7 @@ func TestStartFolderQuotaScanMock(t *testing.T) { rr = executeRequest(req) checkResponseCode(t, http.StatusOK, rr.Code) err = render.DecodeJSON(rr.Body, &scans) - if !assert.NoError(t, err) { - assert.Fail(t, err.Error(), "Error get active folders scans") + if !assert.NoError(t, err, "Error getting active folders scans") { break } if len(scans) == 0 {