Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added integration test #10

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
FROM alpine:20201218

# Adding bash
RUN apk --no-cache add \
bash=5.1.0-r0 \
&& \
rm -rf /var/cache/apk/*

ENTRYPOINT [ "bash" ]
25 changes: 25 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,38 @@
.PHONY: build run linters

# Including all other Makefiles
include $(shell find . -name "Makefile.common")

# Builds the module Docker image
build:
docker-compose build module

# Runs an interactive shell into the module Docker image
run:
docker-compose run module

# Runs linters locally
linters:
docker run \
-e RUN_LOCAL=true \
-v $(shell pwd -P):/tmp/lint \
github/super-linter

# Integration test
#
# The module should be able to reach all the other components
integration-test: build

# Running the test
#
# Retrieves `module`'s return code, and terminates
# the test as soon as it returns
docker-compose \
--file tests/integration/docker-compose.yml \
up \
--exit-code-from module

# Manually removing containers on fail
docker-compose \
--file tests/integration/docker-compose.yml \
down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ make build
make run
```

## Run integration tests

```bash
make integration-test
```

## Run linters locally

```bash
Expand Down
15 changes: 15 additions & 0 deletions tests/integration/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Integration test

Simple experiment that lets the `module` image try to
reach out to services directly connected to it,
e.g.,
RabbitMQ,
DGraph,
and
the Quartermaster Orchestrator.

## How to run

```bash
make --directory ../.. integration-test
```
60 changes: 60 additions & 0 deletions tests/integration/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
version: '3.3'
services:

# DGraph
# From: https://github.com/dgraph-io/dgraph/blob/master/contrib/config/docker/docker-compose.yml
zero:
image: dgraph/dgraph:latest
volumes:
- /tmp/data:/dgraph
ports:
- 5080:5080
- 6080:6080
restart: on-failure
command: dgraph zero --my=zero:5080
logging:
driver: none
alpha:
image: dgraph/dgraph:latest
volumes:
- /tmp/data:/dgraph
ports:
- 8080:8080
- 9080:9080
restart: on-failure
command: dgraph alpha --my=alpha:7080 --zero=zero:5080
logging:
driver: none
ratel:
image: dgraph/dgraph:latest
ports:
- 8000:8000
command: dgraph-ratel
logging:
driver: none

# Orchestrator (former `qmstr-master`)
master:
image: endocodeci/qmstr-master:sha-6f14b29
entrypoint: "/usr/local/bin/qmstr-master"
command: "--config /home/qmstr/config/qmstr.yaml"
depends_on:
- zero
- alpha
- ratel
ports:
- 50051:50051
environment:
SERVER_BUILDPATH: "/var/qmstr/buildroot"
volumes:
- ./qmstr-config.yaml:/home/qmstr/config/qmstr.yaml

# Module
module:
image: endocodeci/module
working_dir: /home/module
volumes:
- ./reach.sh:/home/module/reach.sh
entrypoint: ./reach.sh
depends_on:
- master
15 changes: 15 additions & 0 deletions tests/integration/qmstr-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
project:
name: "CI"
metadata:
message: "Hello World!"
# Using docker-compsoe service names
# https://docs.docker.com/compose/networking/
server:
dbAddress: "alpha:9080"
rpcAddress: "master:50051"
analysis:
- analyzer: scancode-analyzer
name: "Scancode Analyzer"
config:
workdir: "/var/qmstr/buildroot"
resultfile: "/var/qmstr/buildroot/scancode.json"
43 changes: 43 additions & 0 deletions tests/integration/reach.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env bash

set -e

# Logging function
function __log() {
echo "[$1] $2"
}

function __success() {
__log "OK" "$1"
}

function __fail() {
__log "FAIL" "$1"
exit "$2"
}

# Test address connectivity
function __check_connectivity() {
wget --spider -q "$1" # check
local wgetreturn=$? # retrieving wget's return code
if [[ $wgetreturn -eq 0 ]]; then
__success "$1 is reachable"
else
__fail "$1 is not reachable" ${wgetreturn}
fi
}

# All DGraph exposed addresses
dgraph_addresses=(
alpha:8080
ratel:8000
)

# Checking DGraph addresses
echo "Checking DGraph addresses: " "${dgraph_addresses[@]}"
for dgraph_address in "${dgraph_addresses[@]}"; do
__check_connectivity "${dgraph_address}"
done

# All tests
__success "All tests have passed"