Files
sql-server-samples/samples/containers/unit-testing/tsqlt-docker/.github/workflows/automated-tests.yml
T

100 lines
4.6 KiB
YAML

# This workflow installs tSQLt and runs the test units
name: tSQLt installer and unit testing runner
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the "master" branch
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
jobs:
windows-auth-tsqlt:
name: Installting tSQLt with SQL Auth
# The type of runner that the job will run on
runs-on: ubuntu-latest
services:
sqlserver:
image: chriseaton/adventureworks:latest
ports:
- 1433:1433
env:
ACCEPT_EULA: Y
SA_PASSWORD: 3uuiCaKxfbForrK
steps:
- uses: actions/checkout@v2
- name: Install tSQLt with SQL auth on tempdb
uses: lowlydba/tsqlt-installer@v1
with:
sql-instance: localhost
database: tempdb
version: latest
user: sa
password: 3uuiCaKxfbForrK
#- name: Get the containers list unformatted
# run: docker ps
#- name: Get the containers list formatted
# run: docker ps --all --filter status=running --no-trunc --format "{{.ID}}"
#- name: Set the container ID
# run: echo '::set-output name=CONTAINER_ID::$(docker ps --all --filter status=running --no-trunc --format "{{.ID}}")'
# id: ContainerID
#- name: Get container ID
# run: echo "The container ID is ${{ steps.ContainerID.outputs.CONTAINER_ID }}"
- name: Set environment variable ENV_CONTAINER_ID
run: echo "ENV_CONTAINER_ID=$(docker ps --all --filter status=running --no-trunc --format "{{.ID}}")" >> $GITHUB_ENV
- name: Test environment variable ENV_CONTAINER_ID
run: echo $ENV_CONTAINER_ID
#- name: Print environment variables
# run: env
- name: Restore AdventureWorks2017
run: docker exec -i $ENV_CONTAINER_ID /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P "3uuiCaKxfbForrK" -Q "RESTORE DATABASE [AdventureWorks2017] FROM DISK = '/adventureworks.bak' WITH MOVE 'AdventureWorks2017' TO '/var/opt/mssql/data/AdventureWorks.mdf', MOVE 'AdventureWorks2017_log' TO '/var/opt/mssql/data/AdventureWorks_log.ldf'"
- name: Get the database list
run: docker exec -i $ENV_CONTAINER_ID /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P "3uuiCaKxfbForrK" -Q "SELECT Name FROM sys.databases"
- name: Install tSQLt with SQL auth on AdventureWorks2017
uses: lowlydba/tsqlt-installer@v1
with:
sql-instance: localhost
database: AdventureWorks2017
version: latest
user: sa
password: 3uuiCaKxfbForrK
- name: Create sp usp_Raiserror_SafetyStockLevel
run: docker exec -i $ENV_CONTAINER_ID /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P "3uuiCaKxfbForrK" -d AdventureWorks2017 -b < ./source/usp-raiserror-safetystocklevel.sql
- name: Create system under test (SUT) TR_Product_SafetyStockLevel
run: docker exec -i $ENV_CONTAINER_ID /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P "3uuiCaKxfbForrK" -d AdventureWorks2017 -b < ./source/tr-product-safetystocklevel.sql
- name: Create test class UnitTestTRProductSafetyStockLevel
run: docker exec -i $ENV_CONTAINER_ID /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P "3uuiCaKxfbForrK" -d AdventureWorks2017 -b < ./unit-test/test-class-trproductsafetystocklevel.sql
- name: Create and run test case try to insert one wrong row
run: docker exec -i $ENV_CONTAINER_ID /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P "3uuiCaKxfbForrK" -d AdventureWorks2017 -b < ./unit-test/test-case-try-to-insert-one-wrong-row.sql
- name: Create and run test case try to insert one right row
run: docker exec -i $ENV_CONTAINER_ID /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P "3uuiCaKxfbForrK" -d AdventureWorks2017 -b < ./unit-test/test-case-try-to-insert-one-right-row.sql
- name: Create and run test case try to insert multiple rows
run: docker exec -i $ENV_CONTAINER_ID /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P "3uuiCaKxfbForrK" -d AdventureWorks2017 -b < ./unit-test/test-case-try-to-insert-multiple-rows.sql
- name: Create and run test case try to insert multiple rows ordered
run: docker exec -i $ENV_CONTAINER_ID /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P "3uuiCaKxfbForrK" -d AdventureWorks2017 -b < ./unit-test/test-case-try-to-insert-multiple-rows-ordered.sql