@@ -18,6 +18,8 @@ import 'mocha';
1818import { expect } from 'chai' ;
1919import * as sinon from 'sinon' ;
2020
21+ import YAML from 'yaml' ;
22+
2123import * as core from '@actions/core' ;
2224import * as exec from '@actions/exec' ;
2325import * as setupGcloud from '@google-github-actions/setup-cloud-sdk' ;
@@ -248,19 +250,19 @@ describe('#updateEnvVars', () => {
248250 const cases : {
249251 only ?: boolean ;
250252 name : string ;
251- existing : string [ ] ;
253+ existing : KVPair ;
252254 envVars : KVPair ;
253255 expected : KVPair ;
254256 } [ ] = [
255257 {
256258 name : 'empty existing, empty input' ,
257- existing : [ ] ,
259+ existing : { } ,
258260 envVars : { } ,
259261 expected : { } ,
260262 } ,
261263 {
262264 name : 'empty existing, given input' ,
263- existing : [ ] ,
265+ existing : { } ,
264266 envVars : {
265267 FOO : 'bar' ,
266268 ZIP : 'zap' ,
@@ -272,7 +274,9 @@ describe('#updateEnvVars', () => {
272274 } ,
273275 {
274276 name : 'existing, given input' ,
275- existing : [ 'EXISTING=one' ] ,
277+ existing : {
278+ EXISTING : 'one' ,
279+ } ,
276280 envVars : {
277281 FOO : 'bar' ,
278282 ZIP : 'zap' ,
@@ -285,7 +289,9 @@ describe('#updateEnvVars', () => {
285289 } ,
286290 {
287291 name : 'overwrites' ,
288- existing : [ 'FOO=bar' ] ,
292+ existing : {
293+ FOO : 'bar' ,
294+ } ,
289295 envVars : {
290296 FOO : 'zip' ,
291297 } ,
@@ -301,7 +307,32 @@ describe('#updateEnvVars', () => {
301307 expect ( updateEnvVars ( tc . existing , tc . envVars ) ) . to . eql ( tc . expected ) ;
302308 } ) ;
303309 } ) ;
310+
311+ it ( 'handles an yaml with variables' , async ( ) => {
312+ const parsed = YAML . parse ( `
313+ env_variables:
314+ FOO: 'bar'
315+ ` ) ;
316+
317+ console . log ( typeof parsed . env_variables ) ;
318+ const result = updateEnvVars ( parsed . env_variables , { ZIP : 'zap' } ) ;
319+ expect ( result ) . to . eql ( {
320+ FOO : 'bar' ,
321+ ZIP : 'zap' ,
322+ } ) ;
323+ } ) ;
324+
325+ it ( 'handles an yaml without variables' , async ( ) => {
326+ const parsed = YAML . parse ( `{}` ) ;
327+
328+ console . log ( typeof parsed . env_variables ) ;
329+ const result = updateEnvVars ( parsed . env_variables , { ZIP : 'zap' } ) ;
330+ expect ( result ) . to . eql ( {
331+ ZIP : 'zap' ,
332+ } ) ;
333+ } ) ;
304334} ) ;
335+
305336async function expectError ( fn : ( ) => Promise < void > , want : string ) {
306337 try {
307338 await fn ( ) ;
0 commit comments