navy
Version:
Quick and powerful development environments using Docker and Docker Compose
81 lines (79 loc) • 4.78 kB
JavaScript
;
var _chai = require("chai");
var _containerImage = require("../container-image");
/* eslint-env mocha */
describe('container-image', function () {
describe('constants', function () {
it('should expose the default registry hostname', function () {
(0, _chai.expect)(_containerImage.DEFAULT_REGISTRY).to.equal('registry-1.docker.io');
});
it('should expose the docker config.json auth URL', function () {
(0, _chai.expect)(_containerImage.DEFAULT_REGISTRY_AUTH).to.equal('https://index.docker.io/v1/');
});
});
describe('getImageFromImageWithTag', function () {
it('should strip the tag from a registry/org/image:tag string', function () {
(0, _chai.expect)((0, _containerImage.getImageFromImageWithTag)('someregistry.com/some/image:latest')).to.equal('someregistry.com/some/image');
});
it('should return the image unchanged when it has slashes but no tag', function () {
(0, _chai.expect)((0, _containerImage.getImageFromImageWithTag)('someregistry.com/some/image')).to.equal('someregistry.com/some/image');
});
it('should strip the tag from a single-segment image:tag string', function () {
(0, _chai.expect)((0, _containerImage.getImageFromImageWithTag)('node:18')).to.equal('node');
});
it('should return a single-segment image unchanged when it has no tag', function () {
(0, _chai.expect)((0, _containerImage.getImageFromImageWithTag)('node')).to.equal('node');
});
it('should not be confused by a colon in the registry port (no tag)', function () {
(0, _chai.expect)((0, _containerImage.getImageFromImageWithTag)('myregistry.local:5000/foo/bar')).to.equal('myregistry.local:5000/foo/bar');
});
it('should strip the tag while preserving the registry port', function () {
(0, _chai.expect)((0, _containerImage.getImageFromImageWithTag)('myregistry.local:5000/foo/bar:1.0')).to.equal('myregistry.local:5000/foo/bar');
});
});
describe('getTagFromImageWithTag', function () {
it('should extract the tag from a registry/org/image:tag string', function () {
(0, _chai.expect)((0, _containerImage.getTagFromImageWithTag)('someregistry.com/some/image:1.2.3')).to.equal('1.2.3');
});
it('should default to "latest" when slashes exist but no tag', function () {
(0, _chai.expect)((0, _containerImage.getTagFromImageWithTag)('someregistry.com/some/image')).to.equal('latest');
});
it('should extract the tag from a single-segment image:tag', function () {
(0, _chai.expect)((0, _containerImage.getTagFromImageWithTag)('node:18-alpine')).to.equal('18-alpine');
});
it('should default to "latest" for a single-segment image with no tag', function () {
(0, _chai.expect)((0, _containerImage.getTagFromImageWithTag)('node')).to.equal('latest');
});
it('should not treat the registry port colon as a tag', function () {
(0, _chai.expect)((0, _containerImage.getTagFromImageWithTag)('myregistry.local:5000/foo/bar')).to.equal('latest');
});
it('should extract the tag with a registry port present', function () {
(0, _chai.expect)((0, _containerImage.getTagFromImageWithTag)('myregistry.local:5000/foo/bar:1.0')).to.equal('1.0');
});
});
describe('getRegistryFromImage', function () {
it('should return the registry from a registry/org/image string', function () {
(0, _chai.expect)((0, _containerImage.getRegistryFromImage)('someregistry.com/some/image')).to.equal('someregistry.com');
});
it('should fall back to the default registry when no registry is present', function () {
(0, _chai.expect)((0, _containerImage.getRegistryFromImage)('library/node')).to.equal(_containerImage.DEFAULT_REGISTRY);
});
it('should fall back to default for an unprefixed image', function () {
(0, _chai.expect)((0, _containerImage.getRegistryFromImage)('node')).to.equal(_containerImage.DEFAULT_REGISTRY);
});
});
describe('getRepositoryFromImage', function () {
it('should prefix a single-segment image with library/', function () {
(0, _chai.expect)((0, _containerImage.getRepositoryFromImage)('node')).to.equal('library/node');
});
it('should strip the registry from a 3-segment image', function () {
(0, _chai.expect)((0, _containerImage.getRepositoryFromImage)('someregistry.com/some/image')).to.equal('some/image');
});
it('should return a 2-segment image unchanged', function () {
(0, _chai.expect)((0, _containerImage.getRepositoryFromImage)('library/node')).to.equal('library/node');
});
it('should return a 4+-segment image unchanged', function () {
(0, _chai.expect)((0, _containerImage.getRepositoryFromImage)('host/a/b/c')).to.equal('host/a/b/c');
});
});
});