Skip to content
Snippets Groups Projects
Select Git revision
  • aca00a138c9e59d028eb3e2e43c65ca29091a255
  • master default protected
  • bugfix/error-on-not-found-network
  • 5.0.2
  • 5.0.1
  • 5.0.0
  • 4.1.2
  • 4.1.1
  • 4.1.0
  • 4.0.0
  • 3.13.0
  • 3.12.2
  • 3.12.1
  • 3.12.0
  • 3.11.0
  • 3.10.1
  • 3.10.0
  • 3.9.2
  • 3.9.0
  • 3.8.1
  • 3.8.0
  • 3.7.1
  • 3.7.0
23 results

driver.go

Blame
  • docker.spec.js 2.85 KiB
    const got = require('got');
    const docker = require('../../lib/datasource/docker');
    
    jest.mock('got');
    
    describe('api/docker', () => {
      describe('getDigest', () => {
        beforeEach(() => {
          jest.resetAllMocks();
        });
        it('returns null if no token', async () => {
          got.mockReturnValueOnce({ body: {} });
          const res = await docker.getDigest(
            { depName: 'some-dep' },
            'some-new-value'
          );
          expect(res).toBe(null);
        });
        it('returns null if errored', async () => {
          got.mockReturnValueOnce({ body: { token: 'some-token' } });
          const res = await docker.getDigest(
            { depName: 'some-dep' },
            'some-new-value'
          );
          expect(res).toBe(null);
        });
        it('returns digest', async () => {
          got.mockReturnValueOnce({ body: { token: 'some-token' } });
          got.mockReturnValueOnce({
            headers: { 'docker-content-digest': 'some-digest' },
          });
          const res = await docker.getDigest(
            { depName: 'some-dep' },
            'some-new-value'
          );
          expect(res).toBe('some-digest');
        });
        it('supports scoped names', async () => {
          got.mockReturnValueOnce({ body: { token: 'some-token' } });
          got.mockReturnValueOnce({
            headers: { 'docker-content-digest': 'some-digest' },
          });
          const res = await docker.getDigest(
            { depName: 'some-dep', tagSuffix: 'alpine' },
            '8.0.0'
          );
          expect(res).toBe('some-digest');
        });
      });
      describe('getDependency', () => {
        it('returns null if no token', async () => {
          got.mockReturnValueOnce({ body: {} });
          const res = await docker.getDependency({
            fullname: 'node',
            qualifiers: {},
          });
          expect(res).toBe(null);
        });
        it('returns tags with no suffix', async () => {
          const tags = ['a', 'b', '1.0.0', '1.1.0', '1.1.0-alpine'];
          got.mockReturnValueOnce({ headers: {}, body: { token: 'some-token ' } });
          got.mockReturnValueOnce({ headers: {}, body: { tags } });
          const res = await docker.getDependency({
            fullname: 'my/node',
            qualifiers: {},
          });
          expect(res).toMatchSnapshot();
          expect(res.releases).toHaveLength(3);
        });
        it('returns tags with suffix', async () => {
          const tags = ['a', 'b', '1.0.0', '1.1.0-alpine'];
          got.mockReturnValueOnce({ headers: {}, body: { token: 'some-token ' } });
          got.mockReturnValueOnce({ headers: {}, body: { tags } });
          const res = await docker.getDependency({
            fullname: 'my/node',
            qualifiers: { suffix: 'alpine' },
          });
          expect(res).toMatchSnapshot();
          expect(res.releases).toHaveLength(1);
        });
        it('returns null on error', async () => {
          got.mockReturnValueOnce({});
          const res = await docker.getDependency({
            fullname: 'my/node',
            qualifiers: {},
          });
          expect(res).toBe(null);
        });
      });
    });