UNPKG

navy

Version:

Quick and powerful development environments using Docker and Docker Compose

67 lines (65 loc) 2.22 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); var _chai = require("chai"); var _sinon = _interopRequireDefault(require("sinon")); var _proxyquire = _interopRequireDefault(require("proxyquire")); var _ociApiSpecification = require("../../../domain/oci-api-specification"); /* eslint-env mocha */ function fakeResponse({ digest, body }) { return { headers: { get: name => name === 'docker-content-digest' ? digest : null }, json: async () => body }; } function loadModule(getEndpointStub) { return _proxyquire.default.noCallThru()('../get-fat-manifest', { './get-endpoint': getEndpointStub }); } describe('get-fat-manifest', function () { it('should call getEndpoint with the manifest path and the FAT_MANIFEST accept header', async function () { const getEndpoint = _sinon.default.stub().resolves(fakeResponse({ digest: 'sha256:abc', body: { manifests: [] } })); const getFatManifest = loadModule(getEndpoint); const result = await getFatManifest({ repository: 'library/node', registry: 'registry-1.docker.io', tag: 'lts' }); (0, _chai.expect)(result).to.eql({ tag: 'sha256:abc', data: { manifests: [] } }); (0, _chai.expect)(getEndpoint.calledOnce).to.equal(true); const args = getEndpoint.firstCall.args[0]; (0, _chai.expect)(args.endpoint).to.equal('library/node/manifests/lts'); (0, _chai.expect)(args.options.headers.Accept).to.equal(_ociApiSpecification.MEDIA_TYPES.FAT_MANIFEST); (0, _chai.expect)(args.allowUnauthorizedRequest).to.equal(false); (0, _chai.expect)(args.registry).to.equal('registry-1.docker.io'); }); it('should propagate allowUnauthorizedRequest=true', async function () { const getEndpoint = _sinon.default.stub().resolves(fakeResponse({ digest: 'd', body: {} })); const getFatManifest = loadModule(getEndpoint); await getFatManifest({ allowUnauthorizedRequest: true, repository: 'org/img', registry: 'r', tag: 't' }); (0, _chai.expect)(getEndpoint.firstCall.args[0].allowUnauthorizedRequest).to.equal(true); }); });