Skip to content

Commit

Permalink
Advance with coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
placintaalexandru committed Oct 28, 2023
1 parent 589c4fd commit 4e69808
Showing 1 changed file with 73 additions and 4 deletions.
77 changes: 73 additions & 4 deletions tests/installers/rustup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@ 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(),
}));
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() },
}));
Expand Down Expand Up @@ -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)`,
),
);

Expand Down Expand Up @@ -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);
},
);
});

0 comments on commit 4e69808

Please sign in to comment.