How to use docker.createContainer method in qawolf

Best JavaScript code snippet using qawolf

index.test.js

Source:index.test.js Github

copy

Full Screen

1const test = require('ava');2const sinon = require('sinon');3const portscanner = require('portscanner');4const winston = require('winston');5const wsServer = require('../../coinstac-images/coinstac-base/server-ws2');6const mocks = require('../helpers/mocks');7const Manager = require('../src');8const {9 getImages,10 getStatus,11 pullImages,12 pullImagesFromList,13 pruneImages,14 removeImage,15 setLogger,16 startService,17 stopService,18 stopAllServices,19 docker,20} = Manager;21const { ALL_IMAGES, COMPUTATIONS, getRandomPort } = mocks;22const { transports: { Console } } = winston;23const WS_SERVER_PORT = 3223;24process.LOGLEVEL = 'info';25test.before(() => wsServer.start({ port: WS_SERVER_PORT }));26test('getImages, pruneImages and removeImage', async (t) => {27 /* getImages */28 sinon.stub(docker, 'listImages').resolves(ALL_IMAGES);29 let res = await getImages();30 t.is(res.length, ALL_IMAGES.length);31 docker.listImages.restore();32 /* pruneImages */33 sinon.stub(docker, 'listImages').yields(null, ALL_IMAGES);34 const getImageSuccessCallback = { remove: sinon.stub().yields(null, 'success') };35 const getImageFailCallback = { remove: sinon.stub().yields('error') };36 sinon.stub(docker, 'getImage')37 .onFirstCall()38 .returns(getImageFailCallback)39 .returns(getImageSuccessCallback);40 res = await pruneImages();41 t.is(res.filter(elem => elem === 'success').length, 9);42 docker.listImages.restore();43 sinon.stub(docker, 'listImages').yields(new Error('error'), null);44 try {45 res = await pruneImages();46 } catch (e) {47 t.is(e.message, 'error');48 }49 docker.listImages.restore();50 docker.getImage.restore();51 /* removeImage */52 sinon.stub(docker, 'getImage').returns({53 remove: () => Promise.resolve(),54 });55 const image = COMPUTATIONS[0].img;56 res = await removeImage(image);57 t.is(res, undefined);58 docker.getImage.restore();59});60test('getStatus', async (t) => {61 sinon.stub(docker, 'ping').resolves('OK');62 const status = await getStatus();63 t.is(status, 'OK');64 docker.ping.restore();65});66test('pullImages and pullImagesFromList', async (t) => {67 /* pullImages */68 sinon.stub(docker, 'pull').yields(null, 'stream');69 let images = await pullImages(COMPUTATIONS);70 t.deepEqual(71 images.map(image => image.compId),72 COMPUTATIONS.map(comp => comp.compId)73 );74 docker.pull.restore();75 sinon.stub(docker, 'pull').yields('error', null);76 images = await pullImages(COMPUTATIONS);77 t.deepEqual(78 images.map(image => image.compId),79 COMPUTATIONS.map(comp => comp.compId)80 );81 docker.pull.restore();82 sinon.stub(docker, 'pull').yields(null, 'stream');83 const compList = COMPUTATIONS.map(comp => comp.img);84 images = await pullImagesFromList(compList);85 t.is(compList.length, images.length);86 docker.pull.restore();87});88test('setLogger', async (t) => {89 const logger = winston.createLogger({90 level: 'silly',91 transports: [new Console()],92 });93 const res = setLogger(logger);94 t.deepEqual(res, logger);95});96test('startService, stopService, stopAllServices', async (t) => {97 /* startService1 */98 const container = {99 inspect: () => { },100 };101 sinon.stub(portscanner, 'findAPortNotInUse').returns(getRandomPort());102 sinon.stub(docker, 'createContainer').resolves({103 start: sinon.stub().resolves(container),104 stop: () => { },105 inspect: sinon.stub().yields(null, { State: { Running: true } }),106 });107 let opts = {108 docker: { CMD: [] },109 };110 let res = await startService('service-1', 'test-1', 'docker', opts);111 t.is(typeof res, 'function');112 portscanner.findAPortNotInUse.restore();113 docker.createContainer.restore();114 /* startService2 */115 sinon.stub(portscanner, 'findAPortNotInUse').returns(getRandomPort());116 sinon.stub(docker, 'createContainer').resolves({117 start: sinon.stub().resolves(container),118 stop: () => { },119 inspect: sinon.stub().yields('error', null),120 });121 await startService('service-2', 'test-2', 'docker', opts);122 try {123 await startService('service-2', 'test-2', 'docker', opts);124 } catch (error) {125 t.is(error, 'error');126 }127 portscanner.findAPortNotInUse.restore();128 docker.createContainer.restore();129 /* startService3 */130 sinon.stub(portscanner, 'findAPortNotInUse').returns(getRandomPort());131 sinon.stub(docker, 'createContainer').resolves({132 start: sinon.stub().resolves(container),133 stop: () => { },134 inspect: sinon.stub().yields(null, { State: { Running: true } }),135 });136 res = await startService('service-3', 'test-3', 'docker', opts);137 t.is(typeof res, 'function');138 res = await startService('service-3', 'test-3', 'docker', opts);139 t.is(typeof res, 'function');140 portscanner.findAPortNotInUse.restore();141 docker.createContainer.restore();142 /* startService4 */143 sinon.stub(portscanner, 'findAPortNotInUse').returns(getRandomPort());144 sinon.stub(docker, 'createContainer').resolves({145 start: sinon.stub().resolves(container),146 stop: () => { },147 inspect: sinon.stub().yields(null, { State: { Running: false } }),148 });149 res = await startService('service-4', 'test-4', 'docker', opts);150 t.is(typeof res, 'function');151 portscanner.findAPortNotInUse.restore();152 docker.createContainer.restore();153 /* startService5 */154 sinon.stub(portscanner, 'findAPortNotInUse').returns(WS_SERVER_PORT);155 sinon.stub(docker, 'createContainer').resolves({156 start: sinon.stub().resolves(container),157 stop: () => { },158 inspect: sinon.stub().yields(null, { State: { Running: true } }),159 });160 const service = await startService('service-5', 'test-5', 'docker', opts);161 try {162 const res = await service(['echo', '{"passed": true}', ''], 'test-5');163 t.deepEqual(res, { passed: true });164 } catch (error) {165 t.is(error.code, undefined);166 }167 portscanner.findAPortNotInUse.restore();168 docker.createContainer.restore();169 /* stopService1 */170 opts = {171 docker: { CMD: [] },172 };173 sinon.stub(portscanner, 'findAPortNotInUse').returns(getRandomPort());174 sinon.stub(docker, 'createContainer').resolves({175 start: sinon.stub().resolves(container),176 stop: sinon.stub().resolves(),177 inspect: sinon.stub().yields(null, { State: { Running: true } }),178 });179 await startService('service', 'test', 'docker', opts);180 res = await stopService('service', 'test');181 t.is(res, 'service');182 portscanner.findAPortNotInUse.restore();183 docker.createContainer.restore();184 /* stopService2 */185 sinon.stub(portscanner, 'findAPortNotInUse').returns(getRandomPort());186 sinon.stub(docker, 'createContainer').resolves({187 start: sinon.stub().resolves(container),188 stop: sinon.stub().rejects('error'),189 inspect: sinon.stub().yields(null, { State: { Running: true } }),190 });191 await startService('service', 'test', 'docker', opts);192 res = await stopService('service', 'test');193 t.is(res, 'service');194 portscanner.findAPortNotInUse.restore();195 docker.createContainer.restore();196 /* stopAllServices */197 sinon.stub(portscanner, 'findAPortNotInUse').returns(getRandomPort());198 sinon.stub(docker, 'createContainer').resolves({199 start: sinon.stub().resolves(container),200 stop: () => { },201 inspect: sinon.stub().yields(null, { State: { Running: true } }),202 });203 await startService('service', 'test-1', 'docker', opts);204 await stopAllServices();205 const services = Manager.getServices();206 t.deepEqual(services, {});207 portscanner.findAPortNotInUse.restore();208 docker.createContainer.restore();209});210test.after.always('cleanup stubs', () => {211 return new Promise((resolve) => {212 resolve();213 });...

Full Screen

Full Screen

container-manager-spec.js

Source:container-manager-spec.js Github

copy

Full Screen

1const Q = require("q");2const ContainerManager = require("../container-manager");3const MockDocker = require("./mocks/docker");4const ProjectInfo = require("../project-info");5const asyncTest = (test) => (done) =>6 Promise.resolve(test()).then(done).catch(done);7describe("ContainerManager", () => {8 let docker, containerManager;9 beforeEach(() => {10 docker = new MockDocker();11 containerManager = new ContainerManager(docker, () => {12 // Shim `request` function13 return Q({14 status: 200,15 headers: {},16 body: []17 });18 });19 class MockGithubApi {20 authenticate() { }21 }22 containerManager.GithubApi = MockGithubApi;23 MockGithubApi.prototype.repos = {24 get(args, cb) {25 cb(null, { private: false });26 }27 }28 });29 describe("setup", () => {30 it("creates a new container", asyncTest(async () => {31 const details = new ProjectInfo("user", "owner", "repo");32 spyOn(docker, "createContainer").andCallThrough();33 await containerManager.setup(details, "xxx", {});34 expect(docker.createContainer.callCount).toEqual(1);35 }));36 it("returns the host", asyncTest(async () => {37 const host = await containerManager.setup(new ProjectInfo("user", "owner", "repo"), "xxx", {})38 expect(host).toEqual("firefly-project_user_owner_repo:2441");39 }));40 it("removes a container if it fails", asyncTest(async () => {41 docker.createContainer = async () => new Error();42 try {43 await containerManager.setup(new ProjectInfo("user", "owner", "repo"), "xxx", {});44 // expect failure45 expect(false).toBe(true);46 } catch (e) {47 const containers = await docker.listContainers();48 expect(containers.length).toEqual(0);49 }50 }));51 it("doesn't create two containers for one user/owner/repo", asyncTest(async () => {52 spyOn(docker, "createContainer").andCallThrough();53 await Promise.all([54 containerManager.setup(new ProjectInfo("user", "owner", "repo"), "xxx", {}),55 containerManager.setup(new ProjectInfo("user", "owner", "repo"), "xxx", {})56 ]);57 expect(docker.createContainer.callCount).toEqual(1);58 }));59 it("gives the container a useful name", asyncTest(async () => {60 spyOn(docker, "createContainer").andCallThrough();61 await containerManager.setup(new ProjectInfo("one-one", "twotwo", "three123456three"), "xxx", {});62 expect(docker.createContainer.mostRecentCall.args[0].name).toContain("one-one_twotwo_three123456three");63 }));64 it("throws if there's no container and no github access token or username are given", asyncTest(async () => {65 try {66 await containerManager.setup(new ProjectInfo("user", "owner", "repo"))67 expect(false).toBe(true);68 } catch (e) {69 const containers = await docker.listContainers();70 expect(containers.length).toEqual(0);71 }72 }));73 it("creates a subdomain for the details", asyncTest(async () => {74 const details = new ProjectInfo("user", "owner", "repo");75 await containerManager.setup(details, "xxx", {});76 expect(typeof details.toPath()).toEqual("string");77 }));78 });...

Full Screen

Full Screen

docker-container.spec.js

Source:docker-container.spec.js Github

copy

Full Screen

1import './test.boot';2import sinon from 'sinon';3import DockerContainer from '../src/docker-container';4import Docker from 'dockerode-promise';5import chai, {expect} from 'chai';6import Promise from 'bluebird';7describe("DockerContainer", () => {8 const imageName = "a/b";9 const sandbox = sinon.sandbox.create();10 let docker;11 beforeEach(() => {12 docker = sandbox.stub(Docker.prototype);13 docker.pull.returns(Promise.resolve());14 });15 afterEach(() => {16 sandbox.restore();17 });18 const fakeContainer = {};19 const containerName = "a";20 const run = options => {21 const container = new DockerContainer({docker: new Docker(), imageName, containerName});22 return container.run(options || {})23 .then(() => container) };24 beforeEach("initialize a fake controller", () => {25 docker.createContainer.returns(Promise.resolve(fakeContainer));26 fakeContainer.start = sandbox.stub();27 fakeContainer.start.returns(Promise.resolve());28 });29 describe("run", () => {30 it("creates and starts a container", () => run()31 .then(container => expect(container.isRunning()).to.be.true)32 .then(() => expect(docker.createContainer).to.be.calledWithMatch({name: containerName, Image: imageName}))33 .then(() => expect(fakeContainer.start).to.be.called));34 it("passes port bindings to the container's start method", () => run({ports: {from: 1000, to: 2000}})35 .then(() => expect(fakeContainer.start).to.be.calledWith({"PortBindings": {"1000/tcp": [{HostPort: "2000"}]}})));36 it("passes environment variables to the container", () => run({env: {a: 'b', c: 'd'}})37 .then(() => expect(docker.createContainer).to.be.calledWithMatch({Env: ["a=b", "c=d"]})));38 it("passes links to the container", () => run({links: {"containerName": "nameInTarget"}})39 .then(() => expect(docker.createContainer).to.be.calledWithMatch({HostConfig: {Links: ["containerName:nameInTarget"]}})));40 it("passes volumes and binds to the container", () => run({volumes: {"/guestDir": "/hostDir"}})41 .then(() => expect(docker.createContainer).to.be.calledWithMatch({Volumes: {"/guestDir": {}}, HostConfig: {Binds: ["/hostDir:/guestDir"]}})));42 it("passes PublishAllPorts to createContainer", () => run({publishAllPorts: true})43 .then(() => expect(docker.createContainer).to.be.calledWithMatch({HostConfig: {PublishAllPorts: true}})));44 });45 it("returns a mapping of container to host ports", () => {46 fakeContainer.inspect = sandbox.stub();47 fakeContainer.inspect.returns(Promise.resolve({48 "NetworkSettings": {49 "Ports": {50 "80/tcp": [51 {52 "HostPort": 808053 }54 ]55 }56 }57 }));58 return run()59 .then(container => container.getPortMappings())60 .then(mappings => expect(mappings).to.eql({80: 8080}));61 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const docker = require('qawolf/src/docker');2const container = await docker.createContainer();3console.log(container);4const docker = require('qawolf/src/docker');5const container = await docker.createContainer();6console.log(container);7const docker = require('qawolf/src/docker');8const container = await docker.createContainer();9console.log(container);10const docker = require('qawolf/src/docker');11const container = await docker.createContainer();12console.log(container);13const docker = require('qawolf/src/docker');14const container = await docker.createContainer();15console.log(container);16const docker = require('qawolf/src/docker');17const container = await docker.createContainer();18console.log(container);19const docker = require('qawolf/src/docker');20const container = await docker.createContainer();21console.log(container);22const docker = require('qawolf/src/docker');23const container = await docker.createContainer();24console.log(container);25const docker = require('qawolf/src/docker');26const container = await docker.createContainer();27console.log(container);28const docker = require('qawolf/src/docker');29const container = await docker.createContainer();30console.log(container);31const docker = require('qawolf/src/docker');32const container = await docker.createContainer();33console.log(container);34const docker = require('qawolf/src/docker');35const container = await docker.createContainer();36console.log(container);37const docker = require('qawolf/src/docker');38const container = await docker.createContainer();39console.log(container);

Full Screen

Using AI Code Generation

copy

Full Screen

1const docker = require('dockerode')({2});3docker.createContainer({4 HostConfig: {5 }6}).then(container => container.start());7{8 "scripts": {9 }10}11{12 "scripts": {13 }14}15{16 "scripts": {17 }18}19{20 "scripts": {21 }22}

Full Screen

Using AI Code Generation

copy

Full Screen

1const qawolf = require('qawolf');2const docker = require('dockerode')();3const dockerOptions = {4 HostConfig: {5 }6};7docker.createContainer(dockerOptions, (err, container) => {8 if (err) return console.log(err);9 container.start((err, data) => {10 if (err) return console.log(err);11 console.log(data);12 });13});14const qawolf = require('qawolf');15const docker = require('dockerode')();16const dockerOptions = {17 HostConfig: {18 }19};20docker.createContainer(dockerOptions, (err, container) => {21 if (err) return console.log(err);22 container.start((err, data) => {23 if (err) return console.log(err);24 browser.close()25 );26 });27});

Full Screen

Using AI Code Generation

copy

Full Screen

1const docker = require('dockerode')();2docker.createContainer({3 HostConfig: {4 }5}, function (err, container) {6 container.start(function (err, data) {7 console.log(data);8 });9});

Full Screen

Using AI Code Generation

copy

Full Screen

1const { docker } = require('qawolf');2const dockerConfig = {3};4const runTests = async () => {5 await docker.createContainer(dockerConfig);6 await docker.startContainer(dockerConfig);7 await docker.stopContainer(dockerConfig);8};9runTests();10dockerConfig = {11};12dockerConfig = {

Full Screen

Using AI Code Generation

copy

Full Screen

1const qawolf = require("qawolf");2const docker = require("dockerode")();3(async () => {4 const container = await docker.createContainer({5 });6 await container.start();7 const browser = await qawolf.launch({ containerId: container.id });8 const context = await browser.newContext();

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run qawolf automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful