-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
feat: server test with docker CI #36
Open
kartikp36
wants to merge
21
commits into
main
Choose a base branch
from
KB-147-server-test-with-docker-ci
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
c91bcf5
fix: refactor and fix server tests
kartikp36 fe7d6c4
chore: initialize docker in server
kartikp36 6cad33f
fix: minor fixes
kartikp36 36bbc83
fix: integrate postgres & docker and copy types.d.ts
kartikp36 321d9c8
feat: add docker-compose ci
kartikp36 8abb27a
fix: path of docker-compose
kartikp36 1fa702b
fix: env vars for postgres and command fix
kartikp36 3fca112
Merge branch 'KB-139-fix-server-test' into KB-147-server-test-with-do…
kartikp36 58153e5
fix: docker-postgres fixed and initialize pool in db.ts
kartikp36 cd7f2e6
fix: update docker-compose.yml
kartikp36 f438fed
fix: make test exit
kartikp36 138c520
fix: initialise notes table in jest test
kartikp36 97a2e42
fix: timeout and fixs
kartikp36 6126be3
fix: jest test waits for 10 seconds for postgres
kartikp36 38ad451
fix: initialise beforeall and drop afterall in Jest and timeout 5 mins
kartikp36 5bc7771
fix: add jest.config.js and minor fixes
kartikp36 0b6e1a8
fix: run test file only once
kartikp36 db491ca
refactor: delete server/types, move docker-compose.yml and minor fixes
kartikp36 dcab86f
fix: ./docker-compose and timeout 3 mins
kartikp36 8386daf
fix: db exits with app container
kartikp36 4d49c4c
Merge branch 'KB-147-server-test-with-docker-ci' of https://github.co…
kartikp36 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: Docker Test | ||
|
||
on: [pull_request, workflow_dispatch] | ||
jobs: | ||
test: | ||
name: Run test suite | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 3 | ||
env: | ||
POSTGRES_USER: "postgres" | ||
POSTGRES_PASSWORD: "postgres" | ||
POSTGRES_DB: "notes_data" | ||
COMPOSE_FILE: ./docker-compose.yml | ||
DOCKER_USER: ${{ secrets.DOCKER_USER }} | ||
DOCKER_PASS: ${{ secrets.DOCKER_PASS }} | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Login to DockerHub | ||
run: docker login -u $DOCKER_USER -p $DOCKER_PASS | ||
|
||
- name: Build docker images | ||
run: docker-compose build | ||
|
||
- name: Run tests | ||
run: docker-compose up --abort-on-container-exit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
version: "3" | ||
services: | ||
db: | ||
image: postgres:10 | ||
networks: | ||
- webnet | ||
environment: | ||
POSTGRES_PASSWORD: postgres | ||
POSTGRES_USER: postgres | ||
POSTGRES_DB: notes_data | ||
ports: | ||
- "5432:5432" | ||
app: | ||
image: server_app | ||
build: | ||
context: ./ | ||
dockerfile: ./server/Dockerfile | ||
depends_on: | ||
- db | ||
ports: | ||
- "5000:5000" | ||
environment: | ||
DATABASE_URL: "postgres://postgres:postgres@db:5432/notes_data?sslmode=disable" | ||
networks: | ||
- webnet | ||
volumes: | ||
- .:/app/ | ||
- /app/node_modules | ||
command: npm test | ||
networks: | ||
webnet: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
FROM node | ||
WORKDIR /usr/app | ||
COPY types.d.ts ../ | ||
COPY ./server . | ||
RUN npm install typescript -g && npm install | ||
EXPOSE 3000 | ||
CMD npm test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import * as pg from "pg"; | ||
import * as env from "./env"; | ||
|
||
const pool = new pg.Pool({ | ||
connectionString: env.DATABASE_URL, | ||
ssl: { | ||
rejectUnauthorized: false, | ||
}, | ||
}); | ||
|
||
export default pool; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
preset: "ts-jest", | ||
testEnvironment: "node", | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,7 @@ | ||
import app from "./index"; | ||
import * as env from "./env"; | ||
import * as pg from "pg"; | ||
import { initialiseSQLTable } from "./service"; | ||
|
||
export const pool = new pg.Pool({ | ||
connectionString: env.DATABASE_URL, | ||
ssl: { | ||
rejectUnauthorized: false, | ||
}, | ||
}); | ||
|
||
initialiseSQLTable(); | ||
const port = env.SERVER_PORT; | ||
app.listen(port, () => console.log(`Listening at port ${port} ...`)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,18 @@ | ||
import request from "supertest"; | ||
|
||
import app from "../index"; | ||
import pool from "../db"; | ||
|
||
describe("http requests testing", () => { | ||
beforeAll(async () => { | ||
const client = await pool.connect(); | ||
await client.query( | ||
`CREATE TABLE IF NOT EXISTS "notes"(id UUID PRIMARY KEY, title VARCHAR(32) NOT NULL, "noteContent" TEXT NOT NULL, created TIMESTAMPTZ, "lastUpdated" TIMESTAMPTZ)` | ||
); | ||
client.release(true); | ||
}); | ||
|
||
let secondId; | ||
test("Initial GET request", async () => { | ||
const response = await request(app).get("/notes"); | ||
expect(response.statusCode).toBe(200); | ||
|
@@ -32,6 +42,7 @@ describe("http requests testing", () => { | |
title: "2nd", | ||
noteContent: "This is Second note", | ||
}); | ||
secondId = response.text; | ||
expect(response.statusCode).toBe(200); | ||
}); | ||
|
||
|
@@ -45,28 +56,38 @@ describe("http requests testing", () => { | |
}); | ||
|
||
test("GET request of second note by id", async () => { | ||
const response = await request(app).get("/notes/2"); | ||
const response = await request(app).get(`/notes/${secondId}`); | ||
expect(response.statusCode).toStrictEqual(200); | ||
const noteJson: Note = response.body; | ||
expect(noteJson.title).toBe("2nd"); | ||
expect(noteJson.noteContent).toBe("This is Second note"); | ||
}); | ||
|
||
test("GET request by id to get 404 response", async () => { | ||
const response = await request(app).get("/notes/99"); | ||
test("GET request by a random id to get 404 response", async () => { | ||
const response = await request(app).get( | ||
"/notes/c61f1fc9-e0d2-43ce-a6c1-b5436cdebe7d" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's just an example in uuid format as |
||
); | ||
expect(response.statusCode).toStrictEqual(404); | ||
}); | ||
|
||
test("DELETE request of second note by id", async () => { | ||
const response = await request(app).delete("/notes/2"); | ||
const response = await request(app).delete(`/notes/${secondId}`); | ||
expect(response.statusCode).toStrictEqual(200); | ||
}); | ||
test("GET request of deleted second note", async () => { | ||
const response = await request(app).get("/notes/2"); | ||
const response = await request(app).get(`/notes/${secondId}`); | ||
expect(response.statusCode).toStrictEqual(404); | ||
}); | ||
test("DELETE request to get bad request response", async () => { | ||
const response = await request(app).delete("/notes/2"); | ||
const response = await request(app).delete( | ||
"/notes/c61f1fc9-e0d2-43ce-a6c1-b5436cdebe7d" | ||
); | ||
expect(response.statusCode).toStrictEqual(400); | ||
}); | ||
|
||
afterAll(async () => { | ||
const client = await pool.connect(); | ||
await client.query(`DROP TABLE notes`); | ||
client.release(true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we logging to DockerHub again? Can we not use the
Dockerfile
from this repo?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to login for Dockerfile to PULL images.