Skip to content

Commit 32bc120

Browse files
chore(tests): Mock arch to make tests pass on arm host (#191)
Also add Windows arm64 download link test now that arm64 runners exist for Windows.
1 parent 51463d6 commit 32bc120

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/run.test.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ describe('run.ts', () => {
6767
expect(os.arch).toHaveBeenCalled()
6868
})
6969

70-
test('getHelmDownloadURL() - return the URL to download helm for Windows', () => {
70+
test('getHelmDownloadURL() - return the URL to download helm for Windows x64', () => {
7171
jest.spyOn(os, 'platform').mockReturnValue('win32')
7272
jest.spyOn(os, 'arch').mockReturnValue('x64')
7373

@@ -76,6 +76,15 @@ describe('run.ts', () => {
7676
expect(os.platform).toHaveBeenCalled()
7777
})
7878

79+
test('getHelmDownloadURL() - return the URL to download helm for Windows arm64', () => {
80+
jest.spyOn(os, 'platform').mockReturnValue('win32')
81+
jest.spyOn(os, 'arch').mockReturnValue('arm64')
82+
83+
const expected = 'https://test.tld/helm-v3.8.0-windows-arm64.zip'
84+
expect(run.getHelmDownloadURL(downloadBaseURL, 'v3.8.0')).toBe(expected)
85+
expect(os.platform).toHaveBeenCalled()
86+
})
87+
7988
test('getLatestHelmVersion() - return the latest version of HELM', async () => {
8089
const res = {
8190
status: 200,
@@ -88,7 +97,7 @@ describe('run.ts', () => {
8897
test('getLatestHelmVersion() - return the stable version of HELM when simulating a network error', async () => {
8998
const errorMessage: string = 'Network Error'
9099
global.fetch = jest.fn().mockRejectedValueOnce(new Error(errorMessage))
91-
expect(await run.getLatestHelmVersion()).toBe('v3.13.3')
100+
expect(await run.getLatestHelmVersion()).toBe(run.stableHelmVersion)
92101
})
93102

94103
test('getValidVersion() - return version with v prepended', () => {
@@ -204,6 +213,7 @@ describe('run.ts', () => {
204213
const response = JSON.stringify([{tag_name: 'v4.0.0'}])
205214
jest.spyOn(fs, 'readFileSync').mockReturnValue(response)
206215
jest.spyOn(os, 'platform').mockReturnValue('win32')
216+
jest.spyOn(os, 'arch').mockReturnValue('x64')
207217
jest.spyOn(fs, 'chmodSync').mockImplementation(() => {})
208218
jest.spyOn(toolCache, 'extractZip').mockResolvedValue('extractedPath')
209219
jest.spyOn(toolCache, 'cacheDir').mockResolvedValue('pathToCachedDir')
@@ -239,6 +249,7 @@ describe('run.ts', () => {
239249
throw 'Unable to download'
240250
})
241251
jest.spyOn(os, 'platform').mockReturnValue('win32')
252+
jest.spyOn(os, 'arch').mockReturnValue('x64')
242253

243254
const downloadUrl = 'https://test.tld/helm-v3.2.1-windows-amd64.zip'
244255
await expect(run.downloadHelm(downloadBaseURL, 'v3.2.1')).rejects.toThrow(
@@ -254,6 +265,7 @@ describe('run.ts', () => {
254265
jest.spyOn(toolCache, 'downloadTool').mockResolvedValue('pathToTool')
255266
jest.spyOn(toolCache, 'extractZip').mockResolvedValue('extractedPath')
256267
jest.spyOn(os, 'platform').mockReturnValue('win32')
268+
jest.spyOn(os, 'arch').mockReturnValue('x64')
257269
jest.spyOn(fs, 'chmodSync').mockImplementation(() => {})
258270
jest
259271
.spyOn(fs, 'readdirSync')
@@ -283,6 +295,7 @@ describe('run.ts', () => {
283295
jest.spyOn(toolCache, 'downloadTool').mockResolvedValue('pathToTool')
284296
jest.spyOn(toolCache, 'extractZip').mockResolvedValue('extractedPath')
285297
jest.spyOn(os, 'platform').mockReturnValue('win32')
298+
jest.spyOn(os, 'arch').mockReturnValue('x64')
286299
jest.spyOn(fs, 'chmodSync').mockImplementation()
287300
jest.spyOn(fs, 'readdirSync').mockImplementation((file, _) => [])
288301
jest.spyOn(fs, 'statSync').mockImplementation((file) => {

src/run.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import * as toolCache from '@actions/tool-cache'
1010
import * as core from '@actions/core'
1111

1212
const helmToolName = 'helm'
13-
const stableHelmVersion = 'v3.13.3'
13+
export const stableHelmVersion = 'v3.13.3'
1414

1515
export async function run() {
1616
let version = core.getInput('version', {required: true})

0 commit comments

Comments
 (0)