Skip to content

Commit 5979409

Browse files
authored
drop Math.random usage (#163)
1 parent 7a8ffdb commit 5979409

File tree

5 files changed

+12
-7
lines changed

5 files changed

+12
-7
lines changed

__tests__/action_failed.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import * as core from '@actions/core';
99
import * as getcmake from '../src/get-cmake';
1010
import path = require('path');
1111
import { ToolsGetter } from '../src/get-cmake';
12+
import * as crypto from 'crypto';
1213

1314
// 10 minutes
1415
jest.setTimeout(10 * 60 * 1000)
@@ -36,7 +37,7 @@ var coreError = jest.spyOn(core, 'error').mockImplementation(() => {});
3637
var toolsCacheDir = jest.spyOn(toolcache, 'cacheDir');
3738

3839
test('testing get-cmake action failure', async () => {
39-
const testId = Math.random();
40+
const testId = crypto.randomBytes(16).toString('hex');
4041
process.exitCode
4142
process.env.RUNNER_TEMP = path.join(os.tmpdir(), `${testId}`);
4243
process.env.RUNNER_TOOL_CACHE = path.join(os.tmpdir(), `${testId}-cache`);

__tests__/action_succeeded.localcloud.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// SPDX short identifier: MIT
44

55
import * as os from 'os';
6+
import * as crypto from 'crypto';
67
import * as toolcache from '@actions/tool-cache';
78
import * as core from '@actions/core';
89
import * as path from 'path'
@@ -46,7 +47,7 @@ var toolsCacheDir = jest.spyOn(toolcache, 'cacheDir');
4647
var toolsFind = jest.spyOn(toolcache, 'find');
4748

4849
test('testing get-cmake action success with cloud/local cache enabled', async () => {
49-
const testId = Math.random();
50+
const testId = crypto.randomBytes(16).toString('hex');
5051
process.env.RUNNER_TEMP = path.join(os.tmpdir(), `${testId}`);
5152
process.env.RUNNER_TOOL_CACHE = path.join(os.tmpdir(), `${testId}-cache`);
5253

@@ -78,7 +79,7 @@ test('testing get-cmake action success with cloud/local cache enabled', async ()
7879
});
7980

8081
test('testing get-cmake action success with local or cloud cache hits', async () => {
81-
const testId = Math.random();
82+
const testId = crypto.randomBytes(16).toString('hex');
8283
process.env.RUNNER_TEMP = path.join(os.tmpdir(), `${testId}`);
8384
process.env.RUNNER_TOOL_CACHE = path.join(os.tmpdir(), `${testId}-cache`);
8485

@@ -121,7 +122,7 @@ test('testing get-cmake action store and restore local cache', async () => {
121122
toolsCacheDir.mockRestore();
122123
toolsFind.mockRestore();
123124

124-
const testId = Math.random();
125+
const testId = crypto.randomBytes(16).toString('hex');
125126
process.env.RUNNER_TEMP = path.join(os.tmpdir(), `${testId}`);
126127
process.env.RUNNER_TOOL_CACHE = path.join(os.tmpdir(), `${testId}-cache`);
127128
let downloadMock = undefined;

__tests__/cachehit.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import * as os from 'os';
88
import { ToolsGetter } from '../src/get-cmake';
99
import * as cache from '@actions/cache';
1010
import path = require('path');
11+
import * as crypto from 'crypto';
1112

1213
// 10 minutes
1314
jest.setTimeout(10 * 60 * 1000)
@@ -24,7 +25,7 @@ const cacheRestoreCache = jest.spyOn(cache, 'restoreCache').mockImplementation((
2425
const addToolsToPath = jest.spyOn(ToolsGetter.prototype as any, 'addToolsToPath').mockResolvedValue(0);
2526

2627
test('testing get-cmake with cache-hit...', async () => {
27-
const testId = Math.random();
28+
const testId = crypto.randomBytes(16).toString('hex');
2829
process.env.RUNNER_TEMP = path.join(os.tmpdir(), `${testId}`);
2930

3031
const getter: ToolsGetter = new ToolsGetter();

__tests__/cachemiss.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { ToolsGetter } from '../src/get-cmake';
99
import * as cache from '@actions/cache';
1010
import * as core from '@actions/core';
1111
import path = require('path');
12+
import * as crypto from 'crypto';
1213

1314
// 10 minutes
1415
jest.setTimeout(10 * 60 * 1000)
@@ -27,7 +28,7 @@ const cacheRestoreCache = jest.spyOn(cache, 'restoreCache').mockImplementation((
2728
const addToolsToPath = jest.spyOn(ToolsGetter.prototype as any, 'addToolsToPath').mockResolvedValue(0);
2829

2930
test('testing get-cmake with cache-miss...', async () => {
30-
const testId = Math.random();
31+
const testId = crypto.randomBytes(16).toString('hex');
3132
process.env.RUNNER_TEMP = path.join(os.tmpdir(), `${testId}`);
3233
const getter: ToolsGetter = new ToolsGetter();
3334
await getter.run();

__tests__/cacherestorefailure.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import * as os from 'os';
88
import { ToolsGetter } from '../src/get-cmake';
99
import * as cache from '@actions/cache';
1010
import path = require('path');
11+
import * as crypto from 'crypto';
1112

1213
// 10 minutes
1314
jest.setTimeout(10 * 60 * 1000)
@@ -24,7 +25,7 @@ jest.spyOn(cache, 'restoreCache').mockImplementation(() => {
2425
const addToolsToPath = jest.spyOn(ToolsGetter.prototype as any, 'addToolsToPath').mockResolvedValue(0);
2526

2627
test('testing get-cmake with restoreCache failure', async () => {
27-
const testId = Math.random();
28+
const testId = crypto.randomBytes(16).toString('hex');
2829
process.env.RUNNER_TEMP = path.join(os.tmpdir(), `${testId}`);
2930

3031
const getter: ToolsGetter = new ToolsGetter();

0 commit comments

Comments
 (0)