openWa / src /modules /docker /docker.service.spec.ts
harsh
Deploy: Initial commit without binaries
525d39f
Raw History Blame Contribute Delete
1.25 kB
import { DockerService } from './docker.service';
// Prevent actual Docker connections on module init during tests
jest.mock('dockerode');
describe('DockerService.buildDockerOptions', () => {
let service: DockerService;
const originalDockerHost = process.env.DOCKER_HOST;
beforeEach(() => {
service = new DockerService();
});
afterEach(() => {
if (originalDockerHost === undefined) {
delete process.env.DOCKER_HOST;
} else {
process.env.DOCKER_HOST = originalDockerHost;
}
});
it('returns TCP options when DOCKER_HOST is set to tcp://host:port', () => {
process.env.DOCKER_HOST = 'tcp://docker-proxy:2375';
expect(service.buildDockerOptions()).toEqual({
host: 'docker-proxy',
port: 2375,
protocol: 'http',
});
});
it('falls back to unix socket when DOCKER_HOST is not set', () => {
delete process.env.DOCKER_HOST;
expect(service.buildDockerOptions()).toEqual({
socketPath: '/var/run/docker.sock',
});
});
it('falls back to unix socket for unsupported DOCKER_HOST schemes', () => {
process.env.DOCKER_HOST = 'unix:///run/docker.sock';
expect(service.buildDockerOptions()).toEqual({
socketPath: '/var/run/docker.sock',
});
});
});