From 1cb4e21691f516527e555b47b14b75b391c91076 Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Thu, 10 Feb 2022 06:55:07 +0100 Subject: [PATCH] more tests things --- .github/workflows/{rust.yml => ci.yml} | 2 +- amqp_transport/src/lib.rs | 1 - {tests-js => test-js}/.gitignore | 0 {tests-js => test-js}/.prettierrc.json | 0 {tests-js => test-js}/package.json | 2 +- test-js/src/dummy-test.js | 1 + test-js/src/open-channel.js | 15 +++++ test-js/src/send-single-message.js | 14 +++++ {tests-js/src => test-js/src/utils}/utils.js | 0 test-js/test-all.js | 58 ++++++++++++++++++++ {tests-js => test-js}/yarn.lock | 0 tests-js/src/open-channel.js | 17 ------ tests-js/src/send-single-message.js | 16 ------ xtask/src/test_js.rs | 12 ++-- 14 files changed, 98 insertions(+), 40 deletions(-) rename .github/workflows/{rust.yml => ci.yml} (95%) rename {tests-js => test-js}/.gitignore (100%) rename {tests-js => test-js}/.prettierrc.json (100%) rename {tests-js => test-js}/package.json (86%) create mode 100644 test-js/src/dummy-test.js create mode 100644 test-js/src/open-channel.js create mode 100644 test-js/src/send-single-message.js rename {tests-js/src => test-js/src/utils}/utils.js (100%) create mode 100644 test-js/test-all.js rename {tests-js => test-js}/yarn.lock (100%) delete mode 100644 tests-js/src/open-channel.js delete mode 100644 tests-js/src/send-single-message.js diff --git a/.github/workflows/rust.yml b/.github/workflows/ci.yml similarity index 95% rename from .github/workflows/rust.yml rename to .github/workflows/ci.yml index af557e5..f4c72be 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/ci.yml @@ -30,4 +30,4 @@ jobs: - name: Run tests run: cargo test --verbose --all - name: Run client integration tests - run: cargo xtask tests-js + run: cargo xtask test-js diff --git a/amqp_transport/src/lib.rs b/amqp_transport/src/lib.rs index 990217d..2575acc 100644 --- a/amqp_transport/src/lib.rs +++ b/amqp_transport/src/lib.rs @@ -8,7 +8,6 @@ mod sasl; #[cfg(test)] mod tests; - use crate::connection::Connection; use amqp_core::GlobalData; use anyhow::Result; diff --git a/tests-js/.gitignore b/test-js/.gitignore similarity index 100% rename from tests-js/.gitignore rename to test-js/.gitignore diff --git a/tests-js/.prettierrc.json b/test-js/.prettierrc.json similarity index 100% rename from tests-js/.prettierrc.json rename to test-js/.prettierrc.json diff --git a/tests-js/package.json b/test-js/package.json similarity index 86% rename from tests-js/package.json rename to test-js/package.json index 4b08626..a300bce 100644 --- a/tests-js/package.json +++ b/test-js/package.json @@ -6,7 +6,7 @@ "license": "MIT", "scripts": { "fmt": "prettier -w .", - "test": "echo '✔️ Everything fine!'" + "test": "node test-all.js" }, "dependencies": { "@types/amqplib": "^0.8.2", diff --git a/test-js/src/dummy-test.js b/test-js/src/dummy-test.js new file mode 100644 index 0000000..01668bd --- /dev/null +++ b/test-js/src/dummy-test.js @@ -0,0 +1 @@ +console.log('Passed :)'); diff --git a/test-js/src/open-channel.js b/test-js/src/open-channel.js new file mode 100644 index 0000000..b276f62 --- /dev/null +++ b/test-js/src/open-channel.js @@ -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'); diff --git a/test-js/src/send-single-message.js b/test-js/src/send-single-message.js new file mode 100644 index 0000000..f1070d5 --- /dev/null +++ b/test-js/src/send-single-message.js @@ -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'); diff --git a/tests-js/src/utils.js b/test-js/src/utils/utils.js similarity index 100% rename from tests-js/src/utils.js rename to test-js/src/utils/utils.js diff --git a/test-js/test-all.js b/test-js/test-all.js new file mode 100644 index 0000000..1e7343e --- /dev/null +++ b/test-js/test-all.js @@ -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); +} diff --git a/tests-js/yarn.lock b/test-js/yarn.lock similarity index 100% rename from tests-js/yarn.lock rename to test-js/yarn.lock diff --git a/tests-js/src/open-channel.js b/tests-js/src/open-channel.js deleted file mode 100644 index 893970a..0000000 --- a/tests-js/src/open-channel.js +++ /dev/null @@ -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'); -})(); diff --git a/tests-js/src/send-single-message.js b/tests-js/src/send-single-message.js deleted file mode 100644 index b84b3db..0000000 --- a/tests-js/src/send-single-message.js +++ /dev/null @@ -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'); -})(); diff --git a/xtask/src/test_js.rs b/xtask/src/test_js.rs index aa41b52..f61343f 100644 --- a/xtask/src/test_js.rs +++ b/xtask/src/test_js.rs @@ -1,17 +1,21 @@ use crate::project_root; -use anyhow::{bail, Result}; +use anyhow::{bail, Context, Result}; use std::process::Command; pub fn main() -> Result<()> { - let test_js_root = project_root().join("tests-js"); - let status = Command::new("yarn").current_dir(&test_js_root).status()?; + let test_js_root = project_root().join("test-js"); + let status = Command::new("yarn") + .current_dir(&test_js_root) + .status() + .context("yarn install tests")?; if !status.success() { bail!("yarn install failed"); } let status = Command::new("yarn") .arg("test") .current_dir(&test_js_root) - .status()?; + .status() + .context("yarn test tests")?; if !status.success() { bail!("yarn tests failed"); }