diff --git a/tests/installers/rustup.test.ts b/tests/installers/rustup.test.ts index 973f99ce..1eb45b95 100644 --- a/tests/installers/rustup.test.ts +++ b/tests/installers/rustup.test.ts @@ -4,6 +4,7 @@ import { RustUpInit } from "../../src/installers/rustup_init"; import * as mockedIo from "@actions/io"; import * as mockedExec from "@actions/exec"; import * as fcj from "@fast-check/jest"; +import semver = require("semver/preload"); jest.mock("@actions/io", () => ({ which: jest.fn(), @@ -11,6 +12,10 @@ jest.mock("@actions/io", () => ({ jest.mock("@actions/exec", () => ({ exec: jest.fn(), })); +jest.mock("@actions/core", () => ({ + info: jest.fn(), + warning: jest.fn(), +})); jest.mock("../../src/installers/rustup_init", () => ({ RustUpInit: { install: jest.fn() }, })); @@ -80,10 +85,8 @@ describe("Tests of rustup", () => { const rustUp = await RustUp.getOrInstall(); jest.spyOn(rustUp, "callStdout").mockReturnValue( - new Promise((resolve) => - resolve( - `rustup ${major}.${minor}.${patch} (5af9b9484 2023-04-05)`, - ), + Promise.resolve( + `rustup ${major}.${minor}.${patch} (5af9b9484 2023-04-05)`, ), ); @@ -258,4 +261,70 @@ describe("Tests of rustup", () => { undefined, ); }); + + test("Self update", async () => { + (mockedIo.which as jest.Mock).mockReturnValue( + Promise.resolve("/somepath/rustup"), + ); + + const rustUpPath = await mockedIo.which("rustup"); + const rustUp = await RustUp.getOrInstall(); + + await rustUp.selfUpdate(); + + expect(mockedExec.exec).toHaveBeenCalledTimes(1); + expect(mockedExec.exec).toHaveBeenCalledWith( + rustUpPath, + ["self", "update"], + undefined, + ); + }); + + fcj.test.prop([ + fcj.fc.integer({ min: 0, max: 1 }), + fcj.fc.integer({ min: 1, max: 19 }), + fcj.fc.integer({ min: 0, max: 1 }), + ])( + "Version: no support for profiles & components", + async (major, minor, patch) => { + (mockedIo.which as jest.Mock).mockReturnValue( + Promise.resolve("/somepath/rustup"), + ); + + const rustUp = await RustUp.getOrInstall(); + + jest.spyOn(rustUp, "version").mockReturnValue( + Promise.resolve( + semver.parse(`${major}.${minor}.${patch}`) as semver.SemVer, + ), + ); + + expect(await rustUp.supportProfiles()).toBe(false); + expect(await rustUp.supportComponents()).toBe(false); + }, + ); + + fcj.test.prop([ + fcj.fc.integer({ min: 1, max: 100 }), + fcj.fc.integer({ min: 20, max: 100 }), + fcj.fc.integer({ min: 1, max: 100 }), + ])( + "Version: support for profiles & components", + async (major, minor, patch) => { + (mockedIo.which as jest.Mock).mockReturnValue( + Promise.resolve("/somepath/rustup"), + ); + + const rustUp = await RustUp.getOrInstall(); + + jest.spyOn(rustUp, "version").mockReturnValue( + Promise.resolve( + semver.parse(`${major}.${minor}.${patch}`) as semver.SemVer, + ), + ); + + expect(await rustUp.supportProfiles()).toBe(true); + expect(await rustUp.supportComponents()).toBe(true); + }, + ); });