mirror of
https://github.com/goreleaser/goreleaser-action.git
synced 2026-05-15 23:20:32 +00:00
add test
This commit is contained in:
parent
e0b67d079f
commit
e28cad84ee
1 changed files with 95 additions and 0 deletions
95
__tests__/version.test.ts
Normal file
95
__tests__/version.test.ts
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
import {describe, expect, it, beforeEach, afterEach, jest} from '@jest/globals';
|
||||
import * as fs from 'fs';
|
||||
import * as os from 'os';
|
||||
import * as path from 'path';
|
||||
import * as core from '@actions/core';
|
||||
import {getRequestedVersion} from '../src/version';
|
||||
import {Inputs} from '../src/context';
|
||||
|
||||
describe('getRequestedVersion', () => {
|
||||
let tmpDir: string;
|
||||
|
||||
beforeEach(() => {
|
||||
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'goreleaser-test-'));
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
try {
|
||||
fs.rmSync(tmpDir, {recursive: true, force: true});
|
||||
} catch (e) {
|
||||
console.error(`Failed to remove temp directory ${tmpDir}:`, e);
|
||||
}
|
||||
});
|
||||
|
||||
it('returns provided version when set', () => {
|
||||
const inputs: Inputs = {
|
||||
distribution: 'goreleaser',
|
||||
version: 'v1.2.3',
|
||||
versionFile: '',
|
||||
args: '',
|
||||
workdir: '',
|
||||
installOnly: false
|
||||
};
|
||||
|
||||
const v = getRequestedVersion(inputs);
|
||||
expect(v).toBe('v1.2.3');
|
||||
});
|
||||
|
||||
it('warns when both version and version-file are provided and returns version', () => {
|
||||
const inputs: Inputs = {
|
||||
distribution: 'goreleaser',
|
||||
version: 'v9.9.9',
|
||||
versionFile: '.tool-versions',
|
||||
args: '',
|
||||
workdir: '',
|
||||
installOnly: false
|
||||
};
|
||||
|
||||
const v = getRequestedVersion(inputs);
|
||||
expect(v).toBe('v9.9.9');
|
||||
});
|
||||
|
||||
it('throws when version is empty and version-file does not exist', () => {
|
||||
const inputs: Inputs = {
|
||||
distribution: 'goreleaser',
|
||||
version: '',
|
||||
versionFile: 'nonexistent-file',
|
||||
args: '',
|
||||
workdir: '',
|
||||
installOnly: false
|
||||
};
|
||||
|
||||
expect(() => getRequestedVersion(inputs)).toThrow();
|
||||
});
|
||||
|
||||
it('parses .tool-versions and returns v-prefixed version', () => {
|
||||
const toolVersionsPath = path.join(tmpDir, '.tool-versions');
|
||||
fs.writeFileSync(toolVersionsPath, 'goreleaser 1.2.3\n');
|
||||
|
||||
const inputs: Inputs = {
|
||||
distribution: 'goreleaser',
|
||||
version: '',
|
||||
versionFile: '.tool-versions',
|
||||
args: '',
|
||||
workdir: tmpDir,
|
||||
installOnly: false
|
||||
};
|
||||
|
||||
const v = getRequestedVersion(inputs);
|
||||
expect(v).toBe('v1.2.3');
|
||||
});
|
||||
|
||||
it('defaults to ~> v2 when nothing provided', () => {
|
||||
const inputs: Inputs = {
|
||||
distribution: 'goreleaser',
|
||||
version: '',
|
||||
versionFile: '',
|
||||
args: '',
|
||||
workdir: '',
|
||||
installOnly: false
|
||||
};
|
||||
|
||||
const v = getRequestedVersion(inputs);
|
||||
expect(v).toBe('~> v2');
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue