1- import crypto from 'crypto'
2- import fs from 'fs'
3- import path from 'path'
41import { Context } from '@actions/github/lib/context'
52import { getJobParameters } from '../src/inputs'
63import { eventFixturePath } from './helpers'
74
85let context : Context
9- const workspace = path . join ( __dirname , '..' , 'tmp' )
10- const workingDirectory = path . join ( workspace , './test_working_directory' )
11-
12- beforeEach ( ( ) => {
13- fs . mkdirSync ( workingDirectory )
14- } )
15-
16- afterEach ( ( ) => {
17- if ( fs . existsSync ( workingDirectory ) ) {
18- fs . rmdirSync ( workingDirectory )
19- }
20- } )
216
227describe ( 'when there is a fully configured Actions environment' , ( ) => {
238 beforeEach ( ( ) => {
249 process . env . GITHUB_EVENT_PATH = eventFixturePath ( 'default' )
2510 process . env . GITHUB_EVENT_NAME = 'dynamic'
2611 process . env . GITHUB_ACTOR = 'dependabot[bot]'
2712 process . env . GITHUB_TRIGGERING_ACTOR = 'dependabot[bot]'
28- process . env . GITHUB_WORKSPACE = workspace
2913
3014 context = new Context ( )
3115 } )
@@ -39,12 +23,6 @@ describe('when there is a fully configured Actions environment', () => {
3923 expect ( params ?. dependabotApiUrl ) . toEqual ( 'http://localhost:9000' )
4024 expect ( params ?. dependabotApiDockerUrl ) . toEqual ( 'http://localhost:9000' )
4125 } )
42-
43- test ( 'it returns an absolute path based on GITHUB_WORKSPACE and the workingDirectory input' , ( ) => {
44- const params = getJobParameters ( context )
45-
46- expect ( params ?. workingDirectory ) . toEqual ( workingDirectory )
47- } )
4826} )
4927
5028describe ( 'when there is no GITHUB_EVENT_NAME defined' , ( ) => {
@@ -53,7 +31,6 @@ describe('when there is no GITHUB_EVENT_NAME defined', () => {
5331 delete process . env . GITHUB_EVENT_NAME
5432 process . env . GITHUB_ACTOR = 'dependabot[bot]'
5533 process . env . GITHUB_TRIGGERING_ACTOR = 'dependabot[bot]'
56- process . env . GITHUB_WORKSPACE = workspace
5734
5835 context = new Context ( )
5936 } )
@@ -70,7 +47,6 @@ describe('when the GITHUB_EVENT_NAME is not "dynamic"', () => {
7047 process . env . GITHUB_EVENT_PATH = eventFixturePath ( 'default' )
7148 process . env . GITHUB_EVENT_NAME = 'issue_comment'
7249 process . env . GITHUB_TRIGGERING_ACTOR = 'dependabot[bot]'
73- process . env . GITHUB_WORKSPACE = workspace
7450
7551 context = new Context ( )
7652 } )
@@ -88,7 +64,6 @@ describe('when there is no GITHUB_ACTOR defined', () => {
8864 process . env . GITHUB_EVENT_NAME = 'dynamic'
8965 delete process . env . GITHUB_ACTOR
9066 process . env . GITHUB_TRIGGERING_ACTOR = 'dependabot[bot]'
91- process . env . GITHUB_WORKSPACE = workspace
9267
9368 context = new Context ( )
9469 } )
@@ -106,7 +81,6 @@ describe('when the GITHUB_ACTOR is not "dependabot[bot]"', () => {
10681 process . env . GITHUB_EVENT_NAME = 'dynamic'
10782 process . env . GITHUB_ACTOR = 'classic-rando'
10883 process . env . GITHUB_TRIGGERING_ACTOR = 'classic-rando'
109- process . env . GITHUB_WORKSPACE = workspace
11084
11185 context = new Context ( )
11286 } )
@@ -124,7 +98,6 @@ describe('when there is no GITHUB_TRIGGERING_ACTOR defined', () => {
12498 process . env . GITHUB_EVENT_NAME = 'dynamic'
12599 process . env . GITHUB_ACTOR = 'dependabot[bot]'
126100 delete process . env . GITHUB_TRIGGERING_ACTOR
127- process . env . GITHUB_WORKSPACE = workspace
128101
129102 context = new Context ( )
130103 } )
@@ -142,7 +115,6 @@ describe('when the GITHUB_TRIGGERING_ACTOR is not "dependabot[bot]"', () => {
142115 process . env . GITHUB_EVENT_NAME = 'dynamic'
143116 process . env . GITHUB_ACTOR = 'dependabot[bot]'
144117 process . env . GITHUB_TRIGGERING_ACTOR = 'classic-rando'
145- process . env . GITHUB_WORKSPACE = workspace
146118
147119 context = new Context ( )
148120 } )
@@ -154,158 +126,14 @@ describe('when the GITHUB_TRIGGERING_ACTOR is not "dependabot[bot]"', () => {
154126 } )
155127} )
156128
157- describe ( 'when there is no GITHUB_WORKSPACE defined' , ( ) => {
158- beforeEach ( ( ) => {
159- process . env . GITHUB_EVENT_PATH = eventFixturePath ( 'default' )
160- process . env . GITHUB_EVENT_NAME = 'dynamic'
161- process . env . GITHUB_ACTOR = 'dependabot[bot]'
162- process . env . GITHUB_TRIGGERING_ACTOR = 'dependabot[bot]'
163- delete process . env . GITHUB_WORKSPACE
164-
165- context = new Context ( )
166- } )
167-
168- test ( 'it throws an error' , ( ) => {
169- expect ( ( ) => {
170- getJobParameters ( context )
171- } ) . toThrow ( 'Required Actions environment variables missing.' )
172- } )
173- } )
174-
175- describe ( 'when the GITHUB_WORKSPACE path does not exist' , ( ) => {
176- beforeEach ( ( ) => {
177- const randomFolderName = crypto . randomBytes ( 16 ) . toString ( 'hex' )
178-
179- process . env . GITHUB_EVENT_PATH = eventFixturePath ( 'default' )
180- process . env . GITHUB_EVENT_NAME = 'dynamic'
181- process . env . GITHUB_ACTOR = 'dependabot[bot]'
182- process . env . GITHUB_TRIGGERING_ACTOR = 'dependabot[bot]'
183- process . env . GITHUB_WORKSPACE = path . join ( workspace , randomFolderName )
184-
185- context = new Context ( )
186- } )
187-
188- test ( 'it throws an error' , ( ) => {
189- expect ( ( ) => {
190- getJobParameters ( context )
191- } ) . toThrow ( 'The GITHUB_WORKSPACE directory does not exist.' )
192- } )
193- } )
194-
195- describe ( 'when the GITHUB_WORKSPACE exists, but is a file' , ( ) => {
196- const randomFileName = path . join (
197- workspace ,
198- crypto . randomBytes ( 16 ) . toString ( 'hex' )
199- )
200-
201- beforeEach ( ( ) => {
202- process . env . GITHUB_EVENT_PATH = eventFixturePath ( 'default' )
203- process . env . GITHUB_EVENT_NAME = 'dynamic'
204- process . env . GITHUB_ACTOR = 'dependabot[bot]'
205- process . env . GITHUB_TRIGGERING_ACTOR = 'dependabot[bot]'
206- process . env . GITHUB_WORKSPACE = randomFileName
207-
208- fs . closeSync ( fs . openSync ( randomFileName , 'w' ) )
209-
210- context = new Context ( )
211- } )
212-
213- afterEach ( ( ) => {
214- fs . unlinkSync ( randomFileName )
215- } )
216-
217- test ( 'it throws an error' , ( ) => {
218- expect ( ( ) => {
219- getJobParameters ( context )
220- } ) . toThrow ( 'The GITHUB_WORKSPACE directory does not exist.' )
221- } )
222- } )
223-
224- describe ( 'when the workingDirectory is a blank value' , ( ) => {
225- beforeEach ( ( ) => {
226- process . env . GITHUB_EVENT_PATH = eventFixturePath ( 'blank_working_directory' )
227- process . env . GITHUB_EVENT_NAME = 'dynamic'
228- process . env . GITHUB_ACTOR = 'dependabot[bot]'
229- process . env . GITHUB_TRIGGERING_ACTOR = 'dependabot[bot]'
230- process . env . GITHUB_WORKSPACE = workspace
231-
232- context = new Context ( )
233-
234- fs . rmdirSync ( workingDirectory )
235- fs . closeSync ( fs . openSync ( workingDirectory , 'w' ) )
236- } )
237-
238- afterEach ( ( ) => {
239- fs . unlinkSync ( workingDirectory )
240- } )
241-
242- test ( 'it throws an error' , ( ) => {
243- expect ( ( ) => {
244- getJobParameters ( context )
245- } ) . toThrow ( 'The workingDirectory input must not be blank' )
246- } )
247- } )
248-
249- describe ( 'when the workingDirectory does not exist' , ( ) => {
250- beforeEach ( ( ) => {
251- process . env . GITHUB_EVENT_PATH = eventFixturePath ( 'default' )
252- process . env . GITHUB_EVENT_NAME = 'dynamic'
253- process . env . GITHUB_ACTOR = 'dependabot[bot]'
254- process . env . GITHUB_TRIGGERING_ACTOR = 'dependabot[bot]'
255- process . env . GITHUB_WORKSPACE = workspace
256-
257- context = new Context ( )
258-
259- fs . rmdirSync ( workingDirectory )
260- } )
261-
262- test ( 'it throws an error' , ( ) => {
263- expect ( ( ) => {
264- getJobParameters ( context )
265- } ) . toThrow (
266- `The workingDirectory './test_working_directory' does not exist in GITHUB_WORKSPACE`
267- )
268- } )
269- } )
270-
271- describe ( 'when the workingDirectory exists, but is a file' , ( ) => {
272- beforeEach ( ( ) => {
273- process . env . GITHUB_EVENT_PATH = eventFixturePath ( 'default' )
274- process . env . GITHUB_EVENT_NAME = 'dynamic'
275- process . env . GITHUB_ACTOR = 'dependabot[bot]'
276- process . env . GITHUB_TRIGGERING_ACTOR = 'dependabot[bot]'
277- process . env . GITHUB_WORKSPACE = workspace
278-
279- context = new Context ( )
280-
281- fs . rmdirSync ( workingDirectory )
282- fs . closeSync ( fs . openSync ( workingDirectory , 'w' ) )
283- } )
284-
285- afterEach ( ( ) => {
286- fs . unlinkSync ( workingDirectory )
287- } )
288-
289- test ( 'it throws an error' , ( ) => {
290- expect ( ( ) => {
291- getJobParameters ( context )
292- } ) . toThrow (
293- `The workingDirectory './test_working_directory' does not exist in GITHUB_WORKSPACE`
294- )
295- } )
296- } )
297-
298129describe ( 'when the event inputs are empty' , ( ) => {
299130 beforeEach ( ( ) => {
300131 process . env . GITHUB_EVENT_PATH = eventFixturePath ( 'no_inputs' )
301132 process . env . GITHUB_EVENT_NAME = 'dynamic'
302133 process . env . GITHUB_ACTOR = 'dependabot[bot]'
303134 process . env . GITHUB_TRIGGERING_ACTOR = 'dependabot[bot]'
304- process . env . GITHUB_WORKSPACE = workspace
305135
306136 context = new Context ( )
307-
308- fs . rmdirSync ( workingDirectory )
309137 } )
310138
311139 test ( 'it throws an error' , ( ) => {
0 commit comments