Skip to content
Snippets Groups Projects
Select Git revision
  • 65d0f3569cfb31b5896af26333f446bfb058c47d
  • main default protected
  • release/v2.6.x
  • dependabot/github_actions/ci-3649212e03
  • conform-k8s-1.33
  • rfc-external-artifact
  • release/v2.5.x
  • release/v2.4.x
  • remove-notation-validation
  • release/v2.3.x
  • release/v2.2.x
  • RFC
  • fix-commit-log
  • flux-audit
  • release/v2.1.x
  • context-ns
  • ksm-dashboard
  • rfc-passwordless-git-auth
  • release/v2.0.x
  • rfc-gating
  • release/v0.27.4
  • v2.6.2 protected
  • v2.6.1 protected
  • v2.6.0 protected
  • v2.5.1 protected
  • v2.5.0 protected
  • v2.4.0 protected
  • v2.3.0 protected
  • v2.2.3 protected
  • v2.2.2 protected
  • v2.2.1 protected
  • v2.2.0 protected
  • v2.1.2 protected
  • v2.1.1 protected
  • v2.1.0 protected
  • v2.0.1 protected
  • v2.0.0 protected
  • v2.0.0-rc.5 protected
  • v2.0.0-rc.4 protected
  • v2.0.0-rc.3 protected
  • v2.0.0-rc.2 protected
41 results

installation.md

Blame
  • artifacts.spec.ts 8.66 KiB
    import { join } from 'upath';
    import { envMock, exec, mockExecAll } from '../../../../test/exec-util';
    import { env, fs, git, mocked } from '../../../../test/util';
    import { GlobalConfig } from '../../../config/global';
    import type { RepoGlobalConfig } from '../../../config/types';
    import * as docker from '../../../util/exec/docker';
    import * as _hostRules from '../../../util/host-rules';
    import type { UpdateArtifactsConfig } from '../types';
    import * as nuget from './artifacts';
    import * as util from './util';
    
    jest.mock('child_process');
    jest.mock('../../../util/exec/env');
    jest.mock('../../../util/fs');
    jest.mock('../../../util/host-rules');
    jest.mock('../../../util/git');
    jest.mock('./util');
    
    const { getConfiguredRegistries, getDefaultRegistries, getRandomString } =
      mocked(util);
    const hostRules = mocked(_hostRules);
    
    const adminConfig: RepoGlobalConfig = {
      // `join` fixes Windows CI
      localDir: join('/tmp/github/some/repo'),
      cacheDir: join('/tmp/renovate/cache'),
    };
    
    const config: UpdateArtifactsConfig = {};
    
    describe('modules/manager/nuget/artifacts', () => {
      beforeEach(() => {
        jest.resetAllMocks();
        jest.resetModules();
        getDefaultRegistries.mockReturnValue([]);
        env.getChildProcessEnv.mockReturnValue(envMock.basic);
        fs.ensureCacheDir.mockImplementation((dirName: string) =>
          Promise.resolve(`others/${dirName}`)
        );
        git.getFileList.mockResolvedValueOnce([]);
        getRandomString.mockReturnValue('not-so-random');
        GlobalConfig.set(adminConfig);
        docker.resetPrefetchedImages();
      });
    
      afterEach(() => {
        GlobalConfig.reset();
      });
    
      it('aborts if no lock file found', async () => {
        const execSnapshots = mockExecAll(exec);
        fs.getSiblingFileName.mockReturnValueOnce('packages.lock.json');
        expect(
          await nuget.updateArtifacts({
            packageFileName: 'project.csproj',
            updatedDeps: [{ depName: 'foo' }, { depName: 'bar' }],
            newPackageFileContent: '{}',
            config,
          })
        ).toBeNull();
        expect(execSnapshots).toBeEmptyArray();
      });
    
      it('aborts if lock file is unchanged', async () => {
        const execSnapshots = mockExecAll(exec);
        fs.getSiblingFileName.mockReturnValueOnce(
          'path/with space/packages.lock.json'
        );
        fs.readLocalFile.mockResolvedValueOnce('Current packages.lock.json');
        fs.readLocalFile.mockResolvedValueOnce('Current packages.lock.json');
        expect(
          await nuget.updateArtifacts({
            packageFileName: 'path/with space/project.csproj',
            updatedDeps: [{ depName: 'foo' }, { depName: 'bar' }],
            newPackageFileContent: '{}',
            config,
          })
        ).toBeNull();
        expect(execSnapshots).toMatchSnapshot();
      });
    
      it('updates lock file', async () => {
        const execSnapshots = mockExecAll(exec);
        fs.getSiblingFileName.mockReturnValueOnce('packages.lock.json');
        fs.readLocalFile.mockResolvedValueOnce('Current packages.lock.json');
        fs.readLocalFile.mockResolvedValueOnce('New packages.lock.json');
        expect(
          await nuget.updateArtifacts({
            packageFileName: 'project.csproj',
            updatedDeps: [{ depName: 'dep' }],
            newPackageFileContent: '{}',
            config,
          })
        ).not.toBeNull();
        expect(execSnapshots).toMatchSnapshot();
      });
    
      it('does not update lock file when non-proj file is changed', async () => {
        const execSnapshots = mockExecAll(exec);
        fs.getSiblingFileName.mockReturnValueOnce('packages.lock.json');
        fs.readLocalFile.mockResolvedValueOnce('Current packages.lock.json');
        fs.readLocalFile.mockResolvedValueOnce('New packages.lock.json');
        expect(
          await nuget.updateArtifacts({
            packageFileName: 'otherfile.props',
            updatedDeps: [{ depName: 'dep' }],
            newPackageFileContent: '{}',
            config,
          })
        ).toBeNull();
        expect(execSnapshots).toBeEmptyArray();
      });
    
      it('does not update lock file when no deps changed', async () => {
        const execSnapshots = mockExecAll(exec);
        fs.getSiblingFileName.mockReturnValueOnce('packages.lock.json');
        fs.readLocalFile.mockResolvedValueOnce('Current packages.lock.json');
        fs.readLocalFile.mockResolvedValueOnce('New packages.lock.json');
        expect(
          await nuget.updateArtifacts({
            packageFileName: 'project.csproj',
            updatedDeps: [],
            newPackageFileContent: '{}',
            config,
          })
        ).toBeNull();
        expect(execSnapshots).toBeEmptyArray();
      });
    
      it('performs lock file maintenance', async () => {
        const execSnapshots = mockExecAll(exec);
        fs.getSiblingFileName.mockReturnValueOnce('packages.lock.json');
        fs.readLocalFile.mockResolvedValueOnce('Current packages.lock.json');
        fs.readLocalFile.mockResolvedValueOnce('New packages.lock.json');
        expect(
          await nuget.updateArtifacts({
            packageFileName: 'project.csproj',
            updatedDeps: [],
            newPackageFileContent: '{}',
            config: {
              ...config,
              isLockFileMaintenance: true,
            },
          })
        ).not.toBeNull();
        expect(execSnapshots).toMatchSnapshot();
      });
    
      it('supports docker mode', async () => {
        GlobalConfig.set({ ...adminConfig, binarySource: 'docker' });
        const execSnapshots = mockExecAll(exec);
        fs.getSiblingFileName.mockReturnValueOnce('packages.lock.json');
        fs.readLocalFile.mockResolvedValueOnce('Current packages.lock.json');
        fs.readLocalFile.mockResolvedValueOnce('New packages.lock.json');
        expect(
          await nuget.updateArtifacts({
            packageFileName: 'project.csproj',
            updatedDeps: [{ depName: 'dep' }],
            newPackageFileContent: '{}',
            config,
          })
        ).not.toBeNull();
        expect(execSnapshots).toMatchSnapshot();
      });
    
      it('supports global mode', async () => {
        GlobalConfig.set({ ...adminConfig, binarySource: 'global' });
        const execSnapshots = mockExecAll(exec);
        fs.getSiblingFileName.mockReturnValueOnce('packages.lock.json');
        fs.readLocalFile.mockResolvedValueOnce('Current packages.lock.json');
        fs.readLocalFile.mockResolvedValueOnce('New packages.lock.json');
        expect(
          await nuget.updateArtifacts({
            packageFileName: 'project.csproj',
            updatedDeps: [{ depName: 'dep' }],
            newPackageFileContent: '{}',
            config,
          })
        ).not.toBeNull();
        expect(execSnapshots).toMatchSnapshot();
      });
    
      it('catches errors', async () => {
        fs.getSiblingFileName.mockReturnValueOnce('packages.lock.json');
        fs.readLocalFile.mockResolvedValueOnce('Current packages.lock.json');
        fs.writeLocalFile.mockImplementationOnce(() => {
          throw new Error('not found');
        });
        expect(
          await nuget.updateArtifacts({
            packageFileName: 'project.csproj',
            updatedDeps: [{ depName: 'dep' }],
            newPackageFileContent: '{}',
            config,
          })
        ).toEqual([
          {
            artifactError: {
              lockFile: 'packages.lock.json',
              stderr: 'not found',
            },
          },
        ]);
      });
    
      it('authenticates at registries', async () => {
        const execSnapshots = mockExecAll(exec);
        fs.getSiblingFileName.mockReturnValueOnce('packages.lock.json');
        fs.readLocalFile.mockResolvedValueOnce('Current packages.lock.json');
        fs.readLocalFile.mockResolvedValueOnce('New packages.lock.json');
        getConfiguredRegistries.mockResolvedValueOnce([
          {
            name: 'myRegistry',
            url: 'https://my-registry.example.org',
          },
        ] as never);
        hostRules.find.mockImplementationOnce((search) => {
          if (
            search.hostType === 'nuget' &&
            search.url === 'https://my-registry.example.org'
          ) {
            return {
              username: 'some-username',
              password: 'some-password',
            };
          }
          return undefined;
        });
        expect(
          await nuget.updateArtifacts({
            packageFileName: 'project.csproj',
            updatedDeps: [{ depName: 'dep' }],
            newPackageFileContent: '{}',
            config,
          })
        ).not.toBeNull();
        expect(execSnapshots).toMatchSnapshot();
      });
    
      it('strips protocol version from feed url', async () => {
        const execSnapshots = mockExecAll(exec);
        fs.getSiblingFileName.mockReturnValueOnce('packages.lock.json');
        fs.readLocalFile.mockResolvedValueOnce('Current packages.lock.json');
        fs.readLocalFile.mockResolvedValueOnce('New packages.lock.json');
        getConfiguredRegistries.mockResolvedValueOnce([
          {
            name: 'myRegistry',
            url: 'https://my-registry.example.org#protocolVersion=3',
          },
        ] as never);
        hostRules.find.mockImplementationOnce(() => ({}));
        expect(
          await nuget.updateArtifacts({
            packageFileName: 'project.csproj',
            updatedDeps: [{ depName: 'dep' }],
            newPackageFileContent: '{}',
            config,
          })
        ).not.toBeNull();
        expect(execSnapshots).toMatchSnapshot();
      });
    });