@@ -372,6 +372,11 @@ func tearDownNewFunction(t *testing.T, functionName string) {
372
372
t .Log (err )
373
373
}
374
374
}
375
+ if _ , err := os .Stat ("stack.yml" ); err == nil {
376
+ if err := os .Remove ("stack.yml" ); err != nil {
377
+ t .Log (err )
378
+ }
379
+ }
375
380
hDir := handlerDir
376
381
if len (hDir ) == 0 {
377
382
hDir = functionName
@@ -423,3 +428,58 @@ func Test_getPrefixValue_Flag(t *testing.T) {
423
428
t .Errorf ("want %s, got %s" , want , val )
424
429
}
425
430
}
431
+
432
+ func Test_addEofNewlines_works (t * testing.T ) {
433
+ table := []struct {
434
+ funcName string
435
+ }{
436
+ // TODO: after #906 is fixed
437
+ // -f or --yaml will work
438
+ // and we can change stack to func1
439
+ {"stack" },
440
+ {"func2" },
441
+ {"func3" },
442
+ }
443
+ resetForTest ()
444
+ templatePullLocalTemplateRepo (t )
445
+
446
+ defer tearDownFetchTemplates (t )
447
+ const stackFile = "stack.yml"
448
+
449
+ for i , row := range table {
450
+ const functionLang = "ruby"
451
+
452
+ parameters := []string {
453
+ "new" ,
454
+ row .funcName ,
455
+ "--lang=" + functionLang ,
456
+ }
457
+
458
+ if i == 0 {
459
+ // there's a bug where this doesn't get honored
460
+ // as a workaround, func1 is "stack" in the test table
461
+ // this way we predictability create stack.yml
462
+ parameters = append (parameters , "--yaml=" + stackFile )
463
+ } else {
464
+ parameters = append (parameters , "--append=" + stackFile )
465
+ }
466
+
467
+ faasCmd .SetArgs (nil )
468
+ faasCmd .SetArgs (parameters )
469
+ faasCmd .Execute ()
470
+
471
+ // drop last two bytes (\n\n) for the first function
472
+ if i == 0 {
473
+ func (fileName string ) {
474
+ file , _ := os .OpenFile (fileName , os .O_RDWR , 0600 )
475
+ defer file .Close ()
476
+ fileStats , _ := file .Stat ()
477
+ file .Truncate (fileStats .Size () - 2 )
478
+ }(stackFile )
479
+ }
480
+ }
481
+
482
+ for _ , row := range table {
483
+ defer tearDownNewFunction (t , row .funcName )
484
+ }
485
+ }
0 commit comments