Skip to content

Commit

Permalink
Develop (#7)
Browse files Browse the repository at this point in the history
Test definition improvements
Better argument parsing
"generate" command

Co-authored-by: Riccardo Sale <[email protected]>
  • Loading branch information
gicastel and Riccardo Sale authored Sep 20, 2022
1 parent 4b827fa commit f58c042
Show file tree
Hide file tree
Showing 21 changed files with 787 additions and 668 deletions.
3 changes: 2 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
DockerFile
bundle.dockerfile
standalone.dockerfile
.gitattributes
.gitignore
Readme.md
Expand Down
36 changes: 34 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ on:
tags:
- '*'

jobs:
build:
jobs:
build-binaries:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand All @@ -33,3 +33,35 @@ jobs:
artifacts: "*.gz"
token: ${{ secrets.GITHUB_TOKEN }}
draft: true

build-docker-standalone:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
name: Check out code

- uses: mr-smithers-excellent/docker-build-push@v5
name: Build & push Docker standalone image
with:
image: quest
tags: standalone-latest, standalone-${{ github.ref_name }}
registry: ghcr.io
dockerfile: standalone.dockerfile
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

build-docker-bundle:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
name: Check out code

- uses: mr-smithers-excellent/docker-build-push@v5
name: Build & push Docker bundle image
with:
image: quest
tags: bundle-latest, bundle-${{ github.ref_name }}
registry: ghcr.io
dockerfile: bundle.dockerfile
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
56 changes: 37 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# qest

## What is qest?
A simple, cross platform, command line tool to test MSSQL procedures without the needs of a SSDT project or custom procedures / assemblies.

Expand All @@ -13,35 +11,55 @@ The tool does not implement a transaction logic for the tests: you have to provi
This is by design, to not interfere with the transaction logic that may be implemented in the stored procedures.

## Quickstart
### Local
### Local binary
Run tests in a single file:
```
./qest --file relative/path/to/file.yml --tcs targetDatabaseConnectionString
./qest run --file relative/path/to/file.yml --tcs targetDatabaseConnectionString
```
Run all tests in a folder:
```
./qest --folder relative/path/to/folder --tcs targetDatabaseConnectionString
./qest run --folder relative/path/to/folder --tcs targetDatabaseConnectionString
```
Generate templates from the database into an output directory:
```
./qest run --folder relative/path/to/folder --tcs targetDatabaseConnectionString
```
### Local container, provided database server
Same options as the local binary version, but with a provided runtime.
```
### Container
docker run --rm -t \
-v {full/local/path/to/test/folder}:/tests \
-v {full/local/path/to/scripts/folder}:/scripts \
qest:standalone \
run --folder tests --tcs targetDatabaseConnectionString
```
or:
```
docker run --rm -t \
-v {full/local/path/to/template/folder}:/templates \
qest:standalone \
generate --folder templates --tcs targetDatabaseConnectionString
```

### Bundle container
This container contains ( ;-) ) Microsoft SQL Server 2019 *and* qest executables, so you can deploy the database and run tests in a pristine environment.
You need to provide:
- the `dacpac` file of your database: the folder containing it wil be mounted on the `/quest/db` container folder
- the YAML files: the folder containing them wil be mounted on the `/quest/tests` container folder
- the scripts: the folder containing them wil be mounted on the `/quest/scripts` container folder
- the `dacpac` file of your database: the folder containing it wil be mounted on the `/db` container folder
- the YAML files: the folder containing them wil be mounted on the `/tests` container folder
- the scripts: the folder containing them wil be mounted on the `/scripts` container folder


Please note: for this default image to work, YAML files have to reference the _File_ scripts in the `scripts/{filename}` form. See [docs](docs/YamlFormat.md#script).
Please note: for this default image to work, YAML files have to reference the _File_ scripts in the `scripts/{filename}` form. See [docs](https://github.com/Geims83/qest/wiki/YamlFormat).

Run the image binding the `tests`, `scripts` and `db` directories and providing the correct environment variables:
```
docker run --rm \
-v {full/local/path/to/test/folder}:/qest/tests \
-v {full/local/path/to/scripts/folder}:/qest/scripts \
-v {full/local/path/to/dacpac/folder}:/qest/db \
docker run --rm -t \
-v {full/local/path/to/test/folder}:/tests \
-v {full/local/path/to/scripts/folder}:/scripts \
-v {full/local/path/to/dacpac/folder}:/db \
--env DACPAC={filenameWithoutExtension} \
ghcr.io/geims83/qest:latest
qest:bundle
```
## Samples
See [samples folder](samples/README.md).

## YAML test definition
See [docs](docs/YamlFormat.md).
## Got _qest_ ...ions?
Go to the [wiki](https://github.com/Geims83/qest/wiki)!
19 changes: 10 additions & 9 deletions Dockerfile → bundle.dockerfile
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
FROM mcr.microsoft.com/dotnet/sdk:6.0 as build

COPY ./src ./src
RUN dotnet publish /src/qest/ -o /qest --runtime linux-x64 -c Release --self-contained true /p:PublishSingleFile=true /p:PublishTrimmed=true
RUN dotnet publish /src/qest/ -o /output --runtime linux-x64 -c Release --self-contained true /p:PublishSingleFile=true /p:PublishTrimmed=true

FROM mcr.microsoft.com/mssql/server:2019-latest AS mssql
USER root

# env vars needed by the mssql image
ENV ACCEPT_EULA Y
ENV SA_PASSWORD qestDbSecurePassword27!
#
#ENV DACPAC


WORKDIR /qest
COPY --from=build /qest/qest .
WORKDIR /app
COPY --from=build /output/ .

RUN chmod a+x qest

# sqlpackage
RUN apt-get update \
&& apt-get install unzip -y

RUN wget -O sqlpackage.zip https://go.microsoft.com/fwlink/?linkid=2143497
RUN wget -O sqlpackage.zip https://aka.ms/sqlpackage-linux
RUN unzip sqlpackage.zip
RUN chmod a+x sqlpackage

WORKDIR /

# Launch SQL Server, confirm startup is complete, deploy the DACPAC, run tests.
# See https://stackoverflow.com/a/51589787/488695

ENTRYPOINT ["sh", "-c", "( /opt/mssql/bin/sqlservr & ) | grep -q \"Service Broker manager has started\" \
&& ./sqlpackage /a:Publish /sf:db/${DACPAC}.dacpac /tsn:. /tdn:$DACPAC /tu:sa /tp:$SA_PASSWORD \
&& ./qest --folder tests --tcs \"Server=localhost,1433;Initial Catalog=${DACPAC};User Id=sa;Password=${SA_PASSWORD}\""]
&& PATH='$PATH':/app \
&& sqlpackage /a:Publish /sf:db/${DACPAC}.dacpac /tsn:. /tdn:$DACPAC /tu:sa /tp:$SA_PASSWORD \
&& qest run --folder tests --tcs \"Server=localhost,1433;Initial Catalog=${DACPAC};User Id=sa;Password=${SA_PASSWORD}\""]
154 changes: 0 additions & 154 deletions docs/YamlFormat.md

This file was deleted.

2 changes: 1 addition & 1 deletion samples/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ WORKDIR /build
COPY ./sampleDb .
RUN dotnet build . -c Release -o /dacpac

FROM ghcr.io/geims83/qest:latest
FROM qest:bundle

ENV DACPAC=sampleDb

Expand Down
Loading

0 comments on commit f58c042

Please sign in to comment.