knex/test/docker/dockerContainer.js
smulesoft 31ba04a788 fixes #1833 on postgres (#2017)
* fixes #1833 on postgres

* adds @elhigu requested changes

* adds test when database is down

* adds script for docker support

* removes old comment

* fixes syntax

* fixes more syntax errors

* fixes final syntax errors

* Docker testing enabled only on linux for now
2017-06-01 22:41:35 +03:00

60 lines
1.2 KiB
JavaScript

'use strict';
var Promise = require('bluebird');
function DockerContainer(docker, name, image, options) {
this.container = docker.createContainer(name, image, options);
}
/**
* @returns {Promise}
*/
DockerContainer.prototype.start = function () {
var self = this;
return self.container.then(function (c) {
return c.start().then(function () {
console.log('#~ Started container', c.id);
return self.waitReady();
})
})
};
/**
* @returns {Promise}
*/
DockerContainer.prototype.waitReady = function () {
return Promise.resolve(this);
}
/**
* @returns {Promise}
*/
DockerContainer.prototype.stop = function () {
return this.container.then(function (c) {
return c.stop().then(function () {
console.log('#~ Stopped container', c.id);
})
.catch(function (err) {
if (err.statusCode !== 304) {
throw err;
}
});
});
}
/**
* @returns {Promise}
*/
DockerContainer.prototype.destroy = function () {
var self = this;
return self.stop().then(function () {
return self.container.then(function (c) {
return c.remove().then(function () {
console.log('#~ Removed container', c.id);
});
});
});
}
module.exports = DockerContainer;