4
0
Fork 0
mirror of https://github.com/Azure/setup-helm.git synced 2025-11-07 13:06:56 +00:00

Replace deprecated jest methods

This commit is contained in:
Dmytro Bondar 2024-01-30 10:57:48 +01:00
parent a21cf54d5c
commit fb7902fc39
No known key found for this signature in database
GPG key ID: 8CC54FADB0C40187

View file

@ -10,14 +10,14 @@ describe('run.ts', () => {
jest.spyOn(os, 'type').mockReturnValue('Windows_NT') jest.spyOn(os, 'type').mockReturnValue('Windows_NT')
expect(run.getExecutableExtension()).toBe('.exe') expect(run.getExecutableExtension()).toBe('.exe')
expect(os.type).toBeCalled() expect(os.type).toHaveBeenCalled()
}) })
test('getExecutableExtension() - return empty string for non-windows OS', () => { test('getExecutableExtension() - return empty string for non-windows OS', () => {
jest.spyOn(os, 'type').mockReturnValue('Darwin') jest.spyOn(os, 'type').mockReturnValue('Darwin')
expect(run.getExecutableExtension()).toBe('') expect(run.getExecutableExtension()).toBe('')
expect(os.type).toBeCalled() expect(os.type).toHaveBeenCalled()
}) })
test('getHelmDownloadURL() - return the URL to download helm for Linux', () => { test('getHelmDownloadURL() - return the URL to download helm for Linux', () => {
@ -30,8 +30,8 @@ describe('run.ts', () => {
expect(run.getHelmDownloadURL(downloadBaseURL, 'v3.8.0')).toBe( expect(run.getHelmDownloadURL(downloadBaseURL, 'v3.8.0')).toBe(
helmLinuxUrl helmLinuxUrl
) )
expect(os.type).toBeCalled() expect(os.type).toHaveBeenCalled()
expect(os.arch).toBeCalled() expect(os.arch).toHaveBeenCalled()
// arm64 // arm64
jest.spyOn(os, 'type').mockReturnValue('Linux') jest.spyOn(os, 'type').mockReturnValue('Linux')
@ -41,8 +41,8 @@ describe('run.ts', () => {
expect(run.getHelmDownloadURL(downloadBaseURL, 'v3.8.0')).toBe( expect(run.getHelmDownloadURL(downloadBaseURL, 'v3.8.0')).toBe(
helmLinuxArm64Url helmLinuxArm64Url
) )
expect(os.type).toBeCalled() expect(os.type).toHaveBeenCalled()
expect(os.arch).toBeCalled() expect(os.arch).toHaveBeenCalled()
}) })
test('getHelmDownloadURL() - return the URL to download helm for Darwin', () => { test('getHelmDownloadURL() - return the URL to download helm for Darwin', () => {
@ -55,8 +55,8 @@ describe('run.ts', () => {
expect(run.getHelmDownloadURL(downloadBaseURL, 'v3.8.0')).toBe( expect(run.getHelmDownloadURL(downloadBaseURL, 'v3.8.0')).toBe(
helmDarwinUrl helmDarwinUrl
) )
expect(os.type).toBeCalled() expect(os.type).toHaveBeenCalled()
expect(os.arch).toBeCalled() expect(os.arch).toHaveBeenCalled()
// arm64 // arm64
jest.spyOn(os, 'type').mockReturnValue('Darwin') jest.spyOn(os, 'type').mockReturnValue('Darwin')
@ -66,8 +66,8 @@ describe('run.ts', () => {
expect(run.getHelmDownloadURL(downloadBaseURL, 'v3.8.0')).toBe( expect(run.getHelmDownloadURL(downloadBaseURL, 'v3.8.0')).toBe(
helmDarwinArm64Url helmDarwinArm64Url
) )
expect(os.type).toBeCalled() expect(os.type).toHaveBeenCalled()
expect(os.arch).toBeCalled() expect(os.arch).toHaveBeenCalled()
}) })
test('getValidVersion() - return version with v prepended', () => { test('getValidVersion() - return version with v prepended', () => {
@ -83,7 +83,7 @@ describe('run.ts', () => {
expect(run.getHelmDownloadURL(downloadBaseURL, 'v3.8.0')).toBe( expect(run.getHelmDownloadURL(downloadBaseURL, 'v3.8.0')).toBe(
helmWindowsUrl helmWindowsUrl
) )
expect(os.type).toBeCalled() expect(os.type).toHaveBeenCalled()
}) })
test('getLatestHelmVersion() - return the stable version of HELM since its not authenticated', async () => { test('getLatestHelmVersion() - return the stable version of HELM since its not authenticated', async () => {
@ -120,8 +120,8 @@ describe('run.ts', () => {
expect(run.walkSync('mainFolder', null, 'file21')).toEqual([ expect(run.walkSync('mainFolder', null, 'file21')).toEqual([
path.join('mainFolder', 'folder2', 'file21') path.join('mainFolder', 'folder2', 'file21')
]) ])
expect(fs.readdirSync).toBeCalledTimes(3) expect(fs.readdirSync).toHaveBeenCalledTimes(3)
expect(fs.statSync).toBeCalledTimes(8) expect(fs.statSync).toHaveBeenCalledTimes(8)
}) })
test('walkSync() - return empty array if no file with name fileToFind exists', () => { test('walkSync() - return empty array if no file with name fileToFind exists', () => {
@ -152,8 +152,8 @@ describe('run.ts', () => {
}) })
expect(run.walkSync('mainFolder', null, 'helm.exe')).toEqual([]) expect(run.walkSync('mainFolder', null, 'helm.exe')).toEqual([])
expect(fs.readdirSync).toBeCalledTimes(3) expect(fs.readdirSync).toHaveBeenCalledTimes(3)
expect(fs.statSync).toBeCalledTimes(8) expect(fs.statSync).toHaveBeenCalledTimes(8)
}) })
test('findHelm() - change access permissions and find the helm in given directory', () => { test('findHelm() - change access permissions and find the helm in given directory', () => {
@ -212,13 +212,13 @@ describe('run.ts', () => {
expect(await run.downloadHelm(baseURL, 'v4.0.0')).toBe( expect(await run.downloadHelm(baseURL, 'v4.0.0')).toBe(
path.join('pathToCachedDir', 'helm.exe') path.join('pathToCachedDir', 'helm.exe')
) )
expect(toolCache.find).toBeCalledWith('helm', 'v4.0.0') expect(toolCache.find).toHaveBeenCalledWith('helm', 'v4.0.0')
expect(toolCache.downloadTool).toBeCalledWith( expect(toolCache.downloadTool).toHaveBeenCalledWith(
'https://test.tld/helm-v4.0.0-windows-amd64.zip' 'https://test.tld/helm-v4.0.0-windows-amd64.zip'
) )
expect(fs.chmodSync).toBeCalledWith('pathToTool', '777') expect(fs.chmodSync).toHaveBeenCalledWith('pathToTool', '777')
expect(toolCache.extractZip).toBeCalledWith('pathToTool') expect(toolCache.extractZip).toHaveBeenCalledWith('pathToTool')
expect(fs.chmodSync).toBeCalledWith( expect(fs.chmodSync).toHaveBeenCalledWith(
path.join('pathToCachedDir', 'helm.exe'), path.join('pathToCachedDir', 'helm.exe'),
'777' '777'
) )
@ -236,8 +236,8 @@ describe('run.ts', () => {
await expect(run.downloadHelm(baseURL, 'v3.2.1')).rejects.toThrow( await expect(run.downloadHelm(baseURL, 'v3.2.1')).rejects.toThrow(
'Failed to download Helm from location https://test.tld/helm-v3.2.1-windows-amd64.zip' 'Failed to download Helm from location https://test.tld/helm-v3.2.1-windows-amd64.zip'
) )
expect(toolCache.find).toBeCalledWith('helm', 'v3.2.1') expect(toolCache.find).toHaveBeenCalledWith('helm', 'v3.2.1')
expect(toolCache.downloadTool).toBeCalledWith( expect(toolCache.downloadTool).toHaveBeenCalledWith(
'https://test.tld/helm-v3.2.1-windows-amd64.zip' 'https://test.tld/helm-v3.2.1-windows-amd64.zip'
) )
}) })
@ -251,8 +251,8 @@ describe('run.ts', () => {
expect(await run.downloadHelm(baseURL, 'v3.2.1')).toBe( expect(await run.downloadHelm(baseURL, 'v3.2.1')).toBe(
path.join('pathToCachedDir', 'helm.exe') path.join('pathToCachedDir', 'helm.exe')
) )
expect(toolCache.find).toBeCalledWith('helm', 'v3.2.1') expect(toolCache.find).toHaveBeenCalledWith('helm', 'v3.2.1')
expect(fs.chmodSync).toBeCalledWith( expect(fs.chmodSync).toHaveBeenCalledWith(
path.join('pathToCachedDir', 'helm.exe'), path.join('pathToCachedDir', 'helm.exe'),
'777' '777'
) )
@ -279,11 +279,11 @@ describe('run.ts', () => {
await expect(run.downloadHelm(baseURL, 'v3.2.1')).rejects.toThrow( await expect(run.downloadHelm(baseURL, 'v3.2.1')).rejects.toThrow(
'Helm executable not found in path pathToCachedDir' 'Helm executable not found in path pathToCachedDir'
) )
expect(toolCache.find).toBeCalledWith('helm', 'v3.2.1') expect(toolCache.find).toHaveBeenCalledWith('helm', 'v3.2.1')
expect(toolCache.downloadTool).toBeCalledWith( expect(toolCache.downloadTool).toHaveBeenCalledWith(
'https://test.tld/helm-v3.2.1-windows-amd64.zip' 'https://test.tld/helm-v3.2.1-windows-amd64.zip'
) )
expect(fs.chmodSync).toBeCalledWith('pathToTool', '777') expect(fs.chmodSync).toHaveBeenCalledWith('pathToTool', '777')
expect(toolCache.extractZip).toBeCalledWith('pathToTool') expect(toolCache.extractZip).toHaveBeenCalledWith('pathToTool')
}) })
}) })