docker/test/test.nonci.ts

120 lines
3.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';
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
2020-09-30 16:51:03 +00:00
if (process.env.CI) {
2020-09-30 17:01:30 +00:00
tap.test('ci placeholder', async () => {});
2020-09-30 16:56:39 +00:00
tap.start();
2020-09-30 16:51:03 +00:00
process.exit(0);
}
2018-07-16 21:52:50 +00:00
tap.test('should create a new Dockersock instance', async () => {
2019-09-08 17:22:20 +00:00
testDockerHost = new docker.DockerHost('http://unix:/var/run/docker.sock:');
2019-08-15 16:50:13 +00:00
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-09-08 17:22:20 +00:00
await testDockerHost.activateSwarm();
2019-09-08 14:34:26 +00:00
});
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, {
2020-09-30 16:35:24 +00:00
Name: 'webgateway',
2019-08-15 16:50:13 +00:00
});
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',
2020-09-30 16:35:24 +00:00
imageTag: 'alpine',
2019-08-15 16:50:13 +00:00
});
expect(image).to.be.instanceOf(docker.DockerImage);
console.log(image);
});
2020-09-30 16:35:24 +00:00
tap.test('should return a change Observable', async (tools) => {
2019-01-09 23:24:35 +00:00
const testObservable = await testDockerHost.getEventObservable();
2020-09-30 16:35:24 +00:00
const subscription = testObservable.subscribe((changeObject) => {
2019-01-09 23:24:35 +00:00
console.log(changeObject);
});
await tools.delayFor(2000);
subscription.unsubscribe();
});
2017-04-02 10:05:29 +00:00
2019-09-12 12:45:36 +00:00
// SECRETS
tap.test('should create a secret', async () => {
const mySecret = await docker.DockerSecret.createSecret(testDockerHost, {
name: 'testSecret',
2019-09-13 12:40:38 +00:00
version: '1.0.3',
2019-09-12 12:45:36 +00:00
contentArg: `{ "hi": "wow"}`,
2020-09-30 16:35:24 +00:00
labels: {},
2019-09-12 12:45:36 +00:00
});
console.log(mySecret);
});
tap.test('should remove a secret by name', async () => {
const mySecret = await docker.DockerSecret.getSecretByName(testDockerHost, 'testSecret');
await mySecret.remove();
});
2019-08-16 10:48:40 +00:00
// SERVICES
tap.test('should activate swarm mode', async () => {
await testDockerHost.activateSwarm();
});
2020-09-30 16:35:24 +00:00
tap.test('should list all services', async (tools) => {
2019-09-08 17:22:20 +00:00
const services = await testDockerHost.getServices();
2019-08-16 10:48:40 +00:00
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, {
2020-09-30 16:35:24 +00:00
Name: 'testNetwork',
2019-08-16 16:21:55 +00:00
});
2019-09-12 12:45:36 +00:00
const testSecret = await docker.DockerSecret.createSecret(testDockerHost, {
2019-09-20 14:29:43 +00:00
name: 'testSecret',
2019-09-13 12:40:38 +00:00
version: '0.0.1',
2019-09-12 12:45:36 +00:00
labels: {},
2020-09-30 16:35:24 +00:00
contentArg: '{"hi": "wow"}',
2019-09-12 12:45:36 +00:00
});
2019-09-13 14:57:21 +00:00
const testImage = await docker.DockerImage.createFromRegistry(testDockerHost, {
2020-09-30 16:35:24 +00:00
imageUrl: 'registry.gitlab.com/hosttoday/ht-docker-static',
2019-09-13 14:57:21 +00:00
});
const testService = await docker.DockerService.createService(testDockerHost, {
image: testImage,
2019-09-20 14:29:43 +00:00
labels: {},
2019-09-13 12:40:38 +00:00
name: 'testService',
2019-08-16 16:32:41 +00:00
networks: [testNetwork],
2019-09-12 12:45:36 +00:00
networkAlias: 'testService',
2019-09-13 20:37:38 +00:00
secrets: [testSecret],
2020-09-30 16:35:24 +00:00
ports: ['3000:80'],
2019-08-16 12:46:48 +00:00
});
2019-09-12 12:45:36 +00:00
2019-09-08 17:22:20 +00:00
await testService.remove();
await testNetwork.remove();
2019-09-12 12:45:36 +00:00
await testSecret.remove();
2019-08-16 12:46:48 +00:00
});
2018-07-16 21:52:50 +00:00
tap.start();