Skip to content

Commit

Permalink
test(regex-manager): Separate arrange/act/assert with spaces (#30972)
Browse files Browse the repository at this point in the history
  • Loading branch information
zharinov committed Aug 22, 2024
1 parent 1f65d31 commit 321e304
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions lib/modules/manager/custom/regex/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ describe('modules/manager/custom/regex/index', () => {
'{{#if versioning}}{{versioning}}{{else}}semver{{/if}}',
depTypeTemplate: 'final',
};

const res = await extractPackageFile(
dockerfileContent,
'Dockerfile',
config,
);

expect(res).toMatchSnapshot();
expect(res?.deps).toHaveLength(8);
expect(res?.deps.find((dep) => dep.depName === 'yarn')?.versioning).toBe(
Expand All @@ -53,7 +55,9 @@ describe('modules/manager/custom/regex/index', () => {
versioningTemplate:
'{{#if versioning}}{{versioning}}{{else}}semver{{/if}}',
};

const res = await extractPackageFile('', 'Dockerfile', config);

expect(res).toBeNull();
});

Expand All @@ -64,11 +68,13 @@ describe('modules/manager/custom/regex/index', () => {
],
versioningTemplate: '{{#if versioning}}{{versioning}}{{else}}semver',
};

const res = await extractPackageFile(
dockerfileContent,
'Dockerfile',
config,
);

expect(res).toBeNull();
});

Expand All @@ -78,11 +84,13 @@ describe('modules/manager/custom/regex/index', () => {
'ENV NGINX_MODULE_HEADERS_MORE_VERSION=(?<currentValue>.*) # (?<datasource>.*?)/(?<depName>.*?)(\\&versioning=(?<versioning>.*?))?(\\&extractVersion=(?<extractVersion>.*?))?\\s',
],
};

const res = await extractPackageFile(
dockerfileContent,
'Dockerfile',
config,
);

expect(res).toMatchSnapshot();
expect(res?.deps).toHaveLength(1);
expect(
Expand All @@ -99,6 +107,7 @@ describe('modules/manager/custom/regex/index', () => {
],
datasourceTemplate: 'helm',
};

const res = await extractPackageFile(
`
apiVersion: helm.fluxcd.io/v1
Expand All @@ -116,6 +125,7 @@ describe('modules/manager/custom/regex/index', () => {
'Dockerfile',
config,
);

expect(res).toMatchSnapshot({
deps: [
{
Expand All @@ -135,11 +145,13 @@ describe('modules/manager/custom/regex/index', () => {
],
registryUrlTemplate: 'http://registry.{{depName}}.com/',
};

const res = await extractPackageFile(
dockerfileContent,
'Dockerfile',
config,
);

expect(res).toMatchSnapshot();
expect(res?.deps).toHaveLength(1);
expect(
Expand All @@ -154,11 +166,13 @@ describe('modules/manager/custom/regex/index', () => {
],
registryUrlTemplate: 'this-is-not-a-valid-url-{{depName}}',
};

const res = await extractPackageFile(
dockerfileContent,
'Dockerfile',
config,
);

expect(res).toMatchSnapshot({
deps: [
{
Expand Down Expand Up @@ -186,11 +200,13 @@ describe('modules/manager/custom/regex/index', () => {
versioningTemplate:
'{{#if versioning}}{{versioning}}{{else}}semver{{/if}}',
};

const res = await extractPackageFile(
dockerfileContent,
'Dockerfile',
config,
);

expect(res).toMatchSnapshot();
expect(res?.deps).toHaveLength(2);
expect(
Expand All @@ -210,11 +226,13 @@ describe('modules/manager/custom/regex/index', () => {
autoReplaceStringTemplate: 'image: {{{depName}}}:{{{newValue}}}',
datasourceTemplate: 'docker',
};

const res = await extractPackageFile(
'image: my.old.registry/aRepository/andImage:1.18-alpine',
'values.yaml',
config,
);

expect(res).toMatchSnapshot();
expect(res?.deps).toHaveLength(1);
});
Expand All @@ -228,11 +246,13 @@ describe('modules/manager/custom/regex/index', () => {
'image:\n{{{indentation}}} name: {{{depName}}}:{{{newValue}}}',
datasourceTemplate: 'docker',
};

const res = await extractPackageFile(
' image: eclipse-temurin:17.0.0-alpine',
'bitbucket-pipelines.yml',
config,
);

expect(res).toMatchObject({
deps: [
{
Expand All @@ -255,11 +275,13 @@ describe('modules/manager/custom/regex/index', () => {
'image:\n{{{indentation}}} name: {{{depName}}}:{{{newValue}}}',
datasourceTemplate: 'docker',
};

const res = await extractPackageFile(
'name: image: eclipse-temurin:17.0.0-alpine',
'bitbucket-pipelines.yml',
config,
);

expect(res).toMatchObject({
deps: [
{
Expand All @@ -282,11 +304,13 @@ describe('modules/manager/custom/regex/index', () => {
matchStringsStrategy: 'combination',
datasourceTemplate: 'docker',
};

const res = await extractPackageFile(
ansibleYamlContent,
'ansible.yml',
config,
);

expect(res).toMatchSnapshot();
expect(res?.deps).toHaveLength(1);
});
Expand All @@ -303,11 +327,13 @@ describe('modules/manager/custom/regex/index', () => {
datasourceTemplate: 'docker',
depNameTemplate: '{{{ registry }}}/{{{ repository }}}',
};

const res = await extractPackageFile(
ansibleYamlContent,
'ansible.yml',
config,
);

expect(res?.deps).toHaveLength(1);
expect(res?.deps[0].depName).toBe('docker.io/prom/prometheus');
expect(res).toMatchSnapshot();
Expand All @@ -322,11 +348,13 @@ describe('modules/manager/custom/regex/index', () => {
matchStringsStrategy: 'combination',
datasourceTemplate: 'docker',
};

const res = await extractPackageFile(
ansibleYamlContent,
'ansible.yml',
config,
);

expect(res).toMatchSnapshot();
expect(res?.deps).toHaveLength(1);
});
Expand All @@ -341,11 +369,13 @@ describe('modules/manager/custom/regex/index', () => {
],
datasourceTemplate: 'helm',
};

const res = await extractPackageFile(
exampleGitlabCiYml,
'.gitlab-ci.yml',
config,
);

expect(res).toMatchSnapshot();
expect(res?.deps).toHaveLength(1);
});
Expand All @@ -360,11 +390,13 @@ describe('modules/manager/custom/regex/index', () => {
'image:\n name: {{{depName}}}{{#if newValue}}:{{{newValue}}}{{/if}}{{#if newDigest}}@{{{newDigest}}}{{/if}}',
datasourceTemplate: 'docker',
};

const res = await extractPackageFile(
'image: eclipse-temurin:17.0.0-alpine',
'bitbucket-pipelines.yml',
config,
);

expect(res).toMatchObject({
deps: [
{
Expand All @@ -387,11 +419,13 @@ describe('modules/manager/custom/regex/index', () => {
'image:\n name: {{{depName}}}{{#if newValue}}:{{{newValue}}}{{/if}}{{#if newDigest}}@{{{newDigest}}}{{/if}}',
datasourceTemplate: 'docker',
};

const res = await extractPackageFile(
'image: eclipse-temurin@sha256:1234567890abcdef',
'bitbucket-pipelines.yml',
config,
);

expect(res).toMatchObject({
deps: [
{
Expand All @@ -414,11 +448,13 @@ describe('modules/manager/custom/regex/index', () => {
datasourceTemplate: 'helm',
depNameTemplate: 'helm_repo/{{{ depName }}}',
};

const res = await extractPackageFile(
exampleGitlabCiYml,
'.gitlab-ci.yml',
config,
);

expect(res).toMatchSnapshot();
expect(res?.deps).toHaveLength(1);
});
Expand All @@ -433,7 +469,9 @@ describe('modules/manager/custom/regex/index', () => {
datasourceTemplate: 'helm',
depNameTemplate: 'helm_repo/{{{ depName }}}',
};

const res = await extractPackageFile('', '.gitlab-ci.yml', config);

expect(res).toBeNull();
});

Expand All @@ -445,11 +483,13 @@ describe('modules/manager/custom/regex/index', () => {
],
matchStringsStrategy: 'recursive',
};

const res = await extractPackageFile(
exampleJsonContent,
'example.json',
config,
);

expect(res).toMatchSnapshot();
expect(res?.deps).toHaveLength(1);
});
Expand All @@ -462,11 +502,13 @@ describe('modules/manager/custom/regex/index', () => {
],
matchStringsStrategy: 'recursive',
};

const res = await extractPackageFile(
exampleJsonContent,
'example.json',
config,
);

expect(res).toMatchSnapshot();
expect(res?.deps).toHaveLength(2);
});
Expand All @@ -480,11 +522,13 @@ describe('modules/manager/custom/regex/index', () => {
],
matchStringsStrategy: 'recursive',
};

const res = await extractPackageFile(
exampleJsonContent,
'example.json',
config,
);

expect(res).toMatchSnapshot();
expect(res?.deps).toHaveLength(1);
});
Expand All @@ -494,11 +538,13 @@ describe('modules/manager/custom/regex/index', () => {
matchStrings: ['"group.{1}":\\s*\\{[^}]*}'],
matchStringsStrategy: 'recursive',
};

const res = await extractPackageFile(
exampleJsonContent,
'example.json',
config,
);

expect(res).toBeNull();
});

Expand All @@ -507,11 +553,13 @@ describe('modules/manager/custom/regex/index', () => {
matchStrings: ['"trunk.{1}":\\s*\\{[^}]*}'],
matchStringsStrategy: 'recursive',
};

const res = await extractPackageFile(
exampleJsonContent,
'example.json',
config,
);

expect(res).toBeNull();
});

Expand All @@ -525,11 +573,13 @@ describe('modules/manager/custom/regex/index', () => {
matchStringsStrategy: 'recursive',
depNameTemplate: '{{{ first }}}/{{{ second }}}/{{{ depName }}}',
};

const res = await extractPackageFile(
exampleJsonContent,
'example.json',
config,
);

expect(res).toMatchSnapshot();
expect(res?.deps).toHaveLength(4);
});
Expand All @@ -544,6 +594,7 @@ describe('modules/manager/custom/regex/index', () => {
depNameTemplate: 'org.jacoco:jacoco',
datasourceTemplate: 'maven',
};

const res = await extractPackageFile(
`
jacoco {
Expand All @@ -553,6 +604,7 @@ describe('modules/manager/custom/regex/index', () => {
'build.gradle.kts',
config,
);

expect(res).toMatchObject({
deps: [
{
Expand Down

0 comments on commit 321e304

Please sign in to comment.