From 2cfa7feb05cbd65ca399440d45fc669dd6c2ceb2 Mon Sep 17 00:00:00 2001
From: Rhys Arkins <rhys@arkins.net>
Date: Thu, 13 Feb 2020 09:50:03 +0100
Subject: [PATCH] fix: use correct updateDependency params

Closes #5473
---
 lib/manager/cdnurl/update.spec.ts      | 12 +++++--
 lib/manager/cdnurl/update.ts           | 10 +++---
 lib/manager/helm-values/update.spec.ts | 44 +++++++++++++-------------
 lib/manager/helm-values/update.ts      | 10 +++---
 lib/manager/helmfile/update.spec.ts    | 34 ++++++++++----------
 lib/manager/helmfile/update.ts         | 10 +++---
 6 files changed, 63 insertions(+), 57 deletions(-)

diff --git a/lib/manager/cdnurl/update.spec.ts b/lib/manager/cdnurl/update.spec.ts
index c57f770bce..5253603a94 100644
--- a/lib/manager/cdnurl/update.spec.ts
+++ b/lib/manager/cdnurl/update.spec.ts
@@ -16,7 +16,7 @@ describe('manager/cdnurl/update', () => {
       newValue: '9.9.999',
     };
     const { currentValue, newValue } = upgrade;
-    const newFileContent = updateDependency(content, upgrade);
+    const newFileContent = updateDependency({ fileContent: content, upgrade });
     const cmpContent = content.replace(currentValue, newValue);
     expect(newFileContent).toEqual(cmpContent);
   });
@@ -29,7 +29,10 @@ describe('manager/cdnurl/update', () => {
     };
     const { currentValue } = upgrade;
     const alreadyUpdated = content.replace(currentValue, '9.9.999');
-    const newFileContent = updateDependency(alreadyUpdated, upgrade);
+    const newFileContent = updateDependency({
+      fileContent: alreadyUpdated,
+      upgrade,
+    });
     expect(newFileContent).toBe(alreadyUpdated);
   });
   it('returns null if content has changed', () => {
@@ -41,7 +44,10 @@ describe('manager/cdnurl/update', () => {
     };
     const { currentValue } = upgrade;
     const alreadyUpdated = content.replace(currentValue, '2020.1');
-    const newFileContent = updateDependency(alreadyUpdated, upgrade);
+    const newFileContent = updateDependency({
+      fileContent: alreadyUpdated,
+      upgrade,
+    });
     expect(newFileContent).toBeNull();
   });
 });
diff --git a/lib/manager/cdnurl/update.ts b/lib/manager/cdnurl/update.ts
index 5f83d4ca58..f3fd77d648 100644
--- a/lib/manager/cdnurl/update.ts
+++ b/lib/manager/cdnurl/update.ts
@@ -1,10 +1,10 @@
 import { logger } from '../../logger';
-import { Upgrade } from '../common';
+import { UpdateDependencyConfig } from '../common';
 
-export function updateDependency(
-  fileContent: string,
-  upgrade: Upgrade
-): string | null {
+export function updateDependency({
+  fileContent,
+  upgrade,
+}: UpdateDependencyConfig): string {
   const { depName, currentValue, newValue, managerData } = upgrade;
   const { fileReplacePosition } = managerData;
   const leftPart = fileContent.slice(0, fileReplacePosition);
diff --git a/lib/manager/helm-values/update.spec.ts b/lib/manager/helm-values/update.spec.ts
index fac23ab2c1..4ec85ed711 100644
--- a/lib/manager/helm-values/update.spec.ts
+++ b/lib/manager/helm-values/update.spec.ts
@@ -3,13 +3,13 @@ import { updateDependency } from './update';
 describe('lib/manager/helm-values/update', () => {
   describe('updateDependency()', () => {
     it('returns the same fileContent for undefined upgrade', () => {
-      const content = 'someKey: "someValue"';
+      const fileContent = 'someKey: "someValue"';
       const upgrade = undefined;
 
-      expect(updateDependency(content, upgrade)).toBe(content);
+      expect(updateDependency({ fileContent, upgrade })).toBe(fileContent);
     });
     it('returns the same fileContent for invalid values.yaml file', () => {
-      const content = `
+      const fileContent = `
        Invalid values.yaml content.
       `;
       const upgrade = {
@@ -19,11 +19,11 @@ describe('lib/manager/helm-values/update', () => {
         newValue: '0.8.0',
         dockerRepository: 'bitnami/postgres-exporter',
       };
-      expect(updateDependency(content, upgrade)).toBe(content);
+      expect(updateDependency({ fileContent, upgrade })).toBe(fileContent);
     });
     // https://github.com/renovatebot/renovate/issues/5298
     it('returns the same fileContent for duplicate key errors', () => {
-      const content = `
+      const fileContent = `
       replicaCount: 1
       replicaCount: 5
       `;
@@ -34,20 +34,20 @@ describe('lib/manager/helm-values/update', () => {
         newValue: '0.8.0',
         dockerRepository: 'bitnami/postgres-exporter',
       };
-      expect(updateDependency(content, upgrade)).toBe(content);
+      expect(updateDependency({ fileContent, upgrade })).toBe(fileContent);
     });
     it('returns the same fileContent for empty upgrade', () => {
-      const content = 'someKey: "someValue"';
+      const fileContent = 'someKey: "someValue"';
       const upgrade = {};
-      expect(updateDependency(content, upgrade)).toBe(content);
+      expect(updateDependency({ fileContent, upgrade })).toBe(fileContent);
     });
     it('returns the same fileContent for null content', () => {
-      const content = null;
+      const fileContent = null;
       const upgrade = {};
-      expect(updateDependency(content, upgrade)).toBe(content);
+      expect(updateDependency({ fileContent, upgrade })).toBe(fileContent);
     });
     it('upgrades dependency if valid upgrade', () => {
-      const content = `
+      const fileContent = `
       image:
         repository: bitnami/postgres-exporter
         tag: 0.7.0-debian-9-r12
@@ -58,11 +58,11 @@ describe('lib/manager/helm-values/update', () => {
         newValue: '0.8.0',
         dockerRepository: 'bitnami/postgres-exporter',
       };
-      expect(updateDependency(content, upgrade)).not.toBe(content);
-      expect(updateDependency(content, upgrade)).toMatchSnapshot();
+      expect(updateDependency({ fileContent, upgrade })).not.toBe(fileContent);
+      expect(updateDependency({ fileContent, upgrade })).toMatchSnapshot();
     });
     it('survives null values of keys', () => {
-      const content = `
+      const fileContent = `
       empty_key:
       image:
         repository: bitnami/postgres-exporter
@@ -74,11 +74,11 @@ describe('lib/manager/helm-values/update', () => {
         newValue: '0.8.0',
         dockerRepository: 'bitnami/postgres-exporter',
       };
-      expect(updateDependency(content, upgrade)).not.toBe(content);
-      expect(updateDependency(content, upgrade)).toMatchSnapshot();
+      expect(updateDependency({ fileContent, upgrade })).not.toBe(fileContent);
+      expect(updateDependency({ fileContent, upgrade })).toMatchSnapshot();
     });
     it('upgrades dependency if newValue version value is repeated', () => {
-      const content = `
+      const fileContent = `
       db:
         image:
           image:
@@ -99,11 +99,11 @@ describe('lib/manager/helm-values/update', () => {
         newValue: '12.5.0',
         dockerRepository: 'bitnami/postgresql',
       };
-      expect(updateDependency(content, upgrade)).not.toBe(content);
-      expect(updateDependency(content, upgrade)).toMatchSnapshot();
+      expect(updateDependency({ fileContent, upgrade })).not.toBe(fileContent);
+      expect(updateDependency({ fileContent, upgrade })).toMatchSnapshot();
     });
     it('upgrades correct dependency if registry included', () => {
-      const content = `
+      const fileContent = `
       db:
         image:
           image:
@@ -124,8 +124,8 @@ describe('lib/manager/helm-values/update', () => {
         dockerRepository: 'bitnami/postgresql',
       };
 
-      expect(updateDependency(content, upgrade)).not.toBe(content);
-      expect(updateDependency(content, upgrade)).toMatchSnapshot();
+      expect(updateDependency({ fileContent, upgrade })).not.toBe(fileContent);
+      expect(updateDependency({ fileContent, upgrade })).toMatchSnapshot();
     });
   });
 });
diff --git a/lib/manager/helm-values/update.ts b/lib/manager/helm-values/update.ts
index 408a33ec1f..2823f218f8 100644
--- a/lib/manager/helm-values/update.ts
+++ b/lib/manager/helm-values/update.ts
@@ -1,6 +1,6 @@
 import YAWN from 'yawn-yaml/cjs';
 import { logger } from '../../logger';
-import { Upgrade } from '../common';
+import { UpdateDependencyConfig } from '../common';
 import {
   matchesHelmValuesDockerHeuristic,
   HelmDockerImageDependency,
@@ -87,10 +87,10 @@ function updateDoc(
   return false;
 }
 
-export function updateDependency(
-  fileContent: string,
-  upgrade: Upgrade
-): string | null {
+export function updateDependency({
+  fileContent,
+  upgrade,
+}: UpdateDependencyConfig): string | null {
   if (
     !upgrade ||
     !upgrade.depName ||
diff --git a/lib/manager/helmfile/update.spec.ts b/lib/manager/helmfile/update.spec.ts
index 4025077833..d5d627eac0 100644
--- a/lib/manager/helmfile/update.spec.ts
+++ b/lib/manager/helmfile/update.spec.ts
@@ -3,7 +3,7 @@ import { updateDependency } from './update';
 describe('lib/manager/helmfile/extract', () => {
   describe('updateDependency()', () => {
     it('returns the same fileContent for undefined upgrade', () => {
-      const content = `
+      const fileContent = `
       repositories:
         - name: kiwigrid
           url: https://kiwigrid.github.io
@@ -14,11 +14,11 @@ describe('lib/manager/helmfile/extract', () => {
       `;
       const upgrade = undefined;
 
-      expect(updateDependency(content, upgrade)).toBe(content);
+      expect(updateDependency({ fileContent, upgrade })).toBe(fileContent);
     });
 
     it('returns the same fileContent for invalid helmfile.yaml file', () => {
-      const content = `
+      const fileContent = `
        Invalid helmfile.yaml content.
       `;
       const upgrade = {
@@ -26,11 +26,11 @@ describe('lib/manager/helmfile/extract', () => {
         newValue: '5.3.0',
         repository: 'https://kiwigrid.github.io',
       };
-      expect(updateDependency(content, upgrade)).toBe(content);
+      expect(updateDependency({ fileContent, upgrade })).toBe(fileContent);
     });
 
     it('returns the same fileContent for empty upgrade', () => {
-      const content = `
+      const fileContent = `
       repositories:
         - name: kiwigrid
           url: https://kiwigrid.github.io
@@ -40,11 +40,11 @@ describe('lib/manager/helmfile/extract', () => {
           chart: kiwigrid/fluentd-elasticsearch
       `;
       const upgrade = {};
-      expect(updateDependency(content, upgrade)).toBe(content);
+      expect(updateDependency({ fileContent, upgrade })).toBe(fileContent);
     });
 
     it('upgrades dependency if valid upgrade', () => {
-      const content = `
+      const fileContent = `
       repositories:
         - name: kiwigrid
           url: https://kiwigrid.github.io
@@ -58,12 +58,12 @@ describe('lib/manager/helmfile/extract', () => {
         newValue: '5.3.1',
         repository: 'https://kiwigrid.github.io',
       };
-      expect(updateDependency(content, upgrade)).not.toBe(content);
-      expect(updateDependency(content, upgrade)).toMatchSnapshot();
+      expect(updateDependency({ fileContent, upgrade })).not.toBe(fileContent);
+      expect(updateDependency({ fileContent, upgrade })).toMatchSnapshot();
     });
 
     it('upgrades dependency if version field comes before name field', () => {
-      const content = `
+      const fileContent = `
       repositories:
         - name: kiwigrid
           url: https://kiwigrid.github.io
@@ -77,12 +77,12 @@ describe('lib/manager/helmfile/extract', () => {
         newValue: '5.3.1',
         repository: 'https://kiwigrid.github.io',
       };
-      expect(updateDependency(content, upgrade)).not.toBe(content);
-      expect(updateDependency(content, upgrade)).toMatchSnapshot();
+      expect(updateDependency({ fileContent, upgrade })).not.toBe(fileContent);
+      expect(updateDependency({ fileContent, upgrade })).toMatchSnapshot();
     });
 
     it('upgrades dependency if chart is repeated', () => {
-      const content = `
+      const fileContent = `
       repositories:
         - name: kiwigrid
           url: https://kiwigrid.github.io
@@ -105,12 +105,12 @@ describe('lib/manager/helmfile/extract', () => {
         newValue: '5.3.1',
         repository: 'https://kiwigrid.github.io',
       };
-      expect(updateDependency(content, upgrade)).not.toBe(content);
-      expect(updateDependency(content, upgrade)).toMatchSnapshot();
+      expect(updateDependency({ fileContent, upgrade })).not.toBe(fileContent);
+      expect(updateDependency({ fileContent, upgrade })).toMatchSnapshot();
     });
 
     it('Not fail if same version in multiple package', () => {
-      const content = `
+      const fileContent = `
       repositories:
         - name: kiwigrid
           url: https://kiwigrid.github.io
@@ -131,7 +131,7 @@ describe('lib/manager/helmfile/extract', () => {
         newValue: '5.3.1',
         repository: 'https://kiwigrid.github.io',
       };
-      expect(updateDependency(content, upgrade)).toBe(content);
+      expect(updateDependency({ fileContent, upgrade })).toBe(fileContent);
     });
   });
 });
diff --git a/lib/manager/helmfile/update.ts b/lib/manager/helmfile/update.ts
index a62e3f2134..b3a8088f63 100644
--- a/lib/manager/helmfile/update.ts
+++ b/lib/manager/helmfile/update.ts
@@ -3,7 +3,7 @@ import yaml from 'js-yaml';
 import is from '@sindresorhus/is';
 
 import { logger } from '../../logger';
-import { Upgrade } from '../common';
+import { UpdateDependencyConfig } from '../common';
 
 // Return true if the match string is found at index in content
 function matchAt(content: string, index: number, match: string): boolean {
@@ -25,10 +25,10 @@ function replaceAt(
   );
 }
 
-export function updateDependency(
-  fileContent: string,
-  upgrade: Upgrade
-): string | null {
+export function updateDependency({
+  fileContent,
+  upgrade,
+}: UpdateDependencyConfig): string {
   logger.trace({ config: upgrade }, 'updateDependency()');
   if (!upgrade || !upgrade.depName || !upgrade.newValue) {
     logger.debug('Failed to update dependency, invalid upgrade');
-- 
GitLab