Skip to content

Commit

Permalink
Add integation test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
neekolas committed Mar 1, 2024
1 parent 0137d16 commit d58981e
Show file tree
Hide file tree
Showing 29 changed files with 1,172 additions and 34 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/integration
docker-compose.yml
proto
docs
dist
4 changes: 4 additions & 0 deletions .env.docker
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
DB_CONNECTION_STRING="postgres://postgres:xmtp@db:5432/postgres?sslmode=disable"
XMTP_GRPC_ADDRESS="node:5556"
LOG_ENCODING=console
API_PORT="8080"
12 changes: 9 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
name: Test
name: Tests
on:
pull_request:
jobs:
test:
name: Test
name: Unit
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version-file: go.mod
- run: docker-compose up -d
- run: ./dev/up
- name: Run Tests
run: go test -p 1 ./...
integration:
name: Integration
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: docker-compose up integration
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@

# Dependency directories (remove the comment below to include it)
# vendor/
/dist
/dist
node_modules
4 changes: 4 additions & 0 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ func main() {
deliveryServices = append(deliveryServices, fcm)
}

if opts.HttpDelivery.Enabled {
deliveryServices = append(deliveryServices, delivery.NewHttpDelivery(logger, opts.HttpDelivery))
}

listener, err = xmtp.NewListener(ctx, logger, opts.Xmtp, installationsService, subscriptionsService, deliveryServices, clientVersion, appVersion)
if err != nil {
logger.Fatal("failed to initialize listener", zap.Error(err))
Expand Down
4 changes: 4 additions & 0 deletions dev/integration
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
set -eou pipefail

docker-compose up integration
2 changes: 1 addition & 1 deletion dev/up
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
set -eou pipefail

docker compose up -d
docker compose up -d node
34 changes: 34 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ services:
- --api.enable-mls
- --wait-for-db=30s
ports:
- 25555:5555
- 25556:5556
depends_on:
- db
- mlsdb
- validation

validation:
image: ghcr.io/xmtp/mls-validation-service:main
Expand All @@ -32,3 +35,34 @@ services:
image: postgres:13
environment:
POSTGRES_PASSWORD: xmtp

notification_server:
build:
context: .
env_file: .env.docker
depends_on:
- node
command:
- --xmtp-listener
- --api
- --http-delivery
- --http-delivery-address=http://integration:7777/post
- --api-port=8080

integration:
build:
context: ./integration
dockerfile: Dockerfile
expose:
- 7777
volumes:
- ./integration/src:/usr/app/src:ro
depends_on:
- node
- notification_server
environment:
- XMTP_NODE_URL=http://node:5555
- NOTIFICATION_SERVER_URL=http://notification_server:8080
command:
- bun
- test
1 change: 1 addition & 0 deletions integration/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
175 changes: 175 additions & 0 deletions integration/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore

# Logs

logs
_.log
npm-debug.log_
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Caches

.cache

# Diagnostic reports (https://nodejs.org/api/report.html)

report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json

# Runtime data

pids
_.pid
_.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover

lib-cov

# Coverage directory used by tools like istanbul

coverage
*.lcov

# nyc test coverage

.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)

.grunt

# Bower dependency directory (https://bower.io/)

bower_components

# node-waf configuration

.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)

build/Release

# Dependency directories

node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)

web_modules/

# TypeScript cache

*.tsbuildinfo

# Optional npm cache directory

.npm

# Optional eslint cache

.eslintcache

# Optional stylelint cache

.stylelintcache

# Microbundle cache

.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history

.node_repl_history

# Output of 'npm pack'

*.tgz

# Yarn Integrity file

.yarn-integrity

# dotenv environment variable files

.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)

.parcel-cache

# Next.js build output

.next
out

# Nuxt.js build / generate output

.nuxt
dist

# Gatsby files

# Comment in the public line in if your project uses Gatsby and not Next.js

# https://nextjs.org/blog/next-9-1#public-directory-support

# public

# vuepress build output

.vuepress/dist

# vuepress v2.x temp and cache directory

.temp

# Docusaurus cache and generated files

.docusaurus

# Serverless directories

.serverless/

# FuseBox cache

.fusebox/

# DynamoDB Local files

.dynamodb/

# TernJS port file

.tern-port

# Stores VSCode versions used for testing VSCode extensions

.vscode-test

# yarn v2

.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

# IntelliJ based IDEs
.idea

# Finder (MacOS) folder config
.DS_Store
19 changes: 19 additions & 0 deletions integration/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM oven/bun:1 as base
WORKDIR /usr/app

# install dependencies into temp directory
# this will cache them and speed up future builds
FROM base AS install
RUN mkdir -p /temp/dev
COPY package.json bun.lockb /temp/dev/
RUN cd /temp/dev && bun install --frozen-lockfile

# The real release artifact
FROM base
COPY --from=install /temp/dev/node_modules node_modules
COPY . .

# run the app
USER bun
EXPOSE 7777/tcp
ENTRYPOINT [ "bun", "test" ]
29 changes: 29 additions & 0 deletions integration/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# integration

This package is designed to run as an integration test suite for the notification server. It may also serve as a useful reference for how to interact with the server.

These tests rely on the `HttpDelivery` Delivery Service on the node to send notifications directly back to the server to verify the notification content. Normally notifications would be sent by APNS or FCM.

It is meant to be run inside Docker.

## Usage

In the root of the repo

```bash
./dev/integration
```

## Development setup

To install dependencies:

```bash
bun install
```

To run:

```bash
bun run src/index.ts
```
Binary file added integration/bun.lockb
Binary file not shown.
17 changes: 17 additions & 0 deletions integration/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "integration",
"module": "src/index.ts",
"type": "module",
"devDependencies": {
"@types/bun": "latest"
},
"peerDependencies": {
"typescript": "^5.0.0"
},
"dependencies": {
"@connectrpc/connect": "^1.4.0",
"@connectrpc/connect-web": "^1.4.0",
"@xmtp/xmtp-js": "^11.4.1",
"viem": "^2.7.16"
}
}
13 changes: 13 additions & 0 deletions integration/src/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function assertEnvVar(key: string): string {
const value = process.env[key];
if (!value) {
throw new Error(`Missing environment variable ${key}`);
}

return value;
}

export const config = {
nodeUrl: assertEnvVar("XMTP_NODE_URL"),
notificationServerUrl: assertEnvVar("NOTIFICATION_SERVER_URL"),
} as const;
Loading

0 comments on commit d58981e

Please sign in to comment.