generated from well-known-components/template-server
-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat: integration tests #13
Open
lauti7
wants to merge
12
commits into
main
Choose a base branch
from
i-tests
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.
+588
−150
Open
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
4ce25e0
fixes
lauti7 c443d31
wip tests
lauti7 d3f6558
local dev tools
lauti7 90eacc4
release client after commit
lauti7 5c2cea9
stop pubsub without checking
lauti7 c498d44
integration tests
lauti7 575daf2
add redis service
lauti7 d680d3a
update dockerfile
lauti7 4a03e10
fix dockerfile
lauti7 38a04ad
fix workflow
lauti7 0bf3678
fix
lauti7 8d1b83e
one release
lauti7 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 |
---|---|---|
@@ -1,2 +1,4 @@ | ||
node_modules | ||
npm-debug.log | ||
npm-debug.log | ||
docker-compose.* | ||
Makefile |
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,62 @@ | ||
name: build | ||
name: build-app | ||
|
||
on: | ||
push: | ||
|
||
jobs: | ||
build: | ||
uses: decentraland/platform-actions/.github/workflows/apps-with-db-build.yml@main | ||
validations: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Use Node.js 18.x | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 18.x | ||
cache: yarn | ||
- name: install | ||
run: yarn install --frozen-lockfile | ||
- name: lint | ||
run: yarn lint:check | ||
|
||
test: | ||
runs-on: ubuntu-latest | ||
services: | ||
postgres: | ||
image: postgres | ||
env: | ||
POSTGRES_USER: postgres | ||
POSTGRES_DB: db | ||
POSTGRES_PASSWORD: pass1234 | ||
options: >- | ||
--health-cmd pg_isready | ||
--health-interval 10s | ||
--health-timeout 5s | ||
--health-retries 5 | ||
ports: | ||
- 5432:5432 | ||
redis: | ||
image: redis | ||
options: >- | ||
--health-cmd "redis-cli ping" | ||
--health-interval 10s | ||
--health-timeout 5s | ||
--health-retries 5 | ||
ports: | ||
- 6379:6379 | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Use Node.js 18.x | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 18.x | ||
cache: yarn | ||
- name: install | ||
run: yarn install --frozen-lockfile | ||
- name: create .env | ||
run: echo "" >> .env | ||
- name: build | ||
run: yarn build | ||
- name: test | ||
run: yarn test | ||
env: | ||
PG_COMPONENT_PSQL_CONNECTION_STRING: postgres://postgres:pass1234@localhost/db |
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,44 +1,40 @@ | ||
ARG RUN | ||
|
||
FROM node:lts as builderenv | ||
FROM node:18-alpine as builderenv | ||
|
||
WORKDIR /app | ||
|
||
# some packages require a build step | ||
RUN apt-get update && apt-get -y -qq install build-essential | ||
|
||
# We use Tini to handle signals and PID1 (https://github.com/krallin/tini, read why here https://github.com/krallin/tini/issues/8) | ||
ENV TINI_VERSION v0.19.0 | ||
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /tini | ||
RUN chmod +x /tini | ||
|
||
# install dependencies | ||
COPY package.json /app/package.json | ||
COPY yarn.lock /app/yarn.lock | ||
RUN yarn | ||
RUN apk update && apk add wget | ||
|
||
# build the app | ||
COPY . /app | ||
RUN yarn install --frozen-lockfile | ||
RUN yarn build | ||
RUN yarn test | ||
|
||
# remove devDependencies, keep only used dependencies | ||
RUN yarn install --frozen-lockfile --production | ||
RUN yarn install --prod --frozen-lockfile | ||
|
||
########################## END OF BUILD STAGE ########################## | ||
|
||
FROM node:lts | ||
FROM node:18-alpine | ||
|
||
RUN apk update && apk add --update wget && apk add --update tini | ||
|
||
# NODE_ENV is used to configure some runtime options, like JSON logger | ||
ENV NODE_ENV production | ||
|
||
ARG COMMIT_HASH=local | ||
ENV COMMIT_HASH=${COMMIT_HASH:-local} | ||
|
||
ARG CURRENT_VERSION=Unknown | ||
ENV CURRENT_VERSION=${CURRENT_VERSION:-Unknown} | ||
|
||
WORKDIR /app | ||
COPY --from=builderenv /app /app | ||
COPY --from=builderenv /tini /tini | ||
# Please _DO NOT_ use a custom ENTRYPOINT because it may prevent signals | ||
# (i.e. SIGTERM) to reach the service | ||
# Read more here: https://aws.amazon.com/blogs/containers/graceful-shutdowns-with-ecs/ | ||
# and: https://www.ctl.io/developers/blog/post/gracefully-stopping-docker-containers/ | ||
|
||
RUN echo "" > /app/.env | ||
|
||
ENTRYPOINT ["/tini", "--"] | ||
# Run the program under Tini | ||
CMD [ "/usr/local/bin/node", "--trace-warnings", "--abort-on-uncaught-exception", "--unhandled-rejections=strict", "dist/index.js" ] |
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,44 @@ | ||
DOCKER_COMPOSE_EXISTS = $(shell which docker-compose > /dev/null && echo 1 || echo 0) | ||
|
||
RUN_SERVICES = docker-compose -f docker-compose.local.yml up -d && docker exec social_service_ea_db bash -c "until pg_isready; do sleep 1; done" > /dev/null && sleep 5 | ||
RUN_TEST_SERVICES = docker-compose -f docker-compose.test.yml up -d && docker exec social_service_ea_test_db bash -c "until pg_isready; do sleep 1; done" > /dev/null && sleep 5 | ||
LOCAL_DB = $(shell docker ps | grep social_service_ea_db > /dev/null && echo 1 || echo 0) | ||
|
||
run-services: | ||
ifeq ($(DOCKER_COMPOSE_EXISTS), 1) | ||
@$(RUN_SERVICES) | ||
else | ||
@$(ERROR) "Install Docker in order to run the local DB" | ||
@exit 1; | ||
endif | ||
|
||
run-test-services: | ||
ifeq ($(DOCKER_COMPOSE_EXISTS), 1) | ||
@$(RUN_TEST_SERVICES) | ||
else | ||
@$(ERROR) "Install Docker in order to run the local DB" | ||
@exit 1; | ||
endif | ||
|
||
stop-services: | ||
-@docker stop social_service_ea_db | ||
-@docker stop social_service_ea_redis | ||
|
||
stop-test-services: | ||
-@docker stop social_service_ea_test_db | ||
-@docker stop social_service_ea_test_redis | ||
-@docker rm social_service_ea_test_db | ||
-@docker rm social_service_ea_test_redis | ||
|
||
# Local testing | ||
tests: | ||
ifeq ($(LOCAL_DB), 1) | ||
@make stop-services | ||
@make run-test-services | ||
-@npm run test | ||
@make stop-test-services | ||
else | ||
@make run-test-services | ||
-@npm run test | ||
@make stop-test-services | ||
endif |
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,23 @@ | ||
version: '3.8' | ||
services: | ||
postgres: | ||
container_name: 'social_service_ea_db' | ||
image: 'postgres:latest' | ||
restart: always | ||
user: postgres | ||
volumes: | ||
- postgres_volume:/var/lib/postgresql/data | ||
environment: | ||
- POSTGRES_PASSWORD=postgres | ||
- POSTGRES_DB=social_service_ea | ||
ports: | ||
- '5432:5432' | ||
redis: | ||
container_name: 'social_service_ea_redis' | ||
image: 'redis:latest' | ||
restart: always | ||
user: redis | ||
ports: | ||
- '6379:6379' | ||
volumes: | ||
postgres_volume: |
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,19 @@ | ||
version: '3.8' | ||
services: | ||
postgres: | ||
container_name: 'social_service_ea_test_db' | ||
image: 'postgres:latest' | ||
restart: always | ||
user: postgres | ||
environment: | ||
- POSTGRES_PASSWORD=postgres | ||
- POSTGRES_DB=social_service_ea | ||
ports: | ||
- '5432:5432' | ||
redis: | ||
container_name: 'social_service_ea_test_redis' | ||
image: 'redis:latest' | ||
restart: always | ||
user: redis | ||
ports: | ||
- '6379:6379' |
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,10 +1,10 @@ | ||
module.exports = { | ||
transform: { | ||
"^.+\\.(ts|tsx)$": ["ts-jest", {tsconfig: "test/tsconfig.json"}] | ||
'^.+\\.(ts|tsx)$': ['ts-jest', { tsconfig: 'test/tsconfig.json' }] | ||
}, | ||
moduleFileExtensions: ["ts", "js"], | ||
coverageDirectory: "coverage", | ||
collectCoverageFrom: ["src/**/*.ts", "src/**/*.js"], | ||
testMatch: ["**/*.spec.(ts)"], | ||
testEnvironment: "node", | ||
moduleFileExtensions: ['ts', 'js'], | ||
coverageDirectory: 'coverage', | ||
collectCoverageFrom: ['src/**/*.ts', 'src/**/*.js'], | ||
testMatch: ['**/*.spec.(ts)'], | ||
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 |
---|---|---|
|
@@ -129,8 +129,6 @@ export function createDBComponent(components: Pick<AppComponents, 'pg' | 'logs'> | |
async updateFriendshipStatus(friendshipId, isActive, txClient) { | ||
logger.debug(`updating ${friendshipId} - ${isActive}`) | ||
const query = SQL`UPDATE friendships SET is_active = ${isActive}, updated_at = now() WHERE id = ${friendshipId}` | ||
console.log(query.text) | ||
console.log(query.values) | ||
|
||
if (txClient) { | ||
const results = await txClient.query(query) | ||
|
@@ -205,6 +203,8 @@ export function createDBComponent(components: Pick<AppComponents, 'pg' | 'logs'> | |
await client.query('ROLLBACK') | ||
client.release() | ||
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. not sure if this a problem, but you are releasing it twice, once here and one one finally |
||
throw error | ||
} finally { | ||
client.release() | ||
} | ||
} | ||
} | ||
|
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
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
Oops, something went wrong.
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 this? What's missing on the
apps-with-db-build.yml
?