add tests with in docker

This commit is contained in:
Philipp Kunz 2016-06-16 04:18:10 +02:00
parent c58dad05cd
commit 49e7cc010b
7 changed files with 61 additions and 27 deletions

View File

@ -1,4 +1,6 @@
FROM hosttoday/ht-docker-node:lts
COPY ./node_modules /app-node/node_modules
COPY ./dist /app-node/dist
FROM hosttoday/ht-docker-node:npmts
RUN mkdir app-node
COPY ./ /app-node/
WORKDIR /app-node
ENV CI true
CMD ["npmts"]

File diff suppressed because one or more lines are too long

View File

@ -12,11 +12,7 @@ nginx2:
container_name: nginx2
npmts-test-container:
image: "npmts-test-image"
ports:
- "80:80"
- "443:443"
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
env_file: "nogit/nogit.env"
restart: always
container_name: npmts-test-container

View File

@ -4,7 +4,10 @@
"description": "easy communication with docker from node, TypeScript ready",
"main": "dist/index.js",
"scripts": {
"test": "npmts testindocker"
"test": "npmts --notest && npm run cleanup && npm run build && npm run startdocker",
"build": "docker build -t npmts-test-image .",
"startdocker":"docker run -v /var/run/docker.sock:/var/run/docker.sock --name npmts-test-container npmts-test-image",
"cleanup":"docker rm npmts-test-container && docker rmi npmts-test-image"
},
"repository": {
"type": "git",

View File

@ -9,7 +9,22 @@ describe("dockersock", function () {
testDockersock = new index_1.Dockersock();
testDockersock.should.be.instanceof(index_1.Dockersock);
});
it("should list containers", function (done) {
testDockersock.listContainers()
.then(function (dataArg) {
console.log(dataArg);
done();
});
});
it("should list detailed containers", function (done) {
this.timeout(5000);
testDockersock.listContainersDetailed()
.then(function (dataArg) {
console.log(dataArg);
done();
});
});
});
});
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sY0FBYyxDQUFDLENBQUE7QUFDdEIsUUFBTyxRQUVQLENBQUMsQ0FGYztBQUVmLHNCQUF5QixlQUV6QixDQUFDLENBRnVDO0FBRXhDLFF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iwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IFwidHlwaW5ncy10ZXN0XCI7XG5pbXBvcnQgXCJzaG91bGRcIlxuXG5pbXBvcnQge0RvY2tlcnNvY2t9IGZyb20gXCIuLi9kaXN0L2luZGV4XCJcblxuZGVzY3JpYmUoXCJkb2NrZXJzb2NrXCIsZnVuY3Rpb24oKXtcbiAgICBkZXNjcmliZShcIi5Eb2NrZXJzb2NrKClcIixmdW5jdGlvbigpe1xuICAgICAgICBsZXQgdGVzdERvY2tlcnNvY2s6RG9ja2Vyc29jaztcbiAgICAgICAgaXQoXCJzaG91bGQgY3JlYXRlIGEgbmV3IERvY2tlcnNvY2sgaW5zdGFuY2VcIixmdW5jdGlvbigpe1xuICAgICAgICAgICAgdGVzdERvY2tlcnNvY2sgPSBuZXcgRG9ja2Vyc29jaygpO1xuICAgICAgICAgICAgdGVzdERvY2tlcnNvY2suc2hvdWxkLmJlLmluc3RhbmNlb2YoRG9ja2Vyc29jayk7XG4gICAgICAgIH0pO1xuICAgICAgICBpdChcInNob3VsZCBsaXN0IGNvbnRhaW5lcnNcIixmdW5jdGlvbihkb25lKXtcbiAgICAgICAgICAgIHRlc3REb2NrZXJzb2NrLmxpc3RDb250YWluZXJzKClcbiAgICAgICAgICAgICAgICAudGhlbigoZGF0YUFyZyk9PntcbiAgICAgICAgICAgICAgICAgICAgY29uc29sZS5sb2coZGF0YUFyZyk7XG4gICAgICAgICAgICAgICAgICAgIGRvbmUoKTtcbiAgICAgICAgICAgICAgICB9KTtcbiAgICAgICAgfSk7XG4gICAgICAgIGl0KFwic2hvdWxkIGxpc3QgZGV0YWlsZWQgY29udGFpbmVyc1wiLGZ1bmN0aW9uKGRvbmUpe1xuICAgICAgICAgICAgdGhpcy50aW1lb3V0KDUwMDApO1xuICAgICAgICAgICAgdGVzdERvY2tlcnNvY2subGlzdENvbnRhaW5lcnNEZXRhaWxlZCgpXG4gICAgICAgICAgICAgICAgLnRoZW4oKGRhdGFBcmcpPT57XG4gICAgICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKGRhdGFBcmcpO1xuICAgICAgICAgICAgICAgICAgICBkb25lKCk7XG4gICAgICAgICAgICAgICAgfSk7XG4gICAgICAgIH0pO1xuICAgIH0pO1xufSk7Il19

View File

@ -10,5 +10,20 @@ describe("dockersock",function(){
testDockersock = new Dockersock();
testDockersock.should.be.instanceof(Dockersock);
});
it("should list containers",function(done){
testDockersock.listContainers()
.then((dataArg)=>{
console.log(dataArg);
done();
});
});
it("should list detailed containers",function(done){
this.timeout(5000);
testDockersock.listContainersDetailed()
.then((dataArg)=>{
console.log(dataArg);
done();
});
});
});
});

View File

@ -20,19 +20,20 @@ export class Dockersock {
this.listContainers()
.then((dataArg) => {
let recursiveCounter = 0;
let makeDetailed = function(){
if(typeof dataArg[recursiveCounter] != "undefined"){
this.request.get("GET","/containers/" + dataArg[recursiveCounter].Id)
.then((data) => {
recursiveCounter++;
detailedDataObject.push(data);
makeDetailed();
});
} else {
done.resolve(detailedDataObject);
}
};
makeDetailed();
let makeDetailed = () => {
if(typeof dataArg[recursiveCounter] != "undefined"){
this.request("GET","/containers/" + dataArg[recursiveCounter].Id)
.then((dataArg2) => {
detailedDataObject.push(dataArg2);
recursiveCounter++;
// recursive call
makeDetailed();
});
} else {
done.resolve(detailedDataObject);
}
};
makeDetailed();
});
return done.promise;
};
@ -64,7 +65,7 @@ export class Dockersock {
},
body:jsonArg
};
plugins.request(options,function(err, res, body){
plugins.request(options,(err, res, body) => {
if (!err && res.statusCode == 200) {
var responseObj = JSON.parse(body);
done.resolve(responseObj);