Skip to content

Commit

Permalink
fix(terraform): use path joins instead of slashes (#10461)
Browse files Browse the repository at this point in the history
Co-authored-by: Rhys Arkins <[email protected]>
Co-authored-by: Michael Kriese <[email protected]>
  • Loading branch information
3 people authored Jun 16, 2021
1 parent 75099ee commit 2776db6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
20 changes: 7 additions & 13 deletions lib/manager/terraform/lockfile/hash.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createReadStream } from 'fs';
import { join } from 'upath';
import * as httpMock from '../../../../test/http-mock';
import { getFixturePath, getName, loadFixture } from '../../../../test/util';
import { TerraformProviderDatasource } from '../../../datasource/terraform-provider';
Expand All @@ -7,14 +8,11 @@ import createHashes from './hash';
const terraformProviderDatasource = new TerraformProviderDatasource();
const releaseBackendUrl = terraformProviderDatasource.defaultRegistryUrls[1];
const releaseBackendAzurerm = loadFixture('releaseBackendAzurerm_2_56_0.json');
const cacheDir = join('/tmp/renovate/cache');

describe(getName(), () => {
it('returns null if a non hashicorp release is found ', async () => {
const result = await createHashes(
'test/gitlab',
'2.56.0',
'/tmp/renovate/cache'
);
const result = await createHashes('test/gitlab', '2.56.0', cacheDir);
expect(result).toBeNull();
});

Expand All @@ -24,11 +22,7 @@ describe(getName(), () => {
.get('/terraform-provider-azurerm/2.59.0/index.json')
.reply(403, '');

const result = await createHashes(
'hashicorp/azurerm',
'2.59.0',
'/tmp/renovate/cache'
);
const result = await createHashes('hashicorp/azurerm', '2.59.0', cacheDir);
expect(result).toBeNull();
expect(httpMock.getTrace()).toMatchSnapshot();
});
Expand All @@ -39,7 +33,7 @@ describe(getName(), () => {
.get('/terraform-provider-azurerm/2.56.0/index.json')
.replyWithError('');

const result = await createHashes('hashicorp/azurerm', '2.56.0', '/tmp');
const result = await createHashes('hashicorp/azurerm', '2.56.0', cacheDir);
expect(result).toBeNull();
expect(httpMock.getTrace()).toMatchSnapshot();
});
Expand All @@ -64,7 +58,7 @@ describe(getName(), () => {
)
.reply(200, readStreamDarwin);

const result = await createHashes('hashicorp/azurerm', '2.56.0', '/tmp');
const result = await createHashes('hashicorp/azurerm', '2.56.0', cacheDir);
expect(result).toBeNull();
expect(httpMock.getTrace()).toMatchSnapshot();
});
Expand All @@ -89,7 +83,7 @@ describe(getName(), () => {
)
.reply(200, readStreamDarwin);

const result = await createHashes('hashicorp/azurerm', '2.56.0', '/tmp');
const result = await createHashes('hashicorp/azurerm', '2.56.0', cacheDir);
expect(result).not.toBeNull();
expect(result).toBeArrayOfSize(2);
expect(result).toMatchSnapshot();
Expand Down
5 changes: 3 additions & 2 deletions lib/manager/terraform/lockfile/hash.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import crypto from 'crypto';
import extract from 'extract-zip';
import pMap from 'p-map';
import { join } from 'upath';
import { TerraformProviderDatasource } from '../../../datasource/terraform-provider';
import type {
TerraformBuild,
Expand Down Expand Up @@ -80,8 +81,8 @@ export async function calculateHashes(
const hashes = await pMap(
builds,
async (build) => {
const downloadFileName = `${cacheDir}/${build.filename}`;
const extractPath = `${cacheDir}/extract/${build.filename}`;
const downloadFileName = join(cacheDir, build.filename);
const extractPath = join(cacheDir, 'extract', build.filename);
logger.trace(
`Downloading archive and generating hash for ${build.name}-${build.version}...`
);
Expand Down

0 comments on commit 2776db6

Please sign in to comment.