Skip to content

Commit 7057007

Browse files
committed
Improved unit testing runner workflow
1 parent 29aa2bb commit 7057007

File tree

1 file changed

+39
-28
lines changed

1 file changed

+39
-28
lines changed

samples/containers/unit-testing/tsqlt-docker/.github/workflows/automated-tests.yml

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
# This workflow installs tSQLt and runs the test units
1+
# This workflow runs the configured unit tests after installing tSQLt on a SQL Server instance inside a Docker container!
22

3-
name: tSQLt installer and unit testing runner
3+
name: Unit testing runner
4+
5+
#---------- 1. Definition of activation events
46

57
# Controls when the workflow will run
68
on:
@@ -9,16 +11,21 @@ on:
911
branches: [ "master" ]
1012
pull_request:
1113
branches: [ "master" ]
12-
14+
1315
# Allows you to run this workflow manually from the Actions tab
1416
workflow_dispatch:
1517

18+
#---------- 2. Creating a Docker container from a SQL Server image on Linux
19+
1620
jobs:
21+
1722
windows-auth-tsqlt:
18-
name: Installting tSQLt with SQL Auth
23+
24+
name: Installting tSQLt framework with SQL Auth and running unit tests
25+
1926
# The type of runner that the job will run on
2027
runs-on: ubuntu-latest
21-
28+
2229
services:
2330
sqlserver:
2431
image: chriseaton/adventureworks:latest
@@ -29,63 +36,67 @@ jobs:
2936
SA_PASSWORD: 3uuiCaKxfbForrK
3037

3138
steps:
32-
- uses: actions/checkout@v2
3339

34-
- name: Install tSQLt with SQL auth on tempdb
35-
uses: lowlydba/tsqlt-installer@v1
36-
with:
37-
sql-instance: localhost
38-
database: tempdb
39-
version: latest
40-
user: sa
41-
password: 3uuiCaKxfbForrK
42-
40+
#---------- 2.1 Save the container ID into the environment variable ENV_CONTAINER_ID
41+
4342
#- name: Get the containers list unformatted
4443
# run: docker ps
45-
44+
4645
#- name: Get the containers list formatted
4746
# run: docker ps --all --filter status=running --no-trunc --format "{{.ID}}"
48-
47+
4948
#- name: Set the container ID
5049
# run: echo '::set-output name=CONTAINER_ID::$(docker ps --all --filter status=running --no-trunc --format "{{.ID}}")'
5150
# id: ContainerID
52-
51+
5352
#- name: Get container ID
5453
# run: echo "The container ID is ${{ steps.ContainerID.outputs.CONTAINER_ID }}"
55-
54+
5655
- name: Set environment variable ENV_CONTAINER_ID
5756
run: echo "ENV_CONTAINER_ID=$(docker ps --all --filter status=running --no-trunc --format "{{.ID}}")" >> $GITHUB_ENV
5857

5958
- name: Test environment variable ENV_CONTAINER_ID
6059
run: echo $ENV_CONTAINER_ID
61-
62-
#- name: Print environment variables
63-
# run: env
6460

65-
- name: Restore AdventureWorks2017
61+
- name: Sleep for 20s
62+
uses: juliangruber/sleep-action@v1
63+
with:
64+
time: 20s
65+
66+
#---------- 3. AdventureWorks database recovery
67+
68+
- name: Restore AdventureWorks
6669
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'"
6770

6871
- name: Get the database list
6972
run: docker exec -i $ENV_CONTAINER_ID /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P "3uuiCaKxfbForrK" -Q "SELECT Name FROM sys.databases"
7073

74+
#---------- 4. Installation of the tSQLt framework
75+
76+
- uses: actions/[email protected]
77+
7178
- name: Install tSQLt with SQL auth on AdventureWorks2017
7279
uses: lowlydba/tsqlt-installer@v1
7380
with:
7481
sql-instance: localhost
7582
database: AdventureWorks2017
7683
version: latest
7784
user: sa
78-
password: 3uuiCaKxfbForrK
79-
85+
password: 3uuiCaKxfbForrK
86+
87+
#---------- 5. Creating the database objects to be tested (SUT)
88+
8089
- name: Create sp usp_Raiserror_SafetyStockLevel
8190
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
82-
91+
8392
- name: Create system under test (SUT) TR_Product_SafetyStockLevel
8493
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
85-
94+
95+
#---------- 6. Creation and execution of test units
96+
8697
- name: Create test class UnitTestTRProductSafetyStockLevel
8798
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
88-
99+
89100
- name: Create and run test case try to insert one wrong row
90101
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
91102

0 commit comments

Comments
 (0)