docker/test/test.ts

86 lines
2.4 KiB
TypeScript
Raw Normal View History

2018-07-16 21:52:50 +00:00
import { expect, tap } from '@pushrocks/tapbundle';
2019-08-15 16:50:13 +00:00
import * as docker from '../ts/index';
2019-08-16 12:46:48 +00:00
import { DockerService } from '../ts/index';
2017-04-02 10:05:29 +00:00
2019-08-15 16:50:13 +00:00
let testDockerHost: docker.DockerHost;
2017-04-02 10:05:29 +00:00
2018-07-16 21:52:50 +00:00
tap.test('should create a new Dockersock instance', async () => {
2019-08-15 16:50:13 +00:00
testDockerHost = new docker.DockerHost();
return expect(testDockerHost).to.be.instanceof(docker.DockerHost);
2018-07-16 21:52:50 +00:00
});
2017-04-02 10:05:29 +00:00
2019-09-08 14:34:26 +00:00
tap.test('should create a docker swarm', async () => {
});
2019-08-15 16:50:13 +00:00
// Containers
2018-07-16 21:52:50 +00:00
tap.test('should list containers', async () => {
const containers = await testDockerHost.getContainers();
console.log(containers);
});
2017-04-02 10:05:29 +00:00
2019-08-15 16:50:13 +00:00
// Networks
tap.test('should list networks', async () => {
const networks = await testDockerHost.getNetworks();
console.log(networks);
2018-07-16 21:52:50 +00:00
});
2017-04-02 10:05:29 +00:00
2019-08-15 16:50:13 +00:00
tap.test('should create a network', async () => {
const newNetwork = await docker.DockerNetwork.createNetwork(testDockerHost, {
Name: 'webgateway'
});
expect(newNetwork).to.be.instanceOf(docker.DockerNetwork);
expect(newNetwork.Name).to.equal('webgateway');
});
tap.test('should remove a network', async () => {
const webgateway = await docker.DockerNetwork.getNetworkByName(testDockerHost, 'webgateway');
await webgateway.remove();
});
// Images
tap.test('should pull an image from imagetag', async () => {
const image = await docker.DockerImage.createFromRegistry(testDockerHost, {
imageUrl: 'hosttoday/ht-docker-node',
2019-08-16 12:46:48 +00:00
imageTag: 'alpine'
2019-08-15 16:50:13 +00:00
});
expect(image).to.be.instanceOf(docker.DockerImage);
console.log(image);
});
tap.test('should return a change Observable', async tools => {
2019-01-09 23:24:35 +00:00
const testObservable = await testDockerHost.getEventObservable();
const subscription = testObservable.subscribe(changeObject => {
console.log(changeObject);
});
await tools.delayFor(2000);
subscription.unsubscribe();
});
2017-04-02 10:05:29 +00:00
2019-08-16 10:48:40 +00:00
// SERVICES
tap.test('should activate swarm mode', async () => {
await testDockerHost.activateSwarm();
});
tap.test('should list all services', async tools => {
const services = await docker.DockerService.getServices(testDockerHost);
console.log(services);
});
2019-08-16 12:46:48 +00:00
tap.test('should create a service', async () => {
2019-08-16 16:21:55 +00:00
const testNetwork = await docker.DockerNetwork.createNetwork(testDockerHost, {
Name: 'testNetwork'
});
2019-08-16 12:46:48 +00:00
await DockerService.createService(testDockerHost, {
2019-08-16 16:21:55 +00:00
Image: 'nginx:latest',
2019-08-16 12:46:48 +00:00
Labels: {
'testlabel': 'hi'
},
2019-08-16 16:21:55 +00:00
Name: 'testService',
2019-08-16 16:32:41 +00:00
networks: [testNetwork],
networkAlias: 'testService'
2019-08-16 12:46:48 +00:00
});
});
2018-07-16 21:52:50 +00:00
tap.start();