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

Readme #1

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
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
46 changes: 0 additions & 46 deletions docker-compose.yaml

This file was deleted.

17 changes: 17 additions & 0 deletions e2e.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

cd e2e

docker-compose down > /dev/null 2>&1

#sleep 10

docker-compose build
docker-compose up -d

docker-compose ps

docker-compose run --rm e2e

docker-compose down

3 changes: 3 additions & 0 deletions e2e/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
VOTE_IMAGE=lfs261/vote:master
WORKER_IMAGE=lfs261/worker:master
RESULT_IMAGE=lfs261/result:master
14 changes: 7 additions & 7 deletions e2e/docker-compose.test.yml → e2e/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@ version: '2'

services:

sut:
e2e:
build: ./tests/
depends_on:
- vote
- result
- worker
- db
- redis
networks:
- front-tier

vote:
build: ../vote/
image: ${VOTE_IMAGE}
ports: ["80"]
depends_on:
- redis
Expand All @@ -22,8 +24,8 @@ services:
- back-tier

result:
build: .
ports: ["80"]
image: ${RESULT_IMAGE}
ports: ["4000"]
depends_on:
- redis
- db
Expand All @@ -32,7 +34,7 @@ services:
- back-tier

worker:
build: ../worker/
image: ${WORKER_IMAGE}
depends_on:
- redis
- db
Expand All @@ -47,8 +49,6 @@ services:

db:
image: postgres:9.4
volumes:
- "db-data:/var/lib/postgresql/data"
networks:
- back-tier

Expand Down
2 changes: 1 addition & 1 deletion e2e/tests/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ RUN apt-get update -qq && apt-get install -qy \
RUN yarn global add phantomjs-prebuilt
ADD . /app
WORKDIR /app
CMD ["/app/tests.sh"]
CMD ./tests.sh
30 changes: 27 additions & 3 deletions e2e/tests/tests.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,37 @@
#!/bin/sh
#!/bin/bash

current=""
next=""

while ! timeout 1 bash -c "echo > /dev/tcp/vote/80"; do
sleep 1
done

# add initial vote
curl -sS -X POST --data "vote=a" http://vote > /dev/null

current=`phantomjs render.js "http://result:4000/" | grep -i vote | cut -d ">" -f 4 | cut -d " " -f1`
next=`echo "$(($current + 1))"`

echo -e "\n\n-----------------"
echo -e "Current Votes Count: $current"
echo -e "-----------------\n"

echo -e " I: Submitting one more vote...\n"

curl -sS -X POST --data "vote=b" http://vote > /dev/null
sleep 10
sleep 3

new=`phantomjs render.js "http://result:4000/" | grep -i vote | cut -d ">" -f 4 | cut -d " " -f1`


echo -e "\n\n-----------------"
echo -e "New Votes Count: $new"
echo -e "-----------------\n"

echo -e "I: Checking if votes tally......\n"

if phantomjs render.js http://result | grep -q '1 vote'; then
if [ "$next" -eq "$new" ]; then
echo -e "\\e[42m------------"
echo -e "\\e[92mTests passed"
echo -e "\\e[42m------------"
Expand Down
22 changes: 8 additions & 14 deletions result/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
FROM node:8.9-alpine
FROM node:8.16.0-alpine

RUN mkdir -p /app
WORKDIR /app
WORKDIR /app

RUN npm install -g nodemon
RUN npm config set registry https://registry.npmjs.org
COPY package.json /app/package.json
RUN npm install \
&& npm ls \
&& npm cache clean --force \
&& mv /app/node_modules /node_modules
COPY . /app
COPY . .

ENV PORT 80
EXPOSE 80
RUN npm install && \
npm audit fix

EXPOSE 4000

CMD ["node", "server.js"]
CMD npm start
8 changes: 6 additions & 2 deletions result/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "result",
"version": "1.0.0",
"version": "1.1.0",
"description": "",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "node_modules/.bin/mocha"
},
"author": "",
"license": "MIT",
Expand All @@ -16,5 +16,9 @@
"async": "^1.5.0",
"pg": "^4.4.3",
"socket.io": "^1.3.7"
},
"devDependencies": {
"chai": "^4.0.2",
"mocha": "^3.4.2"
}
}
29 changes: 29 additions & 0 deletions result/test/mock.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const expect = require('chai').expect;

describe('mock test 1', () => {
it('unit test 1', () => {
expect(true).to.be.true;
});
});


describe('mock test 2', () => {
it('unit test 2', () => {
expect(true).to.be.true;
});
});

describe('mock test 3', () => {
it('unit test 3', () => {
expect(true).to.be.true;
});
});


describe('mock test 4', () => {
it('unit test 4', () => {
expect(true).to.be.true;
});
});


11 changes: 11 additions & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Uncomment and update Org matching your configurations on Sonarcloud
#sonar.organization=your-org
sonar.projectKey=your-org_example-voting-app
sonar.projectName=Instavote AIO
sonar.projectVersion=1.0
# Comma-separated paths to directories with sources (required)
sonar.sources=worker
# Encoding of the source files
sonar.sourceEncoding=UTF-8
sonar.java.binaries=.
#sonar.coverage.jacoco.xmlReportPaths=worker/target
5 changes: 5 additions & 0 deletions vote/integration/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM alpine:3.9.4
WORKDIR /test
COPY . .
RUN apk add curl
CMD sh
26 changes: 26 additions & 0 deletions vote/integration/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
version: "3"

services:

integration:
build: ./
networks:
- integration

vote:
build: ../
ports: ["80"]
depends_on:
- redis
networks:
- integration

redis:
image: redis:alpine
ports: ["6379"]
networks:
- integration

networks:
integration:

42 changes: 42 additions & 0 deletions vote/integration/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/sh

echo "I: Checking if frontend vote app is available..."

curl http://vote > /dev/null 2>&1

if [ $? -eq 0 ]
then
echo "---------------------------------------"
echo "Vote app is available....proceeding"
echo "---------------------------------------"
else
echo "---------------------------------------"
echo "Vote app is not avilable....aborting"
echo "---------------------------------------"
exit 2
fi


echo "I: Launching integration test..."

# submit a vote. Will return an error if it fails to submit or store vote in redis
# Fail integration test if it returns exit code 0 (error state)

curl -sS -X POST --data "vote=b" http://vote | grep -i erro

if [ $? -eq 0 ]
then
# error, failed
echo "-----------------------------"
echo "INTEGRATION TEST FAILED"
echo "-----------------------------"
exit 1
else
# passed
echo "-----------------------------"
echo "INTEGRATION TEST PASSED"
echo "-----------------------------"
exit 0
fi


30 changes: 30 additions & 0 deletions vote/integration_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash

cd integration

echo "I: Creating environment to run integration tests..."

docker-compose build
docker-compose up -d


echo "I: Launching Integration Test ..."

docker-compose run --rm integration /test/test.sh

if [ $? -eq 0 ]
then
echo "---------------------------------------"
echo "INTEGRATION TESTS PASSED....."
echo "---------------------------------------"
docker-compose down
cd ..
exit 0
else
echo "---------------------------------------"
echo "INTEGRATION TESTS FAILED....."
echo "---------------------------------------"
docker-compose down
cd ..
exit 1
fi
1 change: 1 addition & 0 deletions vote/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Flask
Redis
gunicorn
nose