Skip to content

Commit

Permalink
refactor: strict manager tests (#16155)
Browse files Browse the repository at this point in the history
* refactor: strict manager tests

* chore: revert changes

* Update lib/modules/manager/gradle/extract.spec.ts
  • Loading branch information
viceice committed Jun 20, 2022
1 parent 7cb98e1 commit b431992
Show file tree
Hide file tree
Showing 100 changed files with 950 additions and 867 deletions.
25 changes: 13 additions & 12 deletions lib/modules/manager/ansible-galaxy/extract.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { loadFixture } from '../../../../test/util';
import { extractPackageFile, getSliceEndNumber } from './extract';
import { getSliceEndNumber } from './extract';
import { extractPackageFile } from './';

const yamlFile1 = loadFixture('requirements01.yml');
const yamlFile2 = loadFixture('requirements02.yml');
Expand All @@ -16,14 +17,14 @@ describe('modules/manager/ansible-galaxy/extract', () => {

it('extracts multiple dependencies from requirements.yml', () => {
const res = extractPackageFile(yamlFile1, 'requirements.yml');
expect(res.deps).toMatchSnapshot();
expect(res.deps).toHaveLength(12);
expect(res?.deps).toMatchSnapshot();
expect(res?.deps).toHaveLength(12);
});

it('extracts dependencies from a not beautified requirements file', () => {
const res = extractPackageFile(yamlFile2, 'requirements.yml');
expect(res.deps).toMatchSnapshot();
expect(res.deps).toHaveLength(2);
expect(res?.deps).toMatchSnapshot();
expect(res?.deps).toHaveLength(2);
});

it('check if an empty file returns null', () => {
Expand All @@ -38,21 +39,21 @@ describe('modules/manager/ansible-galaxy/extract', () => {

it('check collection style requirements file', () => {
const res = extractPackageFile(collections1, 'requirements.yml');
expect(res.deps).toMatchSnapshot();
expect(res.deps).toHaveLength(13);
expect(res.deps.filter((value) => value.skipReason)).toHaveLength(6);
expect(res?.deps).toMatchSnapshot();
expect(res?.deps).toHaveLength(13);
expect(res?.deps.filter((value) => value.skipReason)).toHaveLength(6);
});

it('check collection style requirements file in reverse order and missing empty line', () => {
const res = extractPackageFile(collections2, 'requirements.yml');
expect(res.deps).toMatchSnapshot();
expect(res.deps).toHaveLength(4);
expect(res?.deps).toMatchSnapshot();
expect(res?.deps).toHaveLength(4);
});

it('check galaxy definition file', () => {
const res = extractPackageFile(galaxy, 'galaxy.yml');
expect(res.deps).toMatchSnapshot();
expect(res.deps).toHaveLength(2);
expect(res?.deps).toMatchSnapshot();
expect(res?.deps).toHaveLength(2);
});
});

Expand Down
10 changes: 5 additions & 5 deletions lib/modules/manager/ansible/extract.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Fixtures } from '../../../../test/fixtures';
import { extractPackageFile } from './extract';
import { extractPackageFile } from '.';

describe('modules/manager/ansible/extract', () => {
describe('extractPackageFile()', () => {
Expand All @@ -9,14 +9,14 @@ describe('modules/manager/ansible/extract', () => {

it('extracts multiple image lines from docker_container', () => {
const res = extractPackageFile(Fixtures.get('main1.yaml'));
expect(res.deps).toMatchSnapshot();
expect(res.deps).toHaveLength(9);
expect(res?.deps).toMatchSnapshot();
expect(res?.deps).toHaveLength(9);
});

it('extracts multiple image lines from docker_service', () => {
const res = extractPackageFile(Fixtures.get('main2.yaml'));
expect(res.deps).toMatchSnapshot();
expect(res.deps).toHaveLength(4);
expect(res?.deps).toMatchSnapshot();
expect(res?.deps).toHaveLength(4);
});
});
});
6 changes: 3 additions & 3 deletions lib/modules/manager/argocd/extract.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Fixtures } from '../../../../test/fixtures';
import { extractPackageFile } from './extract';
import { extractPackageFile } from '.';

const validApplication = Fixtures.get('validApplication.yml');
const malformedApplication = Fixtures.get('malformedApplications.yml');
Expand Down Expand Up @@ -28,8 +28,8 @@ describe('modules/manager/argocd/extract', () => {
it('full test', () => {
const result = extractPackageFile(validApplication, 'applications.yml');
expect(result).not.toBeNull();
expect(result.deps).toBeArrayOfSize(3);
expect(result.deps).toMatchSnapshot();
expect(result?.deps).toBeArrayOfSize(3);
expect(result?.deps).toMatchSnapshot();
});

it('supports applicationsets', () => {
Expand Down
6 changes: 3 additions & 3 deletions lib/modules/manager/azure-pipelines/extract.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Fixtures } from '../../../../test/fixtures';
import {
extractContainer,
extractPackageFile,
extractRepository,
parseAzurePipelines,
} from './extract';
import { extractPackageFile } from '.';

const azurePipelines = Fixtures.get('azure-pipelines.yaml');

Expand Down Expand Up @@ -95,8 +95,8 @@ describe('modules/manager/azure-pipelines/extract', () => {

it('extracts dependencies', () => {
const res = extractPackageFile(azurePipelines, 'some-file');
expect(res.deps).toMatchSnapshot();
expect(res.deps).toHaveLength(3);
expect(res?.deps).toMatchSnapshot();
expect(res?.deps).toHaveLength(3);
});

it('should return null when there is no dependency found', () => {
Expand Down
4 changes: 2 additions & 2 deletions lib/modules/manager/azure-pipelines/types.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export interface Container {
image: string;
image?: string | null;
}
export interface Repository {
type: 'git' | 'github' | 'bitbucket';
name: string;
ref: string;
ref?: string | null;
}
export interface Resources {
repositories: Repository[];
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/manager/batect-wrapper/artifacts.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as httpMock from '../../../../test/http-mock';
import type { UpdateArtifact } from '../types';
import { updateArtifacts } from './artifacts';
import { updateArtifacts } from '.';

const defaultTo = '1.2.3';
const newUnixWrapperContent = `Unix wrapper script for ${defaultTo}`;
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/manager/batect-wrapper/extract.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Fixtures } from '../../../../test/fixtures';
import { GithubReleasesDatasource } from '../../datasource/github-releases';
import { id as semverVersioning } from '../../versioning/semver';
import type { PackageDependency } from '../types';
import { extractPackageFile } from './extract';
import { extractPackageFile } from '.';

describe('modules/manager/batect-wrapper/extract', () => {
describe('extractPackageFile()', () => {
Expand Down
6 changes: 4 additions & 2 deletions lib/modules/manager/batect/extract.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { id as dockerVersioning } from '../../versioning/docker';
import { id as semverVersioning } from '../../versioning/semver';
import { getDep } from '../dockerfile/extract';
import type { ExtractConfig, PackageDependency } from '../types';
import { extractAllPackageFiles } from './extract';
import { extractAllPackageFiles } from '.';

const fixturesDir = 'lib/modules/manager/batect/__fixtures__';

Expand Down Expand Up @@ -76,8 +76,10 @@ describe('modules/manager/batect/extract', () => {
`${fixturesDir}/valid/batect.yml`,
]);

// TODO: #7154
expect(
result.sort((a, b) => a.packageFile.localeCompare(b.packageFile))
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
result?.sort((a, b) => a.packageFile!.localeCompare(b.packageFile!))
).toEqual([
{
packageFile: `${fixturesDir}/valid/another-include.yml`,
Expand Down
24 changes: 12 additions & 12 deletions lib/modules/manager/bazel/extract.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Fixtures } from '../../../../test/fixtures';
import { extractPackageFile } from './extract';
import { extractPackageFile } from '.';

describe('modules/manager/bazel/extract', () => {
describe('extractPackageFile()', () => {
Expand All @@ -15,13 +15,13 @@ describe('modules/manager/bazel/extract', () => {

it('extracts multiple types of dependencies', () => {
const res = extractPackageFile(Fixtures.get('WORKSPACE1'));
expect(res.deps).toHaveLength(14);
expect(res.deps).toMatchSnapshot();
expect(res?.deps).toHaveLength(14);
expect(res?.deps).toMatchSnapshot();
});

it('extracts github tags', () => {
const res = extractPackageFile(Fixtures.get('WORKSPACE2'));
expect(res.deps).toMatchSnapshot([
expect(res?.deps).toMatchSnapshot([
{ packageName: 'lmirosevic/GBDeviceInfo' },
{ packageName: 'nelhage/rules_boost' },
{ packageName: 'lmirosevic/GBDeviceInfo' },
Expand All @@ -31,14 +31,14 @@ describe('modules/manager/bazel/extract', () => {

it('handle comments and strings', () => {
const res = extractPackageFile(Fixtures.get('WORKSPACE3'));
expect(res.deps).toMatchSnapshot([
expect(res?.deps).toMatchSnapshot([
{ packageName: 'nelhage/rules_boost' },
]);
});

it('extracts dependencies from *.bzl files', () => {
const res = extractPackageFile(Fixtures.get('repositories.bzl'));
expect(res.deps).toMatchSnapshot([
expect(res?.deps).toMatchSnapshot([
{
currentDigest: '0356bef3fbbabec5f0e196ecfacdeb6db62d48c0',
packageName: 'google/subpar',
Expand All @@ -62,7 +62,7 @@ describe('modules/manager/bazel/extract', () => {
tag="v1.0.0-alpha31.cli-migrations"
)`
);
expect(res.deps).toMatchSnapshot([
expect(res?.deps).toMatchSnapshot([
{
currentDigest:
'sha256:a4e8d8c444ca04fe706649e82263c9f4c2a4229bc30d2a64561b5e1d20cc8548',
Expand All @@ -85,8 +85,8 @@ go_repository(
)
`
);
expect(successStory.deps[0].datasource).toBe('go');
expect(successStory.deps[0].packageName).toBe(
expect(successStory?.deps[0].datasource).toBe('go');
expect(successStory?.deps[0].packageName).toBe(
'github.com/test/uuid-fork'
);

Expand All @@ -100,7 +100,7 @@ go_repository(
)
`
);
expect(badStory.deps[0].skipReason).toBe('unsupported-remote');
expect(badStory?.deps[0].skipReason).toBe('unsupported-remote');

const gheStory = extractPackageFile(
`
Expand All @@ -112,7 +112,7 @@ go_repository(
)
`
);
expect(gheStory.deps[0].skipReason).toBe('unsupported-remote');
expect(gheStory?.deps[0].skipReason).toBe('unsupported-remote');

const gitlabRemote = extractPackageFile(
`
Expand All @@ -124,7 +124,7 @@ go_repository(
)
`
);
expect(gitlabRemote.deps[0].skipReason).toBe('unsupported-remote');
expect(gitlabRemote?.deps[0].skipReason).toBe('unsupported-remote');
});
});
});
10 changes: 5 additions & 5 deletions lib/modules/manager/bazel/update.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Readable } from 'stream';
import * as httpMock from '../../../../test/http-mock';
import { loadFixture } from '../../../../test/util';
import type { UpdateType } from '../../../config/types';
import { updateDependency } from './update';
import { updateDependency } from '.';

const content = loadFixture('WORKSPACE1');
const contentContainerPull = loadFixture('container_pull');
Expand Down Expand Up @@ -147,7 +147,7 @@ describe('modules/manager/bazel/update', () => {
upgrade,
});
expect(res).not.toEqual(fileWithBzlExtension);
expect(res.indexOf('0.8.0')).not.toBe(-1);
expect(res?.indexOf('0.8.0')).not.toBe(-1);
});

it('updates finds url instead of urls', async () => {
Expand Down Expand Up @@ -175,7 +175,7 @@ describe('modules/manager/bazel/update', () => {
upgrade,
});
expect(res).not.toEqual(fileWithBzlExtension);
expect(res.indexOf('0.8.0')).not.toBe(-1);
expect(res?.indexOf('0.8.0')).not.toBe(-1);
});

it('returns null if no urls resolve hashes', async () => {
Expand Down Expand Up @@ -267,8 +267,8 @@ http_archive(
upgrade,
});
expect(res).not.toEqual(content);
expect(res.indexOf('0.5.0')).toBe(-1);
expect(res.indexOf('0.6.2')).not.toBe(-1);
expect(res?.indexOf('0.5.0')).toBe(-1);
expect(res?.indexOf('0.6.2')).not.toBe(-1);
});
});
});
6 changes: 3 additions & 3 deletions lib/modules/manager/bitbucket-pipelines/extract.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Fixtures } from '../../../../test/fixtures';
import { extractPackageFile } from './extract';
import { extractPackageFile } from '.';

describe('modules/manager/bitbucket-pipelines/extract', () => {
describe('extractPackageFile()', () => {
Expand All @@ -9,7 +9,7 @@ describe('modules/manager/bitbucket-pipelines/extract', () => {

it('extracts dependencies', () => {
const res = extractPackageFile(Fixtures.get('bitbucket-pipelines.yaml'));
expect(res.deps).toMatchInlineSnapshot(`
expect(res?.deps).toMatchInlineSnapshot(`
Array [
Object {
"autoReplaceStringTemplate": "{{depName}}{{#if newValue}}:{{newValue}}{{/if}}{{#if newDigest}}@{{newDigest}}{{/if}}",
Expand Down Expand Up @@ -37,7 +37,7 @@ Array [
},
]
`);
expect(res.deps).toHaveLength(3);
expect(res?.deps).toHaveLength(3);
});
});
});
14 changes: 7 additions & 7 deletions lib/modules/manager/buildkite/extract.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Fixtures } from '../../../../test/fixtures';
import type { PackageDependency } from '../types';
import { extractPackageFile } from './extract';
import { extractPackageFile } from '.';

describe('modules/manager/buildkite/extract', () => {
describe('extractPackageFile()', () => {
Expand All @@ -9,31 +9,31 @@ describe('modules/manager/buildkite/extract', () => {
});

it('extracts simple single plugin', () => {
const res = extractPackageFile(Fixtures.get('pipeline1.yml')).deps;
const res = extractPackageFile(Fixtures.get('pipeline1.yml'))?.deps;
expect(res).toMatchSnapshot();
expect(res).toHaveLength(1);
});

it('extracts multiple plugins in same file', () => {
const res = extractPackageFile(Fixtures.get('pipeline2.yml')).deps;
const res = extractPackageFile(Fixtures.get('pipeline2.yml'))?.deps;
expect(res).toMatchSnapshot();
expect(res).toHaveLength(2);
});

it('adds skipReason', () => {
const res = extractPackageFile(Fixtures.get('pipeline3.yml')).deps;
const res = extractPackageFile(Fixtures.get('pipeline3.yml'))?.deps;
expect(res).toMatchSnapshot();
expect(res).toHaveLength(2);
});

it('extracts arrays of plugins', () => {
const res = extractPackageFile(Fixtures.get('pipeline4.yml')).deps;
const res = extractPackageFile(Fixtures.get('pipeline4.yml'))?.deps;
expect(res).toMatchSnapshot();
expect(res).toHaveLength(4);
});

it('extracts git-based plugins', () => {
const res = extractPackageFile(Fixtures.get('pipeline5.yml')).deps;
const res = extractPackageFile(Fixtures.get('pipeline5.yml'))?.deps;
expect(res).toMatchSnapshot();
expect(res).toHaveLength(2);
});
Expand All @@ -45,7 +45,7 @@ describe('modules/manager/buildkite/extract', () => {
depName: 'some-org/some-plugin',
registryUrls: ['https://github.company.com'],
};
const res = extractPackageFile(Fixtures.get('pipeline6.yml')).deps;
const res = extractPackageFile(Fixtures.get('pipeline6.yml'))?.deps;
expect(res).toHaveLength(1);
expect(res).toEqual([expectedPackageDependency]);
});
Expand Down

0 comments on commit b431992

Please sign in to comment.