Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
placintaalexandru committed Nov 1, 2023
1 parent 537521f commit 6347a0e
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 26 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/test_components.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ jobs:
toolchain: nightly
profile: minimal
override: true
# Clippy is not included in minimal, so this would force to get clippy as well
components: clippy
# 2 components not included within the minimal profile
components: clippy, miri

- name: Test clippy exists
run: cargo clippy -V

- name: Test miri exists
run: cargo miri -V
install_in_docker:
runs-on: ubuntu-latest
# Docker image, not the GitHub Actions VM
Expand All @@ -44,12 +46,11 @@ jobs:
toolchain: nightly
profile: minimal
override: true
# Clippy is not included in minimal, so this would force to get clippy
# and miri as well
# 2 components not included within the minimal profile
components: clippy, miri

- name: Test clippy exists
run: cargo clippy -V

- name: Test rls exists
- name: Test miri exists
run: cargo miri -V
4 changes: 2 additions & 2 deletions .github/workflows/test_install_as_default_toolchain.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:

- name: Test toolchain version
run: |
test "${{ steps.toolchain.outputs.rustc }}" = "${{ matrix.toolchain }}" || (echo "Expected: ${{ matrix.toolchain }}; Got: ${{ steps.toolchain.outputs.rustc }}" && exit 1)
test "${{ steps.toolchain.outputs.rustc }}" = "${{ matrix.toolchain }}"
install_in_docker:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -54,4 +54,4 @@ jobs:

- name: Test toolchain version
run: |
test "${{ steps.toolchain.outputs.rustc }}" = "${{ matrix.toolchain }}" || (echo "Expected: ${{ matrix.toolchain }}; Got: ${{ steps.toolchain.outputs.rustc }}" && exit 1)
test "${{ steps.toolchain.outputs.rustc }}" = "${{ matrix.toolchain }}"
17 changes: 8 additions & 9 deletions .github/workflows/test_stable_nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,10 @@ jobs:
CARGO: ${{ steps.toolchain.outputs.cargo }}
RUSTUP: ${{ steps.toolchain.outputs.rustup }}
run: |
echo $RUSTC
echo $RUSTC_HASH
echo $CARGO
echo $RUSTUP
echo "$RUSTC" && test "$RUSTC"
echo "$RUSTC_HASH" && test "$RUSTC_HASH"
echo "$CARGO" && test "$CARGO"
echo "$RUSTUP" && test "$RUSTUP"
install_in_docker:
runs-on: ubuntu-latest
strategy:
Expand Down Expand Up @@ -69,7 +68,7 @@ jobs:
CARGO: ${{ steps.toolchain.outputs.cargo }}
RUSTUP: ${{ steps.toolchain.outputs.rustup }}
run: |
echo $RUSTC
echo $RUSTC_HASH
echo $CARGO
echo $RUSTUP
echo "$RUSTC" && test "$RUSTC"
echo "$RUSTC_HASH" && test "$RUSTC_HASH"
echo "$CARGO" && test "$CARGO"
echo "$RUSTUP" && test "$RUSTUP"
6 changes: 2 additions & 4 deletions .github/workflows/test_targets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ jobs:
- name: Test ${{ matrix.target }} exists
# We check for 3 as we expect the target for the current runner + 2
# from the target from the matrix
run: |
( test $(rustup target list | grep -c installed) -eq 3 ) || ( echo "Targets ${{ matrix.target }} not installed properly installed" && exit 1 )
run: test $(rustup target list | grep -c installed) -eq 3

install_in_docker:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -59,5 +58,4 @@ jobs:
- name: Test ${{ matrix.target }} exists
# We check for 3 as we expect the target for the current runner + 2
# from the target from the matrix
run: |
( test $(rustup target list | grep -c installed) -eq 3 ) || ( echo "Targets ${{ matrix.target }} not installed properly installed" && exit 1 )
run: test $(rustup target list | grep -c installed) -eq 3
4 changes: 2 additions & 2 deletions .github/workflows/test_toolchain_version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:

- name: Test toolchain version
run: |
test "${{ steps.toolchain.outputs.rustc }}" = "${{ matrix.toolchain }}" || (echo "Expected: ${{ matrix.toolchain }}; Got: ${{ steps.toolchain.outputs.rustc }}" && exit 1)
test "${{ steps.toolchain.outputs.rustc }}" = "${{ matrix.toolchain }}"
install_in_docker:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -54,4 +54,4 @@ jobs:

- name: Test toolchain version
run: |
test "${{ steps.toolchain.outputs.rustc }}" = "${{ matrix.toolchain }}" || (echo "Expected: ${{ matrix.toolchain }}; Got: ${{ steps.toolchain.outputs.rustc }}" && exit 1)
test "${{ steps.toolchain.outputs.rustc }}" = "${{ matrix.toolchain }}"
36 changes: 32 additions & 4 deletions tests/toolchain_install.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { installToolchainCommand } from "../src/toolchain_install";
import { RustUp } from "../src/installers/rustup";
import { Outputs } from "../src/output";
import * as mockedCore from "@actions/core";
import * as mockedToolchainUtil from "../src/utils/toolchain";

jest.mock("@actions/exec", () => ({
exec: jest.fn(),
Expand All @@ -24,6 +25,7 @@ jest.mock("../src/output", () => ({
outputs: jest.fn(),
},
}));
jest.mock("../src/utils/toolchain");

describe("Tests of toolchain command", () => {
const originalEnv = process.env;
Expand All @@ -44,9 +46,38 @@ describe("Tests of toolchain command", () => {
jest.resetAllMocks();
});

test("Install toolchain: rust toolchain file", () => {
mockedRustUp.supportProfiles.mockReturnValue(Promise.resolve(true));
(RustUp.getOrInstall as jest.Mock).mockImplementation(async () => {
return Promise.resolve(mockedRustUp);
});
(Outputs.outputs as jest.Mock).mockReturnValue(Promise.resolve([]));
(mockedToolchainUtil.rustToolchainFile as jest.Mock).mockReturnValue(
"rust-toolchain.toml",
);

const toolchainArgs = {
toolchain: "some toolchain",
profile: "a profile",
};
(mockedToolchainUtil.toolchainArgs as jest.Mock).mockReturnValue(
toolchainArgs,
);

installToolchainCommand()
.hook("postAction", () => {
expect(mockedToolchainUtil.toolchainArgs).toHaveBeenCalledWith(
"rust-toolchain.toml",
);
expect(mockedRustUp.setProfile).toHaveBeenCalledWith(
toolchainArgs.profile,
);
})
.parse([]);
});

test("Install toolchain: should self update due to profiles", () => {
mockedRustUp.supportProfiles.mockReturnValue(Promise.resolve(false));

(RustUp.getOrInstall as jest.Mock).mockImplementation(async () => {
return Promise.resolve(mockedRustUp);
});
Expand All @@ -61,7 +92,6 @@ describe("Tests of toolchain command", () => {

test("Install toolchain: should self update due to components", () => {
mockedRustUp.supportComponents.mockReturnValue(Promise.resolve(false));

(RustUp.getOrInstall as jest.Mock).mockImplementation(async () => {
return Promise.resolve(mockedRustUp);
});
Expand All @@ -83,7 +113,6 @@ describe("Tests of toolchain command", () => {

test("Install toolchain: profile is set", () => {
mockedRustUp.supportComponents.mockReturnValue(Promise.resolve(false));

(RustUp.getOrInstall as jest.Mock).mockImplementation(async () => {
return Promise.resolve(mockedRustUp);
});
Expand All @@ -101,7 +130,6 @@ describe("Tests of toolchain command", () => {
test("Install toolchain: downgrade on nightly", () => {
mockedRustUp.supportProfiles.mockReturnValue(Promise.resolve(true));
mockedRustUp.supportComponents.mockReturnValue(Promise.resolve(true));

(RustUp.getOrInstall as jest.Mock).mockImplementation(async () => {
return Promise.resolve(mockedRustUp);
});
Expand Down

0 comments on commit 6347a0e

Please sign in to comment.