From c1300e0b5d945464980d2b1e69ee6fd6bd47f967 Mon Sep 17 00:00:00 2001 From: Juri Leino Date: Fri, 17 Feb 2023 17:28:30 +0100 Subject: [PATCH 1/2] fix: dns result order v4 first Since node 18 the result order of DNS names are operating system dependent. Setting the flag `--dns-result-order` to `ipv4first` in the shebang ensures that we are able to connect to an exist-db instance. They do bind on ipv4 addresses. --- cli.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli.js b/cli.js index 961576f..2ad4ae2 100755 --- a/cli.js +++ b/cli.js @@ -1,4 +1,4 @@ -#!/usr/bin/env node +#!/usr/bin/env -S node --dns-result-order ipv4first import yargs from 'yargs' import { commands } from './commands/index.js' From 8ffdcc84bc4a7f8aeb6cc3d9a7a62d029e63f208 Mon Sep 17 00:00:00 2001 From: Juri Leino Date: Fri, 17 Feb 2023 17:33:00 +0100 Subject: [PATCH 2/2] test: ensure exec tests run on OSX This test suite was the last one relying on older test-paradigm. --- spec/tests/exec.js | 130 ++++++++++++++------------------------------- spec/tests/list.js | 2 +- 2 files changed, 40 insertions(+), 92 deletions(-) diff --git a/spec/tests/exec.js b/spec/tests/exec.js index 3e03271..e437efe 100644 --- a/spec/tests/exec.js +++ b/spec/tests/exec.js @@ -1,83 +1,48 @@ import { test } from 'tape' -import yargs from 'yargs' -import * as exec from '../../commands/exec.js' -import { runPipe } from '../test.js' - -const parser = yargs().scriptName('xst').command(exec).help().fail(false) - -const execCmd = async (cmd, args) => { - return await yargs() - .scriptName('xst') - .command(cmd) - .fail(false) - .parse(args) -} - -test('shows help', async function (t) { - // Run the command module with --help as argument - const output = await new Promise((resolve, reject) => { - parser.parse(['execute', '--help'], (err, argv, output) => { - if (err) { return reject(err) } - resolve(output) - }) - }) - const firstLine = output.split('\n')[0] +import { run, runPipe } from '../test.js' + +test("calling 'xst execute --help'", async (t) => { + const { stderr, stdout } = await run('xst', ['execute', '--help']) + if (stderr) { return t.fail(stderr) } + + const firstLine = stdout.split('\n')[0] t.equal(firstLine, 'xst execute [] [options]', firstLine) + t.end() }) -test('executes command', async function (t) { - const argv = await new Promise((resolve, reject) => { - parser.parse(['execute', '1+1'], (err, argv, output) => { - if (err) { return reject(err) } - resolve(argv) - }) - }) +test('executes command', async (t) => { + const { stderr, stdout } = await run('xst', ['execute', '1+1']) + if (stderr) { return t.fail(stderr) } - t.equal(argv.query, '1+1') + t.equal(stdout, '2\n') }) test('executes command with alias \'exec\'', async function (t) { - const argv = await new Promise((resolve, reject) => { - parser.parse(['exec', '1+1'], (err, argv, output) => { - if (err) { return reject(err) } - resolve(argv) - }) - }) - - t.equal(argv.query, '1+1') + const { stderr, stdout } = await run('xst', ['exec', '1+1']) + if (stderr) { return t.fail(stderr) } + + t.equal(stdout, '2\n') }) test('executes command with alias \'run\'', async function (t) { - const argv = await new Promise((resolve, reject) => { - parser.parse(['run', '1+1'], (err, argv, output) => { - if (err) { return reject(err) } - resolve(argv) - }) - }) - - t.equal(argv.query, '1+1') + const { stderr, stdout } = await run('xst', ['run', '1+1']) + if (stderr) { return t.fail(stderr) } + + t.equal(stdout, '2\n') }) test('executes bound command', async function (t) { - const argv = await new Promise((resolve, reject) => { - parser.parse(['exec', '-b', '{"a":1}', '$a+$a'], (err, argv, output) => { - if (err) { return reject(err) } - resolve(argv) - }) - }) - t.plan(2) - t.equal(argv.query, '$a+$a') - t.equal(argv.bind.a, 1) + const { stderr, stdout } = await run('xst', ['execute', '-b', '{"a":1}', '$a+$a']) + if (stderr) { return t.fail(stderr) } + + t.equal(stdout, '2\n') }) test('bind parse error', async function (t) { - try { - const res = await execCmd(exec, ['exec', '-b', '{a:1}', '$a+$a']) - t.notOk(res) - } catch (e) { - t.ok(e, e) - } + const { stderr, stdout } = await run('xst', ['execute', '-b', '{a:1}', '$a+$a']) + t.notOk(stdout) + t.ok(stderr, stderr) }) test('read bind from stdin', async function (t) { @@ -87,44 +52,27 @@ test('read bind from stdin', async function (t) { }) test('cannot read bind from stdin', async function (t) { - try { - const res = await execCmd(exec, ['exec', '-b', '-', '$a+$a']) - t.fail(res) - } catch (e) { - t.ok(e, e) - } + const { stderr, stdout } = await run('xst', ['execute', '-b', '-', '$a+$a']) + if (stdout) { return t.fail(stdout) } + t.ok(stderr, stderr) }) test('cannot read query file from stdin', async function (t) { - try { - const res = await execCmd(exec, ['exec', '-f', '-']) - t.fail(res) - } catch (e) { - t.ok(e, e) - } + const { stderr, stdout } = await run('xst', ['execute', '-f', '-']) + if (stdout) { return t.fail(stdout) } + t.ok(stderr, stderr) }) test('read query file', async function (t) { - try { - const argv = await new Promise((resolve, reject) => { - parser.parse(['exec', '-f', './spec/fixtures/test.xq'], (err, argv, output) => { - if (err) { return reject(err) } - resolve(argv) - }) - }) - t.equals(argv.f, 'spec/fixtures/test.xq', 'should be normalized') - } catch (e) { - t.notOk(e, e) - } + const { stderr, stdout } = await run('xst', ['execute', '-f', './spec/fixtures/test.xq']) + if (stderr) { return t.fail(stderr) } + t.ok(stdout, stdout) }) test('read query file with query', async function (t) { - try { - const argv = await parser.parse(['exec', '-f', 'spec/fixtures/test.xq', '1+1']) - t.fail(argv, 'Should not return a result') - } catch (e) { - t.ok(e, e) - } + const { stderr, stdout } = await run('xst', ['execute', '-f', './spec/fixtures/test.xq', '1+1']) + if (stdout) { return t.fail(stdout) } + t.ok(stderr, stderr) }) test('read file from stdin', async function (t) { diff --git a/spec/tests/list.js b/spec/tests/list.js index 00fd126..0cca61a 100644 --- a/spec/tests/list.js +++ b/spec/tests/list.js @@ -297,8 +297,8 @@ test('with fixtures uploaded', async (t) => { /db/list-test/tests/info.js /db/list-test/tests/cli.js /db/list-test/tests/upload.js -/db/list-test/tests/configuration.js /db/list-test/tests/exec.js +/db/list-test/tests/configuration.js /db/list-test/tests/rm.js /db/list-test/tests/get.js /db/list-test/tests/list.js