Skip to content

Commit ad9529d

Browse files
PauloGoncalvesBHPaulo Gonçalves
authored andcommitted
chore(infra-test): containerize infra test to easier run
1 parent bc4a9c7 commit ad9529d

File tree

6 files changed

+38
-33
lines changed

6 files changed

+38
-33
lines changed

.github/CONTRIBUTING.md

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -122,22 +122,7 @@ Para aprofundar sobre como funciona os testes de mutação, leia o meu texto '[T
122122

123123
É utilizado o [Terratest](https://terratest.gruntwork.io/) para realizar teste de infraestrutura, validando comportamento da imagem docker durante sua execução.
124124

125-
Para executar o teste de infra é preciso ter [Go](https://golang.org/doc/install) instalado.
126-
127-
1. Acesse o diretório aonde estão os arquivos `*_test.go`:
128-
```sh
129-
cd test/infra
130-
```
131-
132-
2. Instale as dependências:
133-
```sh
134-
go mod tidy
135-
```
136-
137-
3. Execute os testes:
138-
```sh
139-
go test -count=1 -v -timeout 5m
140-
```
125+
Para rodar o teste de infra e validar o `docker build` de produção, execute o comando `make test-infra`.
141126

142127
> Para saber mais sobre teste de infraestrutura recomendo o texto [What Is Infrastructure Testing And Why Is It Needed](https://www.softwaretestinghelp.com/infrastructure-testing-tutorial/).
143128

.github/workflows/continuous_delivery.yml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ jobs:
4242
steps:
4343
- name: Project checkout
4444
uses: actions/checkout@v2
45-
- run: docker run --rm -i hadolint/hadolint < Dockerfile
45+
- name: Validate production and dev dockerfile (Dockerfile)
46+
run: docker run --rm -i hadolint/hadolint < Dockerfile
47+
- name: Validate terratest dockerfile (Dockerfile.terratest)
48+
run: docker run --rm -i hadolint/hadolint < Dockerfile.terratest
4649

4750
test-unit:
4851

@@ -122,14 +125,9 @@ jobs:
122125
steps:
123126
- name: Project checkout
124127
uses: actions/checkout@v2
125-
- name: Setup Go
126-
uses: actions/setup-go@v2
127-
with:
128-
go-version: '1.16.3'
129-
- name: Install dependencies
130-
run: cd test/infra && go mod tidy
128+
- run: docker-compose build test-infra
131129
- name: Run infra test
132-
run: cd test/infra && go test -count=1 -v -timeout 5m
130+
run: make test-infra
133131

134132
test-contract:
135133

.github/workflows/continuous_integration.yml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ jobs:
4242
steps:
4343
- name: Project checkout
4444
uses: actions/checkout@v2
45-
- run: docker run --rm -i hadolint/hadolint < Dockerfile
45+
- name: Validate production and dev dockerfile (Dockerfile)
46+
run: docker run --rm -i hadolint/hadolint < Dockerfile
47+
- name: Validate terratest dockerfile (Dockerfile.terratest)
48+
run: docker run --rm -i hadolint/hadolint < Dockerfile.terratest
4649

4750
test-unit:
4851

@@ -124,14 +127,9 @@ jobs:
124127
steps:
125128
- name: Project checkout
126129
uses: actions/checkout@v2
127-
- name: Setup Go
128-
uses: actions/setup-go@v2
129-
with:
130-
go-version: '1.16.3'
131-
- name: Install dependencies
132-
run: cd test/infra && go mod tidy
130+
- run: docker-compose build test-infra
133131
- name: Run infra test
134-
run: cd test/infra && go test -count=1 -v -timeout 5m
132+
run: make test-infra
135133

136134
test-contract:
137135

Dockerfile.terratest

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM golang:1.17.3-alpine3.14
2+
3+
RUN apk --no-cache add build-base=0.5-r2 docker=20.10.11-r0 openrc=0.43.3-r2 bash=5.1.4-r0 \
4+
&& rc-update add docker boot
5+
6+
WORKDIR /app
7+
8+
COPY . .
9+
10+
WORKDIR /app/test/infra

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: build build\run run stop clean run-dev test-contract test test-mutation-diff test-mutation
1+
.PHONY: build build\run run stop clean run-dev test-contract test test-mutation-diff test-mutation test-infra
22
# serverest
33

44
NAME_IMAGE=serverest
@@ -41,3 +41,6 @@ test-mutation-diff:
4141

4242
test-mutation:
4343
@docker-compose up --build test-mutation
44+
45+
test-infra:
46+
@docker-compose up --build test-infra

docker-compose.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,14 @@ services:
5454
command: npm run test:mutation:diff
5555
volumes:
5656
- ./reports:/app/reports
57+
58+
test-infra:
59+
build:
60+
context: .
61+
dockerfile: Dockerfile.terratest
62+
command: >
63+
bash -c "go mod tidy
64+
&& go test -count=1 -v -timeout 5m"
65+
volumes:
66+
- ./test/infra:/app/test/infra
67+
- /var/run/docker.sock:/var/run/docker.sock

0 commit comments

Comments
 (0)