more tests things

This commit is contained in:
nora 2022-02-10 06:55:07 +01:00
parent a7dba08990
commit 1cb4e21691
14 changed files with 98 additions and 40 deletions

View file

@ -30,4 +30,4 @@ jobs:
- name: Run tests - name: Run tests
run: cargo test --verbose --all run: cargo test --verbose --all
- name: Run client integration tests - name: Run client integration tests
run: cargo xtask tests-js run: cargo xtask test-js

View file

@ -8,7 +8,6 @@ mod sasl;
#[cfg(test)] #[cfg(test)]
mod tests; mod tests;
use crate::connection::Connection; use crate::connection::Connection;
use amqp_core::GlobalData; use amqp_core::GlobalData;
use anyhow::Result; use anyhow::Result;

View file

@ -6,7 +6,7 @@
"license": "MIT", "license": "MIT",
"scripts": { "scripts": {
"fmt": "prettier -w .", "fmt": "prettier -w .",
"test": "echo '✔️ Everything fine!'" "test": "node test-all.js"
}, },
"dependencies": { "dependencies": {
"@types/amqplib": "^0.8.2", "@types/amqplib": "^0.8.2",

View file

@ -0,0 +1 @@
console.log('Passed :)');

View file

@ -0,0 +1,15 @@
import { connect } from 'amqplib';
import { sleep } from './utils/utils.js';
const connection = await connect('amqp://localhost');
const channel = await connection.createChannel();
console.log('Successfully opened channel');
await sleep(100_000);
await channel.close();
await connection.close();
console.log('Successfully shut down connection');

View file

@ -0,0 +1,14 @@
import { connect } from 'amqplib';
const connection = await connect('amqp://localhost');
const channel = await connection.createChannel();
channel.publish('exchange-1', 'queue-1', Buffer.from('hello'));
console.log('Published message');
await channel.close();
await connection.close();
console.log('Successfully shut down connection');

58
test-js/test-all.js Normal file
View file

@ -0,0 +1,58 @@
import * as childProcess from 'child_process';
import * as fsSync from 'fs';
import * as fs from 'fs/promises';
import * as path from 'path';
import * as url from 'url';
const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
const srcDir = path.join(__dirname, 'src');
const src = await fs.readdir(srcDir);
const tests = src
.map((test) => [path.join(srcDir, test), test])
.filter(([testPath]) => {
const stats = fsSync.statSync(testPath);
return !stats.isDirectory();
});
let done = 0;
const successes = [];
const failures = [];
function maybeDone() {
if (done === tests.length) {
for (const success of successes) {
console.log(`✔️ Test ${success} successful`);
}
for (const { name, stderr } of failures) {
console.log(
`------------------- stderr test ${name} -------------------`
);
console.log(stderr);
console.log(`------------------- stderr test ${name} -------------------
Test ${name} failed`);
}
if (failures.length > 0) {
process.exit(1);
}
}
}
function runTest(path, name) {
childProcess.exec(`node ${path}`, {}, (error, _, stderr) => {
if (!error) {
successes.push(name);
} else {
failures.push({ name, stderr });
}
done += 1;
maybeDone();
});
}
for (const [test, name] of tests) {
runTest(test, name);
}

View file

@ -1,17 +0,0 @@
import { connect } from 'amqplib';
import { sleep } from './utils.js';
(async () => {
const connection = await connect('amqp://localhost');
const channel = await connection.createChannel();
console.log('Successfully opened channel');
await sleep(100_000);
await channel.close();
await connection.close();
console.log('Successfully shut down connection');
})();

View file

@ -1,16 +0,0 @@
import { connect } from 'amqplib';
(async () => {
const connection = await connect('amqp://localhost');
const channel = await connection.createChannel();
channel.publish('exchange-1', 'queue-1', Buffer.from('hello'));
console.log('Published message');
await channel.close();
await connection.close();
console.log('Successfully shut down connection');
})();

View file

@ -1,17 +1,21 @@
use crate::project_root; use crate::project_root;
use anyhow::{bail, Result}; use anyhow::{bail, Context, Result};
use std::process::Command; use std::process::Command;
pub fn main() -> Result<()> { pub fn main() -> Result<()> {
let test_js_root = project_root().join("tests-js"); let test_js_root = project_root().join("test-js");
let status = Command::new("yarn").current_dir(&test_js_root).status()?; let status = Command::new("yarn")
.current_dir(&test_js_root)
.status()
.context("yarn install tests")?;
if !status.success() { if !status.success() {
bail!("yarn install failed"); bail!("yarn install failed");
} }
let status = Command::new("yarn") let status = Command::new("yarn")
.arg("test") .arg("test")
.current_dir(&test_js_root) .current_dir(&test_js_root)
.status()?; .status()
.context("yarn test tests")?;
if !status.success() { if !status.success() {
bail!("yarn tests failed"); bail!("yarn tests failed");
} }