From c9c6a99fe98b16a8f8f210504561873950a5f32d Mon Sep 17 00:00:00 2001 From: Polianin Nikita Date: Thu, 30 May 2024 21:45:45 +0300 Subject: [PATCH] test: trying to set up tests to test application in different databases --- .gitea/workflows/Settings.json | 51 +++++++++++++++++++ .gitea/workflows/database_test.yaml | 77 +++++++++++++++++++++++++++++ 2 files changed, 128 insertions(+) create mode 100644 .gitea/workflows/Settings.json create mode 100644 .gitea/workflows/database_test.yaml diff --git a/.gitea/workflows/Settings.json b/.gitea/workflows/Settings.json new file mode 100644 index 0000000..c1b7848 --- /dev/null +++ b/.gitea/workflows/Settings.json @@ -0,0 +1,51 @@ +{ + "DbSettings": { + "TypeDatabase": 1, + "ConnectionStringSql": "Data Source=database.db3" + }, + "CacheSettings": { + "TypeDatabase": 0, + "ConnectionString": null + }, + "ScheduleSettings": { + "CronUpdateSchedule": "0 */6 * * *", + "StartTerm": "2024-02-05", + "PairPeriod": { + "1": { + "Start": "09:00:00", + "End": "10:30:00" + }, + "2": { + "Start": "10:40:00", + "End": "12:10:00" + }, + "3": { + "Start": "12:40:00", + "End": "14:10:00" + }, + "4": { + "Start": "14:20:00", + "End": "15:50:00" + }, + "5": { + "Start": "16:20:00", + "End": "17:50:00" + }, + "6": { + "Start": "18:00:00", + "End": "19:30:00" + }, + "7": { + "Start": "19:40:00", + "End": "21:10:00" + } + } + }, + "EmailSettings": { + }, + "LogSettings": { + "EnableLogToFile": false, + "LogFilePath": null, + "LogFileName": null + } +} \ No newline at end of file diff --git a/.gitea/workflows/database_test.yaml b/.gitea/workflows/database_test.yaml new file mode 100644 index 0000000..1a1c5d0 --- /dev/null +++ b/.gitea/workflows/database_test.yaml @@ -0,0 +1,77 @@ +name: Test with Different Databases + +on: + pull_request: + push: + branches: + [master, 'release/*'] + +jobs: + test: + strategy: + matrix: + db-provider: [sqlite, mysql, postgresql] + runs-on: ubuntu-latest + + services: + mysql: + image: mysql:latest + env: + MYSQL_ROOT_PASSWORD: root + MYSQL_DATABASE: testdb + options: >- + --health-cmd "mysqladmin ping --silent" + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + - 3306:3306 + + postgres: + image: postgres:latest + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: testdb + options: >- + --health-cmd "pg_isready -U postgres" + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + - 5432:5432 + + steps: + - uses: actions/checkout@v4 + + - name: Set up .NET Core + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 8.0.x + + - name: Restore dependencies + run: dotnet restore + + - name: Build the solution + run: dotnet build --configuration Release + + - name: Install jq + run: sudo apt-get install -y jq + + - name: Modify configuration for SQLite + if: matrix.db-provider == 'sqlite' + run: | + jq '.DbSettings.TypeDatabase = 1 | .DbSettings.ConnectionStringSql = "Data Source=test.db3"' Settings.json > temp.json && mv temp.json Settings.json + + - name: Modify configuration for MySQL + if: matrix.db-provider == 'mysql' + run: | + jq '.DbSettings.TypeDatabase = 0 | .DbSettings.ConnectionStringSql = "Server=127.0.0.1;Port=3306;Database=testdb;Uid=root;Pwd=root;"' Settings.json > temp.json && mv temp.json Settings.json + + - name: Modify configuration for PostgreSQL + if: matrix.db-provider == 'postgresql' + run: | + jq '.DbSettings.TypeDatabase = 2 | .DbSettings.ConnectionStringSql = "Host=127.0.0.1;Port=5432;Database=testdb;Username=postgres;Password=postgres"' Settings.json > temp.json && mv temp.json Settings.json + + - name: Run tests + run: dotnet test --configuration Release --no-build --no-restore --verbosity normal \ No newline at end of file