docker/test/test.nonci.ts

119 lines
3.6 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 17:06:26 +00:00
} else {
tap.test('should create a new Dockersock instance', async () => {
testDockerHost = new docker.DockerHost('http://unix:/var/run/docker.sock:');
return expect(testDockerHost).to.be.instanceof(docker.DockerHost);
2019-08-15 16:50:13 +00:00
});
2020-09-30 17:06:26 +00:00
tap.test('should create a docker swarm', async () => {
await testDockerHost.activateSwarm();
2019-08-15 16:50:13 +00:00
});
2020-09-30 17:06:26 +00:00
// Containers
tap.test('should list containers', async () => {
const containers = await testDockerHost.getContainers();
console.log(containers);
2019-01-09 23:24:35 +00:00
});
2020-09-30 17:06:26 +00:00
// Networks
tap.test('should list networks', async () => {
const networks = await testDockerHost.getNetworks();
console.log(networks);
2019-09-12 12:45:36 +00:00
});
2020-09-30 17:06:26 +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');
2019-08-16 16:21:55 +00:00
});
2020-09-30 17:06:26 +00:00
tap.test('should remove a network', async () => {
const webgateway = await docker.DockerNetwork.getNetworkByName(testDockerHost, 'webgateway');
await webgateway.remove();
2019-09-12 12:45:36 +00:00
});
2020-09-30 17:06:26 +00:00
// Images
tap.test('should pull an image from imagetag', async () => {
const image = await docker.DockerImage.createFromRegistry(testDockerHost, {
imageUrl: 'hosttoday/ht-docker-node',
imageTag: 'alpine',
});
expect(image).to.be.instanceOf(docker.DockerImage);
console.log(image);
2019-09-13 14:57:21 +00:00
});
2020-09-30 17:06:26 +00:00
tap.test('should return a change Observable', async (tools) => {
const testObservable = await testDockerHost.getEventObservable();
const subscription = testObservable.subscribe((changeObject) => {
console.log(changeObject);
});
await tools.delayFor(2000);
subscription.unsubscribe();
2019-08-16 12:46:48 +00:00
});
2020-09-30 17:06:26 +00:00
// SECRETS
tap.test('should create a secret', async () => {
const mySecret = await docker.DockerSecret.createSecret(testDockerHost, {
name: 'testSecret',
version: '1.0.3',
contentArg: `{ "hi": "wow"}`,
labels: {},
});
console.log(mySecret);
});
tap.test('should remove a secret by name', async () => {
const mySecret = await docker.DockerSecret.getSecretByName(testDockerHost, 'testSecret');
await mySecret.remove();
});
// SERVICES
tap.test('should activate swarm mode', async () => {
await testDockerHost.activateSwarm();
});
tap.test('should list all services', async (tools) => {
const services = await testDockerHost.getServices();
console.log(services);
});
tap.test('should create a service', async () => {
const testNetwork = await docker.DockerNetwork.createNetwork(testDockerHost, {
Name: 'testNetwork',
});
const testSecret = await docker.DockerSecret.createSecret(testDockerHost, {
name: 'testSecret',
version: '0.0.1',
labels: {},
contentArg: '{"hi": "wow"}',
});
const testImage = await docker.DockerImage.createFromRegistry(testDockerHost, {
imageUrl: 'registry.gitlab.com/hosttoday/ht-docker-static',
});
const testService = await docker.DockerService.createService(testDockerHost, {
image: testImage,
labels: {},
name: 'testService',
networks: [testNetwork],
networkAlias: 'testService',
secrets: [testSecret],
ports: ['3000:80'],
});
await testService.remove();
await testNetwork.remove();
await testSecret.remove();
});
tap.start();
}