|
1 | 1 | import * as config from '../src/internal/shared/config'
|
| 2 | +import os from 'os' |
| 3 | + |
| 4 | +// Mock the 'os' module |
| 5 | +jest.mock('os', () => ({ |
| 6 | + cpus: jest.fn() |
| 7 | +})) |
2 | 8 |
|
3 | 9 | beforeEach(() => {
|
4 | 10 | jest.resetModules()
|
@@ -30,3 +36,66 @@ describe('isGhes', () => {
|
30 | 36 | expect(config.isGhes()).toBe(true)
|
31 | 37 | })
|
32 | 38 | })
|
| 39 | + |
| 40 | +describe('uploadChunkTimeoutEnv', () => { |
| 41 | + it('should return default 300000 when no env set', () => { |
| 42 | + expect(config.getUploadChunkTimeout()).toBe(300000) |
| 43 | + }) |
| 44 | + |
| 45 | + it('should return value set in ACTIONS_ARTIFACT_UPLOAD_TIMEOUT_MS', () => { |
| 46 | + process.env.ACTIONS_ARTIFACT_UPLOAD_TIMEOUT_MS = '150000' |
| 47 | + expect(config.getUploadChunkTimeout()).toBe(150000) |
| 48 | + }) |
| 49 | + |
| 50 | + it('should throw if value set in ACTIONS_ARTIFACT_UPLOAD_TIMEOUT_MS is invalid', () => { |
| 51 | + process.env.ACTIONS_ARTIFACT_UPLOAD_TIMEOUT_MS = 'abc' |
| 52 | + expect(() => { |
| 53 | + config.getUploadChunkTimeout() |
| 54 | + }).toThrow() |
| 55 | + }) |
| 56 | +}) |
| 57 | + |
| 58 | +describe('uploadConcurrencyEnv', () => { |
| 59 | + it('should return default 32 when cpu num is <= 4', () => { |
| 60 | + ;(os.cpus as jest.Mock).mockReturnValue(new Array(4)) |
| 61 | + expect(config.getConcurrency()).toBe(32) |
| 62 | + }) |
| 63 | + |
| 64 | + it('should return 16 * num of cpu when cpu num is > 4', () => { |
| 65 | + ;(os.cpus as jest.Mock).mockReturnValue(new Array(6)) |
| 66 | + expect(config.getConcurrency()).toBe(96) |
| 67 | + }) |
| 68 | + |
| 69 | + it('should return up to 300 max value', () => { |
| 70 | + ;(os.cpus as jest.Mock).mockReturnValue(new Array(32)) |
| 71 | + expect(config.getConcurrency()).toBe(300) |
| 72 | + }) |
| 73 | + |
| 74 | + it('should return override value when ACTIONS_ARTIFACT_UPLOAD_CONCURRENCY is set', () => { |
| 75 | + ;(os.cpus as jest.Mock).mockReturnValue(new Array(4)) |
| 76 | + process.env.ACTIONS_ARTIFACT_UPLOAD_CONCURRENCY = '10' |
| 77 | + expect(config.getConcurrency()).toBe(10) |
| 78 | + }) |
| 79 | + |
| 80 | + it('should throw with invalid value of ACTIONS_ARTIFACT_UPLOAD_CONCURRENCY', () => { |
| 81 | + ;(os.cpus as jest.Mock).mockReturnValue(new Array(4)) |
| 82 | + process.env.ACTIONS_ARTIFACT_UPLOAD_CONCURRENCY = 'abc' |
| 83 | + expect(() => { |
| 84 | + config.getConcurrency() |
| 85 | + }).toThrow() |
| 86 | + }) |
| 87 | + |
| 88 | + it('should throw if ACTIONS_ARTIFACT_UPLOAD_CONCURRENCY is < 1', () => { |
| 89 | + ;(os.cpus as jest.Mock).mockReturnValue(new Array(4)) |
| 90 | + process.env.ACTIONS_ARTIFACT_UPLOAD_CONCURRENCY = '0' |
| 91 | + expect(() => { |
| 92 | + config.getConcurrency() |
| 93 | + }).toThrow() |
| 94 | + }) |
| 95 | + |
| 96 | + it('cannot go over currency cap when override value is greater', () => { |
| 97 | + ;(os.cpus as jest.Mock).mockReturnValue(new Array(4)) |
| 98 | + process.env.ACTIONS_ARTIFACT_UPLOAD_CONCURRENCY = '40' |
| 99 | + expect(config.getConcurrency()).toBe(32) |
| 100 | + }) |
| 101 | +}) |
0 commit comments