Add end-to-end test and CI setup
This commit is contained in:
parent
906495d31b
commit
60ba2de7d7
|
@ -1 +1,2 @@
|
|||
tsconfig.json
|
||||
test/*.json
|
||||
|
|
|
@ -1,7 +1,26 @@
|
|||
variables:
|
||||
- &node_image 'node:20.11.0-alpine@sha256:2f46fd49c767554c089a5eb219115313b72748d8f62f5eccb58ef52bc36db4ad'
|
||||
- &create_synapse_access_token >-
|
||||
echo '{"user_id":"ci-dummy","access_token":"ci-dummy","home_server":"ci-dummy","device_id":"ci-dummy"}' > src/config/synapse_access_token.json
|
||||
|
||||
services:
|
||||
synapse:
|
||||
image: docker.io/matrixdotorg/synapse:v1.99.0
|
||||
environment:
|
||||
- SYNAPSE_CONFIG_PATH=/data/homeserver.yaml
|
||||
- SYNAPSE_SERVER_NAME=synapse
|
||||
- SYNAPSE_REPORT_STATS=no
|
||||
ports:
|
||||
- 8008
|
||||
volumes:
|
||||
- /mnt/synapse:/data
|
||||
commands:
|
||||
- rm -rf /data/*
|
||||
- /start.py generate
|
||||
- sed -ri '/^registration_shared_secret:.*$/d' /data/homeserver.yaml
|
||||
- echo >> /data/homeserver.yaml
|
||||
- cat test/homeserver_additions.yaml >> /data/homeserver.yaml
|
||||
- cp app-service.example.yaml /data/app-service.yaml
|
||||
- chmod +r /data/*.signing.key
|
||||
- /start.py
|
||||
|
||||
steps:
|
||||
check-pre-commit:
|
||||
|
@ -11,10 +30,17 @@ steps:
|
|||
commands:
|
||||
- pre-commit run --all-files
|
||||
|
||||
synapse-register-admin:
|
||||
image: docker.io/matrixdotorg/synapse:v1.99.0
|
||||
commands:
|
||||
- timeout 120 sh -c 'while !(( register_new_matrix_user http://synapse:8008 --shared-secret testrun --admin --user admin --password admin 2> /dev/null )); do sleep 1; done;'
|
||||
- 'curl --request POST --url http://synapse:8008/_matrix/client/v3/login --header "Content-Type: application/json" --data "{\"type\": \"m.login.password\",\"user\": \"admin\",\"password\": \"admin\",\"device_id\": \"DEV\"}" | tee src/config/synapse_access_token.json'
|
||||
|
||||
node-install-dependencies:
|
||||
image: *node_image
|
||||
commands:
|
||||
- npm clean-install
|
||||
depends_on: [check-pre-commit]
|
||||
|
||||
node-lint:
|
||||
image: *node_image
|
||||
|
@ -28,16 +54,30 @@ steps:
|
|||
- npm run format
|
||||
depends_on: [node-install-dependencies]
|
||||
|
||||
node-test-e2e:
|
||||
image: *node_image
|
||||
environment:
|
||||
- REGISTRATION_SHARED_SECRET=testrun
|
||||
- AS_TOKEN=30c05ae90a248a4188e620216fa72e349803310ec83e2a77b34fe90be6081f46
|
||||
- SYNAPSE_URL=http://synapse:8008
|
||||
- ADMIN_USERNAME=admin
|
||||
- ADMIN_PASSWORD=admin
|
||||
commands:
|
||||
- mkdir -p inputs
|
||||
- npx node-jq --compact-output '.' test/messages.json > inputs/rocketchat_message.json
|
||||
- npx node-jq --compact-output '.' test/rooms.json > inputs/rocketchat_room.json
|
||||
- npx node-jq --compact-output '.' test/users.json > inputs/users.json
|
||||
- npm start
|
||||
depends_on: [node-install-dependencies, synapse-register-admin]
|
||||
|
||||
node-test:
|
||||
image: *node_image
|
||||
commands:
|
||||
- *create_synapse_access_token
|
||||
- npm test --ci
|
||||
depends_on: [node-install-dependencies]
|
||||
|
||||
node-compile:
|
||||
image: *node_image
|
||||
commands:
|
||||
- *create_synapse_access_token
|
||||
- npm run compile
|
||||
depends_on: [node-install-dependencies]
|
||||
|
|
0
inputs/.gitkeep
Normal file
0
inputs/.gitkeep
Normal file
1311
package-lock.json
generated
1311
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -26,6 +26,7 @@
|
|||
"fix": "npm run lint-fix",
|
||||
"test": "rm -rf dist/ && jest",
|
||||
"compile": "rm -rf dist/ && tsc",
|
||||
"jq-test-users": "jq --compact-output '.' test/users.json",
|
||||
"start": "npm run compile && node dist/app.js",
|
||||
"prepare": "husky"
|
||||
},
|
||||
|
@ -45,6 +46,7 @@
|
|||
"eslint-plugin-promise": "^6.1.1",
|
||||
"husky": "^9.0.0",
|
||||
"lint-staged": "^15.0.0",
|
||||
"node-jq": "^4.3.1",
|
||||
"prettier": "3.2.5",
|
||||
"ts-jest": "^29.1.1",
|
||||
"typescript": "^5.2.2"
|
||||
|
|
|
@ -22,6 +22,7 @@ import {
|
|||
getMatrixMembers,
|
||||
whoami,
|
||||
} from './helpers/synapse'
|
||||
import { exit } from 'node:process'
|
||||
|
||||
log.info('rocketchat2matrix starts.')
|
||||
|
||||
|
@ -139,6 +140,7 @@ async function main() {
|
|||
} else {
|
||||
log.error(`Encountered an error while booting up: ${error}`, error)
|
||||
}
|
||||
exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
31
test/homeserver_additions.yaml
Normal file
31
test/homeserver_additions.yaml
Normal file
|
@ -0,0 +1,31 @@
|
|||
registration_shared_secret: testrun
|
||||
|
||||
rc_login:
|
||||
address:
|
||||
per_second: 1024
|
||||
burst_count: 2048
|
||||
account:
|
||||
per_second: 1024
|
||||
burst_count: 2048
|
||||
rc_joins:
|
||||
local:
|
||||
per_second: 1024
|
||||
burst_count: 2048
|
||||
rc_joins_per_room:
|
||||
per_second: 1024
|
||||
burst_count: 2048
|
||||
rc_message:
|
||||
per_second: 1024
|
||||
burst_count: 2048
|
||||
rc_invites:
|
||||
per_room:
|
||||
per_second: 1024
|
||||
burst_count: 2048
|
||||
per_user:
|
||||
per_second: 1024
|
||||
burst_count: 2048
|
||||
per_issuer:
|
||||
per_second: 1024
|
||||
burst_count: 2048
|
||||
app_service_config_files:
|
||||
- /data/app-service.yaml
|
35
test/login.js
Normal file
35
test/login.js
Normal file
|
@ -0,0 +1,35 @@
|
|||
const axios = require('axios')
|
||||
const fs = require('fs')
|
||||
|
||||
async function login() {
|
||||
let loggedIn = false
|
||||
while (!loggedIn) {
|
||||
await new Promise((resolve) => setTimeout(resolve, 1000)) // Wait for 1 second before retrying
|
||||
try {
|
||||
const response = await axios.post(
|
||||
'http://synapse:8008/_matrix/client/v3/login',
|
||||
{
|
||||
type: 'm.login.password',
|
||||
user: 'admin',
|
||||
password: 'admin',
|
||||
device_id: 'DEV',
|
||||
}
|
||||
)
|
||||
if (response.status === 200) {
|
||||
fs.writeFileSync(
|
||||
'src/config/synapse_access_token.json',
|
||||
JSON.stringify(response.data)
|
||||
)
|
||||
loggedIn = true
|
||||
} else {
|
||||
console.log(
|
||||
`Login failed with status ${response.status}: ${response.data}`
|
||||
)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error during login:', error.message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
login()
|
Loading…
Reference in a new issue