From bdc3c96b013664ce98feb303290a0b5b192f6d12 Mon Sep 17 00:00:00 2001 From: Danny McCormick Date: Thu, 20 Jun 2019 09:40:29 -0400 Subject: [PATCH] Add tests --- __tests__/installer.test.ts | 55 ++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/__tests__/installer.test.ts b/__tests__/installer.test.ts index 3bcd0ae..930aafd 100644 --- a/__tests__/installer.test.ts +++ b/__tests__/installer.test.ts @@ -17,5 +17,58 @@ describe('installer tests', () => { await io.rmRF(tempDir); }); - it('TODO - Add tests', async () => {}); + afterAll(async () => { + try { + await io.rmRF(toolDir); + await io.rmRF(tempDir); + } catch { + console.log('Failed to remove test directories'); + } + }, 100000); + + it('Acquires version of dotnet if no matching version is installed', async () => { + await getDotnet('2.2.104'); + const nodeDir = path.join(toolDir, 'dncs', '2.2.104', os.arch()); + + expect(fs.existsSync(`${nodeDir}.complete`)).toBe(true); + expect(fs.existsSync(path.join(nodeDir, 'dotnet.exe'))).toBe(true); + }, 100000); + + it('Throws if no location contains correct dotnet version', async () => { + let thrown = false; + try { + await getDotnet('1000.0.0') + } catch { + thrown = true; + } + expect(thrown).toBe(true); + }); + + it('Uses version of dotnet installed in cache', async () => { + const dotnetDir: string = path.join(toolDir, 'dncs', '250.0.0', os.arch()); + await io.mkdirP(dotnetDir); + fs.writeFileSync(`${dotnetDir}.complete`, 'hello'); + // This will throw if it doesn't find it in the cache (because no such version exists) + await getDotnet('250.0.0'); + return; + }); + + it('Doesnt use version of dotnet that was only partially installed in cache', async () => { + const dotnetDir: string = path.join(toolDir, 'dncs', '251.0.0', os.arch()); + await io.mkdirP(dotnetDir); + let thrown = false; + try { + // This will throw if it doesn't find it in the cache (because no such version exists) + await getDotnet('251.0.0'); + } catch { + thrown = true; + } + expect(thrown).toBe(true); + return; + }); }); + +async function getDotnet(version: string): Promise { + const dotnetInstaller = new installer.DotnetCoreInstaller(version); + await dotnetInstaller.installDotnet(); +}