Skip to content

Commit

Permalink
Adding unit tests (#13)
Browse files Browse the repository at this point in the history
* add initial tests for jdkfile, zulu and base class

* add fail-fast: false

* work on possible fix

* fixing tests

* fixing format and create create release

* add possible fix

* V malob/adopt tests (#2)

* implement adopt tests

* fix nitpicks

* return debug back

* remove to-do

* remove workflow file

* resolving a part of comments

* add changes

* resolving a part of comments

* work on resolving comments

* resolve comment

* fix calls

* resolving comments

* fixing tests

* add method with support build version

* improve tests (#3)

* improve tests

* Update installer.ts

* fix version resolution

* Update index.js

* remove import

* resolving comments

* remove extra describe and afterEach

Co-authored-by: Maxim Lobanov <[email protected]>
  • Loading branch information
dmitry-shibanov and Maxim Lobanov authored Mar 5, 2021
1 parent 5f4cba8 commit 60cdc3b
Show file tree
Hide file tree
Showing 17 changed files with 2,018 additions and 383 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ jobs:
- run: npm ci
- run: npm run build
- run: npm run format-check
# TO-DO: Uncomment jest tests when unit-tests are fixed
#- run: npm test
- run: npm test
- name: Verify no unstaged changes
if: runner.os != 'windows'
run: bash __tests__/verify-no-unstaged-changes.sh
24 changes: 12 additions & 12 deletions __tests__/auth.test.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
import io = require('@actions/io');
import fs = require('fs');
import os = require('os');
import path = require('path');

// make the os.homedir() call be local to the tests
jest.doMock('os', () => {
return {
homedir: jest.fn(() => __dirname)
};
});
import os from 'os';

import * as auth from '../src/auth';

const m2Dir = path.join(__dirname, auth.M2_DIR);
const settingsFile = path.join(m2Dir, auth.SETTINGS_FILE);

describe('auth tests', () => {
let spyOSHomedir: jest.SpyInstance;

beforeEach(async () => {
await io.rmRF(m2Dir);
spyOSHomedir = jest.spyOn(os, 'homedir');
spyOSHomedir.mockReturnValue(__dirname);
}, 300000);

afterAll(async () => {
Expand All @@ -26,6 +23,9 @@ describe('auth tests', () => {
} catch {
console.log('Failed to remove test directories');
}
jest.resetAllMocks();
jest.clearAllMocks();
jest.restoreAllMocks();
}, 100000);

it('creates settings.xml in alternate locations', async () => {
Expand All @@ -38,7 +38,7 @@ describe('auth tests', () => {
process.env[`INPUT_SETTINGS-PATH`] = altHome;
await io.rmRF(altHome); // ensure it doesn't already exist

await auth.configAuthentication(id, username, password);
await auth.createAuthenticationSettings(id, username, password);

expect(fs.existsSync(m2Dir)).toBe(false);
expect(fs.existsSync(settingsFile)).toBe(false);
Expand All @@ -58,7 +58,7 @@ describe('auth tests', () => {
const username = 'UNAME';
const password = 'TOKEN';

await auth.configAuthentication(id, username, password);
await auth.createAuthenticationSettings(id, username, password);

expect(fs.existsSync(m2Dir)).toBe(true);
expect(fs.existsSync(settingsFile)).toBe(true);
Expand All @@ -71,7 +71,7 @@ describe('auth tests', () => {
const password = 'TOKEN';
const gpgPassphrase = 'GPG';

await auth.configAuthentication(id, username, password, gpgPassphrase);
await auth.createAuthenticationSettings(id, username, password, gpgPassphrase);

expect(fs.existsSync(m2Dir)).toBe(true);
expect(fs.existsSync(settingsFile)).toBe(true);
Expand All @@ -90,7 +90,7 @@ describe('auth tests', () => {
expect(fs.existsSync(m2Dir)).toBe(true);
expect(fs.existsSync(settingsFile)).toBe(true);

await auth.configAuthentication(id, username, password);
await auth.createAuthenticationSettings(id, username, password);

expect(fs.existsSync(m2Dir)).toBe(true);
expect(fs.existsSync(settingsFile)).toBe(true);
Expand Down
Loading

0 comments on commit 60cdc3b

Please sign in to comment.