Skip to content

Commit

Permalink
[CONSUL-183] Create Bats Dockerfile (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
cocolavayen authored and joselo85 committed Dec 21, 2022
1 parent a2e7802 commit 5587848
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 8 deletions.
15 changes: 15 additions & 0 deletions test/integration/connect/envoy/Dockerfile-bats-core-windows
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM mcr.microsoft.com/windows/servercore:1809

RUN ["powershell", "Set-ExecutionPolicy", "Bypass", "-Scope", "Process", "-Force;"]
RUN ["powershell", "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))"]

RUN choco install git.install -yf

ENV BATS_URL=https://github.com/bats-core/bats-core/archive/refs/tags/v1.7.0.zip
RUN curl %BATS_URL% -L -o bats.zip

RUN mkdir bats-core
RUN tar -xf bats.zip -C bats-core --strip-components=1
RUN cd "C:\\Program Files\\Git\\bin" && bash.exe -c "/c/bats-core/install.sh /c/bats"

ENTRYPOINT ["C:\\Program Files\\Git\\bin\\bash.exe", "C:\\bats\\bin\\bats"]
9 changes: 9 additions & 0 deletions test/integration/connect/envoy/Dockerfile-bats-windows
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM docker.mirror.hashicorp.services/windows/fortio AS fortio

FROM docker.mirror.hashicorp.services/windows/bats:1.7.0

RUN choco install openssl -yf
RUN choco install jq -yf

COPY --from=fortio C:\\fortio C:\\fortio
ENV PATH C:\\fortio;%PATH%
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
function dummyFunction {
local LOCAL_VAR=$1
echo $LOCAL_VAR $COMMON_VAR
}
1 change: 1 addition & 0 deletions test/integration/connect/envoy/case-dummy-bats/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
echo $1 >> $2
2 changes: 2 additions & 0 deletions test/integration/connect/envoy/case-dummy-bats/vars.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
COMMON_VAR="Common variable"
TXT_FILE_NAME="file.txt"
9 changes: 9 additions & 0 deletions test/integration/connect/envoy/case-dummy-bats/verify_1.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@test "Basic Test 1" {
result=4
[ "$result" -eq 4 ]
}

@test "Basic Test 2" {
result=10
[ "$result" -eq 10 ]
}
30 changes: 30 additions & 0 deletions test/integration/connect/envoy/case-dummy-bats/verify_2.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bats

load dummy-function

setup() {
source $(pwd)/workdir/vars.sh
source $(pwd)/workdir/setup.sh "Content of the created setup.txt file in setup.sh" $TXT_FILE_NAME
}

teardown() {
rm $TXT_FILE_NAME
}

@test "Test with dummyFunction invoked" {
FIRST_ARG="First Argument"

run dummyFunction "$FIRST_ARG"

[ $status -eq 0 ]
[ -n "$output" ] # Not empty
[ "$output" = "$FIRST_ARG $COMMON_VAR" ]
}

@test "Test skipped" {
skip

run not_existing_function

[ "$status" -eq 100000 ]
}
48 changes: 40 additions & 8 deletions test/integration/connect/envoy/docker.windows.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- [Dockerfile-test-sds-server-windows](#dockerfile-test-sds-server-windows)
- [Dockerfile-fortio-windows](#dockerfile-fortio-windows)
- [Dockerfile-socat-windows](#dockerfile-socat-windows)
- [Dockerfile-bats-windows](#dockerfile-bats-windows)

## About this File

Expand All @@ -16,21 +17,21 @@ In this file you will find which Dockerfiles are needed to run the Envoy integra
This file sole purpose is to build the test-sds-server executable using Go. To do so, we use an official [golang image](https://hub.docker.com/_/golang/) provided in docker hub with Windows nano server.
To build this image you need to run the following command on your terminal:

```Powershell
```shell
docker build -t test-sds-server -f Dockerfile-test-sds-server-windows test-sds-server
```

This is the same command used in run-tests.sh

You can test the built file by running the following command:

```Powershell
```shell
docker run --rm -p 1234:1234 --name test-sds-server test-sds-server
```

If everything works properly you should get the following output:

```Powershell
```shell
20XX-XX-XXTXX:XX:XX.XXX-XXX [INFO] Loaded cert from file: name=ca-root
20XX-XX-XXTXX:XX:XX.XXX-XXX [INFO] Loaded cert from file: name=foo.example.com
20XX-XX-XXTXX:XX:XX.XXX-XXX [INFO] Loaded cert from file: name=wildcard.ingress.consul
Expand All @@ -43,15 +44,15 @@ If everything works properly you should get the following output:
This file sole purpose is to build the custom Fortio image for Windows OS. To do this, the official [windows/nanoserver image](https://hub.docker.com/_/microsoft-windows-nanoserver) is used as base image.
To build this image you need to run the following command on your terminal:

```Powershell
```shell
docker build -t fortio . -f Dockerfile-fortio-windows
```

This is the same command used in run-tests.sh

You can test the built file by running the following command:

```Powershell
```shell
docker run --rm -p 8080:8080 --name fortio fortio
```

Expand All @@ -67,18 +68,49 @@ The compiled windows version of Socat can be found in the repository [https://gi

To build this image you need to run the following command on your terminal:

```Powershell
```shell
docker build -t socat -f Dockerfile-socat-windows .
```

You can test the built file by running the following command:

```Powershell
```shell
docker run --rm --name socat socat
```

If everything works properly you should get the following output:

```Powershell
```shell
20XX/XX/XX XX:XX:XX socat[1292] E exactly 2 addresses required (there are 0); use option "-h" for help
```

## Dockerfile-bats-windows

This file sole purpose is to build the custom Bats image for Windows OS. To do this, the official [windows/servercore image](https://hub.docker.com/_/microsoft-windows-servercore) is used as base image.
To build this image you need to run the following command on your terminal:

```shell
docker build -t bats-verify . -f Dockerfile-bats-windows
```

This is the same command used in run-tests.sh

You can test the built file by running the following command:

```shell
docker run --rm --name bats-verify -v $(pwd -W)/case-dummy-bats:C:\\workdir bats-verify --pretty /c/workdir/*.bats
```

If everything works properly you should see the result of the dummy test executed as is displayed below

```shell
$ docker run --rm --name bats-verify -v $(pwd -W)/case-dummy-bats:C:\\workdir bats-verify --pretty /c/workdir/*.bats
verify_1.bats
✔ Basic Test 1
✔ Basic Test 2
verify_2.bats
✔ Test with dummyFunction invoked
- Test skipped (skipped)

4 tests, 0 failures, 1 skipped
```

0 comments on commit 5587848

Please sign in to comment.