Skip to content
This repository has been archived by the owner on May 29, 2024. It is now read-only.

Commit

Permalink
Address warnings wih save-state
Browse files Browse the repository at this point in the history
  • Loading branch information
dexamundsen committed Mar 24, 2024
1 parent b9ca0b2 commit cc64233
Show file tree
Hide file tree
Showing 37 changed files with 7,480 additions and 5,726 deletions.
721 changes: 365 additions & 356 deletions __test__/git-auth-helper.test.ts

Large diffs are not rendered by default.

366 changes: 184 additions & 182 deletions __test__/git-directory-helper.test.ts

Large diffs are not rendered by default.

78 changes: 39 additions & 39 deletions __test__/git-version.test.ts
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
import {GitVersion} from '../lib/git-version'
import { GitVersion } from "../lib/git-version";

describe('git-version tests', () => {
it('basics', async () => {
let version = new GitVersion('')
expect(version.isValid()).toBeFalsy()
describe("git-version tests", () => {
it("basics", async () => {
let version = new GitVersion("");
expect(version.isValid()).toBeFalsy();

version = new GitVersion('asdf')
expect(version.isValid()).toBeFalsy()
version = new GitVersion("asdf");
expect(version.isValid()).toBeFalsy();

version = new GitVersion('1.2')
expect(version.isValid()).toBeTruthy()
expect(version.toString()).toBe('1.2')
version = new GitVersion("1.2");
expect(version.isValid()).toBeTruthy();
expect(version.toString()).toBe("1.2");

version = new GitVersion('1.2.3')
expect(version.isValid()).toBeTruthy()
expect(version.toString()).toBe('1.2.3')
})
version = new GitVersion("1.2.3");
expect(version.isValid()).toBeTruthy();
expect(version.toString()).toBe("1.2.3");
});

it('check minimum', async () => {
let version = new GitVersion('4.5')
expect(version.checkMinimum(new GitVersion('3.6'))).toBeTruthy()
expect(version.checkMinimum(new GitVersion('3.6.7'))).toBeTruthy()
expect(version.checkMinimum(new GitVersion('4.4'))).toBeTruthy()
expect(version.checkMinimum(new GitVersion('4.5'))).toBeTruthy()
expect(version.checkMinimum(new GitVersion('4.5.0'))).toBeTruthy()
expect(version.checkMinimum(new GitVersion('4.6'))).toBeFalsy()
expect(version.checkMinimum(new GitVersion('4.6.0'))).toBeFalsy()
expect(version.checkMinimum(new GitVersion('5.1'))).toBeFalsy()
expect(version.checkMinimum(new GitVersion('5.1.2'))).toBeFalsy()
it("check minimum", async () => {
let version = new GitVersion("4.5");
expect(version.checkMinimum(new GitVersion("3.6"))).toBeTruthy();
expect(version.checkMinimum(new GitVersion("3.6.7"))).toBeTruthy();
expect(version.checkMinimum(new GitVersion("4.4"))).toBeTruthy();
expect(version.checkMinimum(new GitVersion("4.5"))).toBeTruthy();
expect(version.checkMinimum(new GitVersion("4.5.0"))).toBeTruthy();
expect(version.checkMinimum(new GitVersion("4.6"))).toBeFalsy();
expect(version.checkMinimum(new GitVersion("4.6.0"))).toBeFalsy();
expect(version.checkMinimum(new GitVersion("5.1"))).toBeFalsy();
expect(version.checkMinimum(new GitVersion("5.1.2"))).toBeFalsy();

version = new GitVersion('4.5.6')
expect(version.checkMinimum(new GitVersion('3.6'))).toBeTruthy()
expect(version.checkMinimum(new GitVersion('3.6.7'))).toBeTruthy()
expect(version.checkMinimum(new GitVersion('4.4'))).toBeTruthy()
expect(version.checkMinimum(new GitVersion('4.5'))).toBeTruthy()
expect(version.checkMinimum(new GitVersion('4.5.5'))).toBeTruthy()
expect(version.checkMinimum(new GitVersion('4.5.6'))).toBeTruthy()
expect(version.checkMinimum(new GitVersion('4.5.7'))).toBeFalsy()
expect(version.checkMinimum(new GitVersion('4.6'))).toBeFalsy()
expect(version.checkMinimum(new GitVersion('4.6.0'))).toBeFalsy()
expect(version.checkMinimum(new GitVersion('5.1'))).toBeFalsy()
expect(version.checkMinimum(new GitVersion('5.1.2'))).toBeFalsy()
})
})
version = new GitVersion("4.5.6");
expect(version.checkMinimum(new GitVersion("3.6"))).toBeTruthy();
expect(version.checkMinimum(new GitVersion("3.6.7"))).toBeTruthy();
expect(version.checkMinimum(new GitVersion("4.4"))).toBeTruthy();
expect(version.checkMinimum(new GitVersion("4.5"))).toBeTruthy();
expect(version.checkMinimum(new GitVersion("4.5.5"))).toBeTruthy();
expect(version.checkMinimum(new GitVersion("4.5.6"))).toBeTruthy();
expect(version.checkMinimum(new GitVersion("4.5.7"))).toBeFalsy();
expect(version.checkMinimum(new GitVersion("4.6"))).toBeFalsy();
expect(version.checkMinimum(new GitVersion("4.6.0"))).toBeFalsy();
expect(version.checkMinimum(new GitVersion("5.1"))).toBeFalsy();
expect(version.checkMinimum(new GitVersion("5.1.2"))).toBeFalsy();
});
});
192 changes: 96 additions & 96 deletions __test__/input-helper.test.ts
Original file line number Diff line number Diff line change
@@ -1,133 +1,133 @@
import * as assert from 'assert'
import * as core from '@actions/core'
import * as fsHelper from '../lib/fs-helper'
import * as github from '@actions/github'
import * as inputHelper from '../lib/input-helper'
import * as path from 'path'
import {IGitSourceSettings} from '../lib/git-source-settings'
import * as assert from "assert";
import * as core from "@actions/core";
import * as fsHelper from "../lib/fs-helper";
import * as github from "@actions/github";
import * as inputHelper from "../lib/input-helper";
import * as path from "path";
import { IGitSourceSettings } from "../lib/git-source-settings";

const originalGitHubWorkspace = process.env['GITHUB_WORKSPACE']
const gitHubWorkspace = path.resolve('/checkout-tests/workspace')
const originalGitHubWorkspace = process.env["GITHUB_WORKSPACE"];
const gitHubWorkspace = path.resolve("/checkout-tests/workspace");

// Inputs for mock @actions/core
let inputs = {} as any
let inputs = {} as any;

// Shallow clone original @actions/github context
let originalContext = {...github.context}
let originalContext = { ...github.context };

describe('input-helper tests', () => {
describe("input-helper tests", () => {
beforeAll(() => {
// Mock getInput
jest.spyOn(core, 'getInput').mockImplementation((name: string) => {
return inputs[name]
})
jest.spyOn(core, "getInput").mockImplementation((name: string) => {
return inputs[name];
});

// Mock error/warning/info/debug
jest.spyOn(core, 'error').mockImplementation(jest.fn())
jest.spyOn(core, 'warning').mockImplementation(jest.fn())
jest.spyOn(core, 'info').mockImplementation(jest.fn())
jest.spyOn(core, 'debug').mockImplementation(jest.fn())
jest.spyOn(core, "error").mockImplementation(jest.fn());
jest.spyOn(core, "warning").mockImplementation(jest.fn());
jest.spyOn(core, "info").mockImplementation(jest.fn());
jest.spyOn(core, "debug").mockImplementation(jest.fn());

// Mock github context
jest.spyOn(github.context, 'repo', 'get').mockImplementation(() => {
jest.spyOn(github.context, "repo", "get").mockImplementation(() => {
return {
owner: 'some-owner',
repo: 'some-repo'
}
})
github.context.ref = 'refs/heads/some-ref'
github.context.sha = '1234567890123456789012345678901234567890'
owner: "some-owner",
repo: "some-repo"
};
});
github.context.ref = "refs/heads/some-ref";
github.context.sha = "1234567890123456789012345678901234567890";

// Mock ./fs-helper directoryExistsSync()
jest
.spyOn(fsHelper, 'directoryExistsSync')
.mockImplementation((path: string) => path == gitHubWorkspace)
.spyOn(fsHelper, "directoryExistsSync")
.mockImplementation((path: string) => path == gitHubWorkspace);

// GitHub workspace
process.env['GITHUB_WORKSPACE'] = gitHubWorkspace
})
process.env["GITHUB_WORKSPACE"] = gitHubWorkspace;
});

beforeEach(() => {
// Reset inputs
inputs = {}
})
inputs = {};
});

afterAll(() => {
// Restore GitHub workspace
delete process.env['GITHUB_WORKSPACE']
delete process.env["GITHUB_WORKSPACE"];
if (originalGitHubWorkspace) {
process.env['GITHUB_WORKSPACE'] = originalGitHubWorkspace
process.env["GITHUB_WORKSPACE"] = originalGitHubWorkspace;
}

// Restore @actions/github context
github.context.ref = originalContext.ref
github.context.sha = originalContext.sha
github.context.ref = originalContext.ref;
github.context.sha = originalContext.sha;

// Restore
jest.restoreAllMocks()
})

it('sets defaults', () => {
const settings: IGitSourceSettings = inputHelper.getInputs()
expect(settings).toBeTruthy()
expect(settings.authToken).toBeFalsy()
expect(settings.clean).toBe(true)
expect(settings.commit).toBeTruthy()
expect(settings.commit).toBe('1234567890123456789012345678901234567890')
expect(settings.fetchDepth).toBe(1)
expect(settings.lfs).toBe(false)
expect(settings.ref).toBe('refs/heads/some-ref')
expect(settings.repositoryName).toBe('some-repo')
expect(settings.repositoryOwner).toBe('some-owner')
expect(settings.repositoryPath).toBe(gitHubWorkspace)
})

it('qualifies ref', () => {
let originalRef = github.context.ref
jest.restoreAllMocks();
});

it("sets defaults", () => {
const settings: IGitSourceSettings = inputHelper.getInputs();
expect(settings).toBeTruthy();
expect(settings.authToken).toBeFalsy();
expect(settings.clean).toBe(true);
expect(settings.commit).toBeTruthy();
expect(settings.commit).toBe("1234567890123456789012345678901234567890");
expect(settings.fetchDepth).toBe(1);
expect(settings.lfs).toBe(false);
expect(settings.ref).toBe("refs/heads/some-ref");
expect(settings.repositoryName).toBe("some-repo");
expect(settings.repositoryOwner).toBe("some-owner");
expect(settings.repositoryPath).toBe(gitHubWorkspace);
});

it("qualifies ref", () => {
let originalRef = github.context.ref;
try {
github.context.ref = 'some-unqualified-ref'
const settings: IGitSourceSettings = inputHelper.getInputs()
expect(settings).toBeTruthy()
expect(settings.commit).toBe('1234567890123456789012345678901234567890')
expect(settings.ref).toBe('refs/heads/some-unqualified-ref')
github.context.ref = "some-unqualified-ref";
const settings: IGitSourceSettings = inputHelper.getInputs();
expect(settings).toBeTruthy();
expect(settings.commit).toBe("1234567890123456789012345678901234567890");
expect(settings.ref).toBe("refs/heads/some-unqualified-ref");
} finally {
github.context.ref = originalRef
github.context.ref = originalRef;
}
})
});

it('requires qualified repo', () => {
inputs.repository = 'some-unqualified-repo'
it("requires qualified repo", () => {
inputs.repository = "some-unqualified-repo";
assert.throws(() => {
inputHelper.getInputs()
}, /Invalid repository 'some-unqualified-repo'/)
})
inputHelper.getInputs();
}, /Invalid repository 'some-unqualified-repo'/);
});

it('roots path', () => {
inputs.path = 'some-directory/some-subdirectory'
const settings: IGitSourceSettings = inputHelper.getInputs()
it("roots path", () => {
inputs.path = "some-directory/some-subdirectory";
const settings: IGitSourceSettings = inputHelper.getInputs();
expect(settings.repositoryPath).toBe(
path.join(gitHubWorkspace, 'some-directory', 'some-subdirectory')
)
})

it('sets correct default ref/sha for other repo', () => {
inputs.repository = 'some-owner/some-other-repo'
const settings: IGitSourceSettings = inputHelper.getInputs()
expect(settings.ref).toBe('refs/heads/master')
expect(settings.commit).toBeFalsy()
})

it('sets ref to empty when explicit sha', () => {
inputs.ref = '1111111111222222222233333333334444444444'
const settings: IGitSourceSettings = inputHelper.getInputs()
expect(settings.ref).toBeFalsy()
expect(settings.commit).toBe('1111111111222222222233333333334444444444')
})

it('sets sha to empty when explicit ref', () => {
inputs.ref = 'refs/heads/some-other-ref'
const settings: IGitSourceSettings = inputHelper.getInputs()
expect(settings.ref).toBe('refs/heads/some-other-ref')
expect(settings.commit).toBeFalsy()
})
})
path.join(gitHubWorkspace, "some-directory", "some-subdirectory")
);
});

it("sets correct default ref/sha for other repo", () => {
inputs.repository = "some-owner/some-other-repo";
const settings: IGitSourceSettings = inputHelper.getInputs();
expect(settings.ref).toBe("refs/heads/master");
expect(settings.commit).toBeFalsy();
});

it("sets ref to empty when explicit sha", () => {
inputs.ref = "1111111111222222222233333333334444444444";
const settings: IGitSourceSettings = inputHelper.getInputs();
expect(settings.ref).toBeFalsy();
expect(settings.commit).toBe("1111111111222222222233333333334444444444");
});

it("sets sha to empty when explicit ref", () => {
inputs.ref = "refs/heads/some-other-ref";
const settings: IGitSourceSettings = inputHelper.getInputs();
expect(settings.ref).toBe("refs/heads/some-other-ref");
expect(settings.commit).toBeFalsy();
});
});
Loading

0 comments on commit cc64233

Please sign in to comment.