describe('test-integration/basic', () => { let namespace = null beforeEach(async () => { namespace = await env.setupNamespace() }) afterEach(async () => { await env.tearDownNamespace(namespace) }) // Tests beforeEach and afterEach it('creates and deletes Namespaces', async () => { }) it('gets Pod logs', async () => { const manifest = yaml.safeLoad(fs.readFileSync('./integration/test/busybox-pod.yaml')) const client = await env.getClient() await client.api.v1.namespaces(namespace).pods.post({ body: manifest }) await waitForPod({ client, namespace, name: manifest.metadata.name }) for (let attempt = 0; attempt < 3; attempt++) { const result = await client.api.v1.namespaces(namespace).pods(manifest.metadata.name).log.get() if (result.body && result.body === 'hello\n') return await sleep(1000) } expect.fail('Did not read expected Pod log result') }) })
it('requires `options.dir`', async function () { try { await data({}); } catch (err) { expect(err).to.be.an.instanceOf(CliError); return; } expect.fail('should have thrown an error'); });
context('using invalid parameters', () => { it('fails to connect if parameter is not string or object', () => { return mysqlx.getSession(null) .then(() => expect.fail()) .catch(err => expect(err.message).to.not.equal('expect.fail()')); }); it('fails to connect if URI is not valid', () => { return mysqlx.getSession('') .then(() => expect.fail()) .catch(err => expect(err.message).to.not.equal('expect.fail()')); }); });
it('fails to connect to the server if any address priority is out of bounds', () => { const failoverConfig = Object.assign({}, config); const hosts = [`(address=${failoverConfig.host}, priority=100), (address=[::1], priority=101)`]; const uri = `mysqlx://${failoverConfig.dbUser}:${failoverConfig.dbPassword}@[${hosts.join(', ')}]`; return mysqlx.getSession(uri) .then(() => expect.fail()) .catch(err => { expect(err.message).to.equal('The priorities must be between 0 and 100'); expect(err.errno).to.equal(4007); }); });
it('fails if some unexpected error is thrown even if the option to re-use is enabled alongside additional options', () => { const instance = schema('foo', 'bar'); const options = { reuse_existing: true, validation: true }; const error = new Error(); error.info = {}; td.when(execute()).thenReject(error); td.when(sqlExecute('foo', 'create_collection', [{ schema: 'bar', name: 'baz', options }], 'mysqlx')).thenReturn({ execute }); return instance.createCollection('baz', { reuseExisting: true, validation: true }) .then(() => expect.fail()) .catch(err => expect(err).to.deep.equal(error)); });
it('postpones enabling the schema validation', () => { const jsonSchema = { type: 'object', properties: { name: { type: 'string' } } }; const options = { validation: { schema: jsonSchema, level: mysqlx.Schema.ValidationLevel.OFF } }; return schema.createCollection('test', options) .then(() => schema.modifyCollection('test', { validation: { level: mysqlx.Schema.ValidationLevel.STRICT } })) .then(collection => collection.add({ name: 1 }).execute()) .then(() => expect.fail()) .catch(err => { expect(err.info).to.include.keys('code'); expect(err.info.code).to.equal(5180); }); });
it('fails with unknown validation options', () => { return schema.createCollection('test', { validation: { foo: 'bar' } }) .then(() => expect.fail()) .catch(err => { expect(err.info).to.include.keys('code'); expect(err.info.code).to.equal(5021); }); });
it('fails to connect with the default configuration', () => { const defaultConfig = Object.assign({}, config, { dbUser: '', schema: undefined }); return mysqlx.getSession(defaultConfig) .then(() => expect.fail()) .catch(err => { expect(err.info).to.include.keys('code'); expect(err.info.code).to.equal(1045); }); });
it('fails if there is an unexpected error while encoding the Mysqlx.Session.Reset message ', () => { const client = new FakeClient(network); const error = new Error(); error.info = { code: -1 }; td.when(expectOpen(), { ignoreExtraArgs: true }).thenResolve(); td.when(encodeReset(), { ignoreExtraArgs: true }).thenReturn(); td.when(encodeMessage(), { ignoreExtraArgs: true }).thenThrow(error); return client.sessionReset() .then(() => expect.fail()) .catch(err => expect(err).to.deep.equal(error)); });
it('does not create a savepoint with empty string', () => { return session.startTransaction() .then(() => session.setSavepoint('')) .then(() => expect.fail()) .catch(err => expect(err.message).to.equal('Invalid Savepoint name.')); });
it('fails if the server does not support TLS', () => { const client = new FakeClient(socket); const error = new Error(); error.info = { code: 5001 }; td.when(capabilitiesSet({ tls: true })).thenReject(error); return client.enableTLS() .then(() => expect.fail()) .catch(err => expect(err.message).to.equal('The X Plugin version installed in the server does not support TLS. Check https://dev.mysql.com/doc/refman/8.0/en/x-plugin-ssl-connections.html for more details on how to enable secure connections.')); });
it('fails to connect if the port is out of bounds', () => { const invalidConfig = Object.assign({}, config, { port: -1 }); const uri = `mysqlx://${invalidConfig.dbUser}:${invalidConfig.dbPassword}@${invalidConfig.host}:${invalidConfig.port}`; const error = 'Port must be between 0 and 65536'; return mysqlx.getSession(uri) .then(() => expect.fail()) .catch(err => expect(err.message).to.equal(error)); });
it('fails with an invalid JSON schema', () => { const options = { validation: { schema: 'foo' } }; return schema.createCollection('test', options) .then(() => expect.fail()) .catch(err => { expect(err.info).to.include.keys('code'); expect(err.info.code).to.equal(5182); }); });
it('fails with an invalid value of "level"', () => { const jsonSchema = { type: 'object', properties: { name: { type: 'string' } } }; const options = { validation: { schema: jsonSchema, level: 'foo' } }; return schema.createCollection('test', options) .then(() => expect.fail()) .catch(err => { expect(err.info).to.include.keys('code'); expect(err.info.code).to.equal(5017); }); });
it('fails to connect if the port is out of bounds', () => { const invalidConfig = Object.assign({}, config, { port: 65537 }); const uri = `${invalidConfig.dbUser}:${invalidConfig.dbPassword}@${invalidConfig.host}:${invalidConfig.port}`; const error = 'Port must be between 0 and 65536'; return mysqlx.getSession(uri) .then(() => expect.fail()) .catch(err => expect(err.message).to.equal(error)); });