it('supports async examples', (done) => { try { runExample(getRunArgs(), async () => { await Promise.delay(10) done() }) } catch (e) { assert.fail('should not have thrown an error with an async example func') } })
after(async function () { try { await queryClient.execute(databaseName, `.drop table ${tableName} ifexists`); } catch (err) { assert.fail("Failed to drop table"); } });
function fail (msg) { assert.fail(msg); }
it.skip('does not catch errors if testing is provided', () => { let errorThrown = false try { runExample(getRunArgs(), async () => { throw new Error('test error') }) assert.fail('error was not propagated') } catch (e) { errorThrown = true } assert.ok(errorThrown, 'error was not thrown') })
describe('SetUp', function () { it('Create table', async function () { try { await queryClient.execute(databaseName, `.create table ${tableName} ${tableColumns}`); } catch (err) { assert.fail("Failed to create table"); } }); it('Create table ingestion mapping', async function () { try { await queryClient.execute(databaseName, `.create-or-alter table ${tableName} ingestion json mapping '${mappingName}' '${mapping}'`); } catch (err) { assert.fail("Failed to create table ingestion mapping" + err); } }); });
describe('StreamingIngestClient', function () { it('ingestFromFile', async function () { for (let item of testItems.filter(item => item.testOnstreamingIngestion)) { try { await streamingIngestClient.ingestFromFile(item.path, item.ingestionProperties); } catch (err) { console.error(err); assert.fail(`Failed to ingest ${item.description}`); } await assertRowsCount(item); } }).timeout(240000); it('ingestFromStream', async function () { for (let item of testItems.filter(item => item.testOnstreamingIngestion)) { let stream = fs.createReadStream(item.path); if (item.path.endsWith('gz')) { stream = new StreamDescriptor(stream, null, CompressionType.GZIP); } try { await streamingIngestClient.ingestFromStream(stream, item.ingestionProperties); } catch (err) { assert.fail(`Failed to ingest ${item.description}`); } await assertRowsCount(item); } }).timeout(240000); });
it('throws an error if no example name is provided', () => { try { runExample({}, () => (assert.fail('example should not have executed'))) assert.fail('error should have been thrown with missing name') } catch (e) { assert.ok(!!e) } try { runExample({ name: '' }, async () => (assert.fail('example should not have executed'))) assert.fail('error should have been thrown with empty name') } catch (e) { assert.ok(!!e) } })
describe('ingestClient', function () { it('ingestFromFile', async function () { for (let item of testItems) { try { await ingestClient.ingestFromFile(item.path, item.ingestionProperties); } catch (err) { console.error(err); assert.fail(`Failed to ingest ${item.description}`); } await assertRowsCount(item); } }).timeout(240000); it('ingestFromStream', async function () { for (let item of testItems) { let stream = fs.createReadStream(item.path); if (item.path.endsWith('gz')) { stream = new StreamDescriptor(stream, null, CompressionType.GZIP); } try { await ingestClient.ingestFromStream(stream, item.ingestionProperties); } catch (err) { assert.fail(`Failed to ingest ${item.description}`); } await assertRowsCount(item); } }).timeout(240000); });
}; const handleError = (error) => { assert.fail(error); }; fetchJson.get(url).then(handleData).catch(handleError); const url = 'https://httpbin.org/status/500'; const handleData = (data) => { assert.fail(data); }; const handleError = (error) => { }; const handleError = (error) => { assert.fail(error); }; fetchJson.get(url).then(handleData).catch(handleError);
props.validate(); } catch (ex) { assert.fail(ex);
describe('debugTable', () => { it('throws an error if row, header, and column counts don\'t match', () => { try { debugTable({ rows: [[1]], headers: ['', ''], widths: [20, 20, 20], debug: () => {} }) assert.fail('no error was thrown') } catch (e) { assert.ok(true) } }) it('prints the table out line by line, and returns it as a multi-line string', () => { let debugLineCount = 0 const str = debugTable({ rows: [[1, 1, 1], [2, 2, 2], [3, 3, 3]], headers: ['', '', ''], widths: [20, 20, 20], debug: () => debugLineCount++ }) assert.strictEqual(str.split('\n').length, debugLineCount) }) })
describe('QueryClient', function () { it('General BadRequest', async function () { try { response = await queryClient.executeQuery(databaseName, "invalidSyntax "); } catch (ex) { return; } assert.fail(`General BadRequest ${item.description}`); }); it('PartialQueryFailure', async function () { try { response = await queryClient.executeQuery(databaseName, "invalidSyntax "); } catch (ex) { return; } assert.fail(`Didn't throw PartialQueryFailure ${item.description}`); }); });
it.skip('catches example errors', async () => { let exampleExecuted = false try { await runExample(getRunArgs({ testing: false }), () => { exampleExecuted = true throw new Error('test error') })() } catch (e) { assert.fail('example error should have been caught internally') } assert.ok(exampleExecuted, 'example was not executed') })