Skip to content

Commit

Permalink
Merge pull request #5 from pathwar/dev/moul/integration-test
Browse files Browse the repository at this point in the history
feat: integration test
  • Loading branch information
moul committed Dec 20, 2018
2 parents 370ba9c + aa9c334 commit 69526c8
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 17 deletions.
41 changes: 24 additions & 17 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ jobs:
steps:
- checkout
- setup_remote_docker
- run:
name: docker build
command: docker build -t pathwar/pathwar .
- run: docker build -t pathwar/pathwar .
# FIXME: save cache

# build and unit test the project
Expand All @@ -28,26 +26,35 @@ jobs:
steps:
- checkout
# FIXME: restore cache
- run:
name: fetch dependencies
command: |
go clean -modcache
go get
- run:
name: install
command: |
sleep 1
touch .generated
make install
- run:
name: test
command: make test
- run: go clean -modcache
- run: go get
- run: make _ci_prepare
- run: make test
# FIXME: save cache
# FIXME: store_test_results

docker.integration:
docker:
- image: docker:17.05.0-ce-git
steps:
- checkout
- run:
name: Install Deps
command: |
apk --no-cache add curl openssl python3 make bash
pip3 install -U pip docker-compose
docker-compose --version
- setup_remote_docker:
docker_layer_caching: true
- run: docker build -t pathwar/pathwar .
- run: make docker.integration
- run: make docker.integration
- run: docker-compose logs

workflows:
version: 2
commit:
jobs:
- test
- docker.build
- docker.integration
16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ $(BIN): .generated $(OUR_SOURCES)
clean:
rm -f $(GENERATED_FILES) .generated

.PHONY: _ci_prepare
_ci_prepare:
touch $(OUR_PROTOS) $(GENERATED_FILES)
sleep 1
touch .generated

.PHONY: generate
generate: .generated
.generated: $(OUR_PROTOS)
Expand Down Expand Up @@ -77,3 +83,13 @@ test: .generated
.PHONY: docker.build
docker.build:
docker build -t pathwar/pathwar .

.PHONY: docker.integration
docker.integration:
docker-compose -f ./test/docker-compose.yml up -d server
docker-compose -f ./test/docker-compose.yml run client
docker-compose -f ./test/docker-compose.yml down

.PHONY: integration
integration:
./test/integration.sh
11 changes: 11 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: '2.3'

services:
server:
&server
image: pathwar/pathwar
command: server
#depends_on:
# - mysql
ports:
- 8000
8 changes: 8 additions & 0 deletions test/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM alpine
RUN apk --no-cache add curl openssl python3 make bash jq \
&& pip3 install -U pip setuptools httpie \
&& http --version \
&& jq --version
ENTRYPOINT ["/bin/bash", "-c"]
CMD ["sleep 5; ./integration.sh"]
COPY . .
15 changes: 15 additions & 0 deletions test/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: '2.3'

services:
server:
extends:
file: ../docker-compose.yml
service: server

client:
build: .
environment:
TARGET: http://server:8000
depends_on:
- server
tty: true
9 changes: 9 additions & 0 deletions test/integration.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash -xe
# depends on: httpie, jq

TARGET="${TARGET:-http://localhost:8000}"

http --check-status "${TARGET}"/ping
token=$(http --check-status "${TARGET}"/authenticate username=integration | jq -r .token)
test "$(http --check-status "${TARGET}"/session | jq -r .message)" = "no token provided"
test "$(http --check-status "${TARGET}"/session "Authorization:$token" | jq -r .username)" = "integration"

0 comments on commit 69526c8

Please sign in to comment.