1
0
mirror of https://github.com/joaquinjsb/gitea-release-please-action synced 2026-05-05 10:37:47 +02:00

fix: get the correct boolean value of the input (#233)

This commit is contained in:
yi_Xu
2021-02-18 03:56:51 +08:00
committed by GitHub
parent eea7db7fda
commit c23605fcb2
3 changed files with 97 additions and 28 deletions

View File

@@ -5,6 +5,19 @@ const core = require('@actions/core')
const sinon = require('sinon')
const { factory, GitHubRelease } = require('release-please/build/src')
const { Node } = require('release-please/build/src/releasers/node')
// As defined in action.yml
const defaultInput = {
fork: 'false',
clean: 'true',
'bump-minor-pre-major': 'false',
path: '',
'monorepo-tags': 'false',
'changelog-path': '',
'changelog-types': '',
command: '',
'version-file': '',
'default-branch': ''
}
const sandbox = sinon.createSandbox()
process.env.GITHUB_REPOSITORY = 'google/cloud'
@@ -14,6 +27,47 @@ describe('release-please-action', () => {
sandbox.restore()
})
const trueValue = ['true', 'True', 'TRUE', 'yes', 'Yes', 'YES', 'y', 'Y', 'on', 'On', 'ON']
const falseValue = ['false', 'False', 'FALSE', 'no', 'No', 'NO', 'n', 'N', 'off', 'Off', 'OFF']
trueValue.forEach(value => {
it(`get the boolean true with the input of '${value}'`, () => {
const input = {
fork: value
}
core.getInput = (name) => {
return input[name] || defaultInput[name]
}
const actual = action.getBooleanInput('fork')
assert.strictEqual(actual, true)
})
})
falseValue.forEach(value => {
it(`get the boolean with the input of '${value}'`, () => {
const input = {
fork: value
}
core.getInput = (name) => {
return input[name] || defaultInput[name]
}
const actual = action.getBooleanInput('fork')
assert.strictEqual(actual, false)
})
})
it('get an error when inputting the wrong boolean value', () => {
const input = {
fork: 'wrong'
}
core.getInput = (name) => {
return input[name] || defaultInput[name]
}
assert.throws(() => {
action.getBooleanInput('fork')
}, { name: 'TypeError', message: 'Wrong boolean value of the input \'fork\'' })
})
it('both opens PR to the default branch and tags GitHub releases by default', async () => {
const output = {}
core.setOutput = (name, value) => {
@@ -23,7 +77,7 @@ describe('release-please-action', () => {
'release-type': 'node'
}
core.getInput = (name) => {
return input[name]
return input[name] || defaultInput[name]
}
const runCommandStub = sandbox.stub(factory, 'runCommand')
@@ -61,7 +115,7 @@ describe('release-please-action', () => {
'default-branch': 'dev'
}
core.getInput = (name) => {
return input[name]
return input[name] || defaultInput[name]
}
const runCommandStub = sandbox.stub(factory, 'runCommand')
@@ -100,7 +154,7 @@ describe('release-please-action', () => {
command: 'release-pr'
}
core.getInput = (name) => {
return input[name]
return input[name] || defaultInput[name]
}
const runCommandStub = sandbox.stub(factory, 'runCommand')
@@ -129,7 +183,7 @@ describe('release-please-action', () => {
command: 'github-release'
}
core.getInput = (name) => {
return input[name]
return input[name] || defaultInput[name]
}
const runCommandStub = sandbox.stub(factory, 'runCommand')
@@ -170,7 +224,7 @@ describe('release-please-action', () => {
command: 'github-release'
}
core.getInput = (name) => {
return input[name]
return input[name] || defaultInput[name]
}
const runCommandStub = sandbox.stub(factory, 'runCommand')
@@ -195,7 +249,7 @@ describe('release-please-action', () => {
command: 'release-pr'
}
core.getInput = (name) => {
return input[name]
return input[name] || defaultInput[name]
}
const runCommandStub = sandbox.stub(factory, 'runCommand')
@@ -217,7 +271,7 @@ describe('release-please-action', () => {
command: 'release-pr'
}
core.getInput = (name) => {
return input[name]
return input[name] || defaultInput[name]
}
const runCommandStub = sandbox.stub(factory, 'runCommand')
@@ -239,7 +293,7 @@ describe('release-please-action', () => {
command: 'release-pr'
}
core.getInput = (name) => {
return input[name]
return input[name] || defaultInput[name]
}
await action.main()
assert.ok(maybeReleasePR instanceof Node)
@@ -255,7 +309,7 @@ describe('release-please-action', () => {
command: 'github-release'
}
core.getInput = (name) => {
return input[name]
return input[name] || defaultInput[name]
}
await action.main()
assert.ok(maybeGitHubRelease instanceof GitHubRelease)