mirror of
https://github.com/hashicorp/vault-action.git
synced 2026-04-16 08:45:44 +00:00
wip: replace jest with vitest
This commit is contained in:
parent
b379e88781
commit
fcac78057e
22 changed files with 2182 additions and 78 deletions
|
|
@ -111,8 +111,7 @@ async function exportSecrets() {
|
|||
|
||||
for (const line of value.replace(/\r/g, '').split('\n')) {
|
||||
if (line.length > 0) {
|
||||
// core.setSecret(line);
|
||||
core.setOutput(line);
|
||||
core.setSecret(line);
|
||||
}
|
||||
}
|
||||
if (exportEnv) {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import { jest } from '@jest/globals';
|
||||
import { vi, describe, test, expect } from 'vitest';
|
||||
|
||||
jest.mock('got');
|
||||
jest.mock('@actions/core');
|
||||
jest.mock('@actions/core/lib/command');
|
||||
vi.mock('got');
|
||||
vi.mock('@actions/core');
|
||||
vi.mock('@actions/core/lib/command');
|
||||
|
||||
import * as command from '@actions/core/lib/command';
|
||||
import * as core from '@actions/core';
|
||||
|
|
@ -134,7 +134,7 @@ describe('parseHeaders', () => {
|
|||
|
||||
describe('exportSecrets', () => {
|
||||
beforeEach(() => {
|
||||
jest.resetAllMocks();
|
||||
vi.resetAllMocks();
|
||||
|
||||
when(core.getInput)
|
||||
.calledWith('url', expect.anything())
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
import { jest } from '@jest/globals';
|
||||
import { vi, describe, test, expect } from 'vitest';
|
||||
|
||||
jest.mock('got');
|
||||
jest.mock('@actions/core');
|
||||
jest.mock('@actions/core/lib/command');
|
||||
jest.mock('fs', () => ({
|
||||
stat: jest.fn().mockResolvedValue(null),
|
||||
vi.mock('got');
|
||||
vi.mock('@actions/core');
|
||||
vi.mock('@actions/core/lib/command');
|
||||
vi.mock('fs', () => ({
|
||||
stat: vi.fn().mockResolvedValue(null),
|
||||
promises: {
|
||||
access: jest.fn().mockResolvedValue(null),
|
||||
access: vi.fn().mockResolvedValue(null),
|
||||
}
|
||||
}));
|
||||
|
||||
|
|
@ -26,7 +26,7 @@ function mockInput(name, key) {
|
|||
|
||||
function mockApiResponse() {
|
||||
const response = { body: { auth: { client_token: testToken, renewable: true, policies: [], accessor: "accessor" } } }
|
||||
got.post = jest.fn()
|
||||
got.post = vi.fn()
|
||||
got.post.mockReturnValue(response)
|
||||
}
|
||||
const testToken = "testoken";
|
||||
|
|
@ -34,7 +34,7 @@ const testToken = "testoken";
|
|||
describe("test retrival for token", () => {
|
||||
|
||||
beforeEach(() => {
|
||||
jest.resetAllMocks();
|
||||
vi.resetAllMocks();
|
||||
});
|
||||
|
||||
it("test retrival with approle", async () => {
|
||||
|
|
@ -75,7 +75,7 @@ describe("test retrival for token", () => {
|
|||
mockInput("kubernetesTokenPath", testTokenPath)
|
||||
mockInput("role", testRole)
|
||||
mockInput("path", testPath)
|
||||
fs.readFileSync = jest.fn()
|
||||
fs.readFileSync = vi.fn()
|
||||
fs.readFileSync.mockReturnValueOnce(jwtToken)
|
||||
const token = await retrieveToken(method, got)
|
||||
expect(token).toEqual(testToken)
|
||||
|
|
|
|||
|
|
@ -1,17 +1,19 @@
|
|||
jest.mock('@actions/core');
|
||||
import { vi, describe, test, expect } from 'vitest';
|
||||
|
||||
vi.mock('@actions/core');
|
||||
|
||||
import * as core from '@actions/core';
|
||||
import * as ServerMock from 'mock-http-server';
|
||||
import exportSecrets from './action.js';
|
||||
import { when } from 'jest-when'
|
||||
import ServerMock from 'mock-http-server';
|
||||
import { exportSecrets } from './action.js';
|
||||
import { when } from 'jest-when';
|
||||
|
||||
describe('exportSecrets retries', () => {
|
||||
var server = new ServerMock({ host: "127.0.0.1", port: 0 });
|
||||
var calls = 0;
|
||||
|
||||
beforeEach((done) => {
|
||||
beforeEach(() => new Promise(done => {
|
||||
calls = 0;
|
||||
jest.resetAllMocks();
|
||||
vi.resetAllMocks();
|
||||
|
||||
when(core.getInput)
|
||||
.calledWith('token', expect.anything())
|
||||
|
|
@ -28,11 +30,11 @@ describe('exportSecrets retries', () => {
|
|||
.mockReturnValueOnce('http://127.0.0.1:' + server.getHttpPort());
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
afterEach((done) => {
|
||||
afterEach(() => new Promise(done => {
|
||||
server.stop(done);
|
||||
});
|
||||
}));
|
||||
|
||||
function mockStatusCodes(statusCodes) {
|
||||
server.on({
|
||||
|
|
@ -51,19 +53,19 @@ describe('exportSecrets retries', () => {
|
|||
});
|
||||
}
|
||||
|
||||
it('retries on 412 status code', (done) => {
|
||||
it('retries on 412 status code', () => new Promise(done => {
|
||||
mockStatusCodes([412, 200])
|
||||
exportSecrets().then(() => {
|
||||
expect(calls).toEqual(2);
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('retries on 500 status code', (done) => {
|
||||
it('retries on 500 status code', () => new Promise(done => {
|
||||
mockStatusCodes([500, 200])
|
||||
exportSecrets().then(() => {
|
||||
expect(calls).toEqual(2);
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue