From 62079dbf4b1cfd5e3aaa2135a0a228dd46ad68cb Mon Sep 17 00:00:00 2001
From: Dmitry Shibanov <shibanov-1997@inbox.ru>
Date: Mon, 9 May 2022 11:16:24 +0200
Subject: [PATCH] fix tests

---
 __tests__/find-pypy.test.ts    | 44 ++++++++++++++++++++++++++++++++++
 __tests__/finder.test.ts       |  7 ++++++
 __tests__/install-pypy.test.ts | 34 ++++++++++++++++++++++++--
 3 files changed, 83 insertions(+), 2 deletions(-)

diff --git a/__tests__/find-pypy.test.ts b/__tests__/find-pypy.test.ts
index a72b4ba2..fa4a1806 100644
--- a/__tests__/find-pypy.test.ts
+++ b/__tests__/find-pypy.test.ts
@@ -63,6 +63,12 @@ describe('findPyPyToolCache', () => {
   const pypyPath = path.join('PyPy', actualPythonVersion, architecture);
   let tcFind: jest.SpyInstance;
   let spyReadExactPyPyVersion: jest.SpyInstance;
+  let infoSpy: jest.SpyInstance;
+  let warningSpy: jest.SpyInstance;
+  let debugSpy: jest.SpyInstance;
+  let addPathSpy: jest.SpyInstance;
+  let exportVariableSpy: jest.SpyInstance;
+  let setOutputSpy: jest.SpyInstance;
 
   beforeEach(() => {
     tcFind = jest.spyOn(tc, 'find');
@@ -75,6 +81,24 @@ describe('findPyPyToolCache', () => {
 
     spyReadExactPyPyVersion = jest.spyOn(utils, 'readExactPyPyVersionFile');
     spyReadExactPyPyVersion.mockImplementation(() => actualPyPyVersion);
+
+    infoSpy = jest.spyOn(core, 'info');
+    infoSpy.mockImplementation(() => null);
+
+    warningSpy = jest.spyOn(core, 'warning');
+    warningSpy.mockImplementation(() => null);
+
+    debugSpy = jest.spyOn(core, 'debug');
+    debugSpy.mockImplementation(() => null);
+
+    addPathSpy = jest.spyOn(core, 'addPath');
+    addPathSpy.mockImplementation(() => null);
+
+    exportVariableSpy = jest.spyOn(core, 'exportVariable');
+    exportVariableSpy.mockImplementation(() => null);
+
+    setOutputSpy = jest.spyOn(core, 'setOutput');
+    setOutputSpy.mockImplementation(() => null);
   });
 
   afterEach(() => {
@@ -118,7 +142,12 @@ describe('findPyPyToolCache', () => {
 
 describe('findPyPyVersion', () => {
   let getBooleanInputSpy: jest.SpyInstance;
+  let warningSpy: jest.SpyInstance;
+  let debugSpy: jest.SpyInstance;
   let infoSpy: jest.SpyInstance;
+  let addPathSpy: jest.SpyInstance;
+  let exportVariableSpy: jest.SpyInstance;
+  let setOutputSpy: jest.SpyInstance;
   let tcFind: jest.SpyInstance;
   let spyExtractZip: jest.SpyInstance;
   let spyExtractTar: jest.SpyInstance;
@@ -140,6 +169,21 @@ describe('findPyPyVersion', () => {
     infoSpy = jest.spyOn(core, 'info');
     infoSpy.mockImplementation(() => {});
 
+    warningSpy = jest.spyOn(core, 'warning');
+    warningSpy.mockImplementation(() => null);
+
+    debugSpy = jest.spyOn(core, 'debug');
+    debugSpy.mockImplementation(() => null);
+
+    addPathSpy = jest.spyOn(core, 'addPath');
+    addPathSpy.mockImplementation(() => null);
+
+    exportVariableSpy = jest.spyOn(core, 'exportVariable');
+    exportVariableSpy.mockImplementation(() => null);
+
+    setOutputSpy = jest.spyOn(core, 'setOutput');
+    setOutputSpy.mockImplementation(() => null);
+
     tcFind = jest.spyOn(tc, 'find');
     tcFind.mockImplementation((tool: string, version: string) => {
       const semverRange = new semver.Range(version);
diff --git a/__tests__/finder.test.ts b/__tests__/finder.test.ts
index ed0a4e46..c3c5ec32 100644
--- a/__tests__/finder.test.ts
+++ b/__tests__/finder.test.ts
@@ -27,6 +27,13 @@ import * as installer from '../src/install-python';
 const manifestData = require('./data/versions-manifest.json');
 
 describe('Finder tests', () => {
+  let writeSpy: jest.SpyInstance;
+
+  beforeEach(() => {
+    writeSpy = jest.spyOn(process.stdout, 'write');
+    writeSpy.mockImplementation(() => {});
+  });
+
   afterEach(() => {
     jest.resetAllMocks();
     jest.clearAllMocks();
diff --git a/__tests__/install-pypy.test.ts b/__tests__/install-pypy.test.ts
index cffc90e8..ae7fb4a6 100644
--- a/__tests__/install-pypy.test.ts
+++ b/__tests__/install-pypy.test.ts
@@ -4,6 +4,7 @@ import {HttpClient} from '@actions/http-client';
 import * as ifm from '@actions/http-client/interfaces';
 import * as tc from '@actions/tool-cache';
 import * as exec from '@actions/exec';
+import * as core from '@actions/core';
 import * as path from 'path';
 
 import * as installer from '../src/install-pypy';
@@ -51,6 +52,22 @@ describe('findRelease', () => {
     download_url: `https://test.download.python.org/pypy/pypy3.6-v7.3.3-${extensionName}`
   };
 
+  let getBooleanInputSpy: jest.SpyInstance;
+  let warningSpy: jest.SpyInstance;
+  let debugSpy: jest.SpyInstance;
+  let infoSpy: jest.SpyInstance;
+
+  beforeEach(() => {
+    infoSpy = jest.spyOn(core, 'info');
+    infoSpy.mockImplementation(() => {});
+
+    warningSpy = jest.spyOn(core, 'warning');
+    warningSpy.mockImplementation(() => null);
+
+    debugSpy = jest.spyOn(core, 'debug');
+    debugSpy.mockImplementation(() => null);
+  });
+
   it("Python version is found, but PyPy version doesn't match", () => {
     const pythonVersion = '3.6';
     const pypyVersion = '7.3.7';
@@ -133,6 +150,10 @@ describe('findRelease', () => {
 
 describe('installPyPy', () => {
   let tcFind: jest.SpyInstance;
+  let getBooleanInputSpy: jest.SpyInstance;
+  let warningSpy: jest.SpyInstance;
+  let debugSpy: jest.SpyInstance;
+  let infoSpy: jest.SpyInstance;
   let spyExtractZip: jest.SpyInstance;
   let spyExtractTar: jest.SpyInstance;
   let spyFsReadDir: jest.SpyInstance;
@@ -158,6 +179,15 @@ describe('installPyPy', () => {
     spyExtractTar = jest.spyOn(tc, 'extractTar');
     spyExtractTar.mockImplementation(() => tempDir);
 
+    infoSpy = jest.spyOn(core, 'info');
+    infoSpy.mockImplementation(() => {});
+
+    warningSpy = jest.spyOn(core, 'warning');
+    warningSpy.mockImplementation(() => null);
+
+    debugSpy = jest.spyOn(core, 'debug');
+    debugSpy.mockImplementation(() => null);
+
     spyFsReadDir = jest.spyOn(fs, 'readdirSync');
     spyFsReadDir.mockImplementation(() => ['PyPyTest']);
 
@@ -194,7 +224,7 @@ describe('installPyPy', () => {
 
   it('throw if release is not found', async () => {
     await expect(
-      installer.installPyPy('7.3.3', '3.6.17', architecture)
+      installer.installPyPy('7.3.3', '3.6.17', architecture, undefined)
     ).rejects.toThrowError(
       `PyPy version 3.6.17 (7.3.3) with arch ${architecture} not found`
     );
@@ -214,7 +244,7 @@ describe('installPyPy', () => {
     spyChmodSync.mockImplementation(() => undefined);
 
     await expect(
-      installer.installPyPy('7.3.x', '3.6.12', architecture)
+      installer.installPyPy('7.3.x', '3.6.12', architecture, undefined)
     ).resolves.toEqual({
       installDir: path.join(toolDir, 'PyPy', '3.6.12', architecture),
       resolvedPythonVersion: '3.6.12',