Skip to content

Commit 931b7bc

Browse files
committed
add some tests
1 parent d370d22 commit 931b7bc

File tree

6 files changed

+35
-21
lines changed

6 files changed

+35
-21
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ The only required input is `project-name`.
7575
The default value is 15.
7676

7777
1. **hide-cloudwatch-logs** (optional) :
78-
Set to `true` if you do not want CloudWatch logs to be streamed to GitHub Action.
78+
Set to `true` if you do not want CloudWatch Logs to be streamed to GitHub Action.
7979

8080
### Outputs
8181

action.yml

-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ inputs:
3434
hide-cloudwatch-logs:
3535
description: 'Set to `true` to prevent the CloudWatch logs from streaming the output to GitHub'
3636
required: false
37-
default: false
3837
outputs:
3938
aws-build-id:
4039
description: 'The AWS CodeBuild Build ID for this build.'

aws-codebuild-run-build

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit eb17d173dcaabf0456059585bbb8ad3f41924004

code-build.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ function runBuild() {
2222

2323
const inputs = githubInputs();
2424

25-
const config = (({ updateInterval, updateBackOff, hideCloudwatchLogs }) => ({
25+
const config = (({ updateInterval, updateBackOff, hideCloudWatchLogs }) => ({
2626
updateInterval,
2727
updateBackOff,
28-
hideCloudwatchLogs,
28+
hideCloudWatchLogs,
2929
}))(inputs);
3030

3131
// Get input options for startBuild
@@ -45,7 +45,7 @@ async function build(sdk, params, config) {
4545
async function waitForBuildEndTime(
4646
sdk,
4747
{ id, logs },
48-
{ updateInterval, updateBackOff, hideCloudwatchLogs },
48+
{ updateInterval, updateBackOff, hideCloudWatchLogs },
4949
seqEmptyLogs,
5050
totalEvents,
5151
throttleCount,
@@ -66,9 +66,9 @@ async function waitForBuildEndTime(
6666
// Check the state
6767
const [batch, cloudWatch = {}] = await Promise.all([
6868
codeBuild.batchGetBuilds({ ids: [id] }).promise(),
69-
!hideCloudwatchLogs &&
69+
!hideCloudWatchLogs &&
7070
logGroupName &&
71-
cloudWatchLogs // only make the call if hideCloudwatchLogs is not enabled and a logGroupName exists
71+
cloudWatchLogs // only make the call if hideCloudWatchLogs is not enabled and a logGroupName exists
7272
.getLogEvents({
7373
logGroupName,
7474
logStreamName,
@@ -155,7 +155,7 @@ async function waitForBuildEndTime(
155155
return waitForBuildEndTime(
156156
sdk,
157157
current,
158-
{ updateInterval, updateBackOff, hideCloudwatchLogs },
158+
{ updateInterval, updateBackOff, hideCloudWatchLogs },
159159
seqEmptyLogs,
160160
totalEvents,
161161
throttleCount,
@@ -210,8 +210,8 @@ function githubInputs() {
210210
10
211211
) * 1000;
212212

213-
const hideCloudwatchLogs =
214-
core.getInput("hide-cloudwatch-logs", { required: false }) || undefined;
213+
const hideCloudWatchLogs =
214+
core.getInput("hide-cloudwatch-logs", { required: false }) === "true";
215215

216216
return {
217217
projectName,
@@ -226,7 +226,7 @@ function githubInputs() {
226226
updateInterval,
227227
updateBackOff,
228228
disableSourceOverride,
229-
hideCloudwatchLogs,
229+
hideCloudWatchLogs,
230230
};
231231
}
232232

dist/index.js

+9-10
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@
3333
const config = (({
3434
updateInterval,
3535
updateBackOff,
36-
hideCloudwatchLogs,
36+
hideCloudWatchLogs,
3737
}) => ({
3838
updateInterval,
3939
updateBackOff,
40-
hideCloudwatchLogs,
40+
hideCloudWatchLogs,
4141
}))(inputs);
4242

4343
// Get input options for startBuild
@@ -57,7 +57,7 @@
5757
async function waitForBuildEndTime(
5858
sdk,
5959
{ id, logs },
60-
{ updateInterval, updateBackOff, hideCloudwatchLogs },
60+
{ updateInterval, updateBackOff, hideCloudWatchLogs },
6161
seqEmptyLogs,
6262
totalEvents,
6363
throttleCount,
@@ -78,9 +78,9 @@
7878
// Check the state
7979
const [batch, cloudWatch = {}] = await Promise.all([
8080
codeBuild.batchGetBuilds({ ids: [id] }).promise(),
81-
!hideCloudwatchLogs &&
81+
!hideCloudWatchLogs &&
8282
logGroupName &&
83-
cloudWatchLogs // only make the call if hideCloudwatchLogs is not enabled and a logGroupName exists
83+
cloudWatchLogs // only make the call if hideCloudWatchLogs is not enabled and a logGroupName exists
8484
.getLogEvents({
8585
logGroupName,
8686
logStreamName,
@@ -170,7 +170,7 @@
170170
return waitForBuildEndTime(
171171
sdk,
172172
current,
173-
{ updateInterval, updateBackOff, hideCloudwatchLogs },
173+
{ updateInterval, updateBackOff, hideCloudWatchLogs },
174174
seqEmptyLogs,
175175
totalEvents,
176176
throttleCount,
@@ -227,9 +227,8 @@
227227
10
228228
) * 1000;
229229

230-
const hideCloudwatchLogs =
231-
core.getInput("hide-cloudwatch-logs", { required: false }) ||
232-
undefined;
230+
const hideCloudWatchLogs =
231+
core.getInput("hide-cloudwatch-logs", { required: false }) === "true";
233232

234233
return {
235234
projectName,
@@ -244,7 +243,7 @@
244243
updateInterval,
245244
updateBackOff,
246245
disableSourceOverride,
247-
hideCloudwatchLogs,
246+
hideCloudWatchLogs,
248247
};
249248
}
250249

test/code-build-test.js

+15
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ describe("githubInputs", () => {
8282
.and.to.equal(undefined);
8383
expect(test).to.haveOwnProperty("imageOverride").and.to.equal(undefined);
8484
expect(test).to.haveOwnProperty("envPassthrough").and.to.deep.equal([]);
85+
expect(test).to.haveOwnProperty("hideCloudWatchLogs").and.to.equal(false);
8586
});
8687

8788
it("a project name is required.", () => {
@@ -170,6 +171,7 @@ describe("githubInputs", () => {
170171
"No source version could be evaluated."
171172
);
172173
});
174+
173175
it("can handle configuring update call-rate", () => {
174176
process.env[`INPUT_PROJECT-NAME`] = projectName;
175177
process.env[`INPUT_UPDATE-INTERVAL`] = `${updateInterval}`;
@@ -188,6 +190,19 @@ describe("githubInputs", () => {
188190
.to.haveOwnProperty("updateBackOff")
189191
.and.to.equal(updateBackOff * 1000);
190192
});
193+
194+
it("can hide cloudwatch logs when the parameter is set to true", () => {
195+
// This is how GITHUB injects its input values.
196+
// It would be nice if there was an easy way to test this...
197+
process.env[`INPUT_PROJECT-NAME`] = projectName;
198+
process.env[`INPUT_HIDE-CLOUDWATCH-LOGS`] = "true";
199+
process.env[`GITHUB_REPOSITORY`] = repoInfo;
200+
process.env[`GITHUB_SHA`] = sha;
201+
202+
const test = githubInputs();
203+
204+
expect(test).to.haveOwnProperty("hideCloudWatchLogs").and.to.equal(true);
205+
});
191206
});
192207

193208
describe("inputs2Parameters", () => {

0 commit comments

Comments
 (0)