@@ -16,6 +16,7 @@ package fileparser
1616
1717import (
1818 stdos "os"
19+ "reflect"
1920 "strings"
2021 "testing"
2122
@@ -364,6 +365,24 @@ func TestIsStepExecKind(t *testing.T) {
364365 args : args {},
365366 want : false ,
366367 },
368+ {
369+ name : "step is not nil" ,
370+ args : args {
371+ step : & actionlint.Step {
372+ Exec : & actionlint.ExecAction {},
373+ },
374+ },
375+ want : true ,
376+ },
377+ {
378+ name : "step is not nil, but kind is not equal" ,
379+ args : args {
380+ step : & actionlint.Step {
381+ Exec : & actionlint.ExecRun {},
382+ },
383+ },
384+ want : false ,
385+ },
367386 }
368387
369388 for _ , tt := range tests {
@@ -463,3 +482,240 @@ func TestFormatActionlintError(t *testing.T) {
463482 })
464483 }
465484}
485+
486+ func TestGetUses (t * testing.T ) {
487+ t .Parallel ()
488+ type args struct {
489+ step * actionlint.Step
490+ }
491+ //nolint
492+ tests := []struct {
493+ name string
494+ args args
495+ want * actionlint.String
496+ }{
497+ {
498+ name : "uses" ,
499+ args : args {
500+ step : & actionlint.Step {
501+ Exec : & actionlint.ExecAction {
502+ Uses : & actionlint.String {
503+ Value : "foo" ,
504+ },
505+ },
506+ },
507+ },
508+ want : & actionlint.String {
509+ Value : "foo" ,
510+ },
511+ },
512+ {
513+ name : "uses is empty" ,
514+ args : args {
515+ step : & actionlint.Step {
516+ Exec : & actionlint.ExecAction {
517+ Uses : & actionlint.String {
518+ Value : "" ,
519+ },
520+ },
521+ },
522+ },
523+ want : & actionlint.String {
524+ Value : "" ,
525+ },
526+ },
527+ {
528+ name : "step is nil" ,
529+ args : args {},
530+ want : nil ,
531+ },
532+ {
533+ name : "step is not nil, but uses is nil" ,
534+ args : args {
535+ step : & actionlint.Step {
536+ Exec : & actionlint.ExecAction {},
537+ },
538+ },
539+ want : nil ,
540+ },
541+ {
542+ name : "step is not nil, but uses is not nil" ,
543+ args : args {
544+ step : & actionlint.Step {},
545+ },
546+ want : nil ,
547+ },
548+ }
549+ for _ , tt := range tests {
550+ tt := tt // Re-initializing variable so it is not changed while executing the closure below
551+ t .Run (tt .name , func (t * testing.T ) {
552+ t .Parallel ()
553+ if got := GetUses (tt .args .step ); ! reflect .DeepEqual (got , tt .want ) {
554+ t .Errorf ("GetUses() = %v, want %v" , got , tt .want )
555+ }
556+ })
557+ }
558+ }
559+
560+ func Test_getWith (t * testing.T ) {
561+ t .Parallel ()
562+ type args struct {
563+ step * actionlint.Step
564+ }
565+ //nolint
566+ tests := []struct {
567+ name string
568+ args args
569+ want map [string ]* actionlint.Input
570+ }{
571+ {
572+ name : "with" ,
573+ args : args {
574+ step : & actionlint.Step {
575+ Exec : & actionlint.ExecAction {
576+ Inputs : map [string ]* actionlint.Input {
577+ "foo" : {
578+ Name : & actionlint.String {Value : "foo" },
579+ Value : & actionlint.String {Value : "bar" },
580+ },
581+ },
582+ },
583+ },
584+ },
585+ want : map [string ]* actionlint.Input {
586+ "foo" : {
587+ Name : & actionlint.String {Value : "foo" },
588+ Value : & actionlint.String {Value : "bar" },
589+ },
590+ },
591+ },
592+ {
593+ name : "with is empty" ,
594+ args : args {
595+ step : & actionlint.Step {
596+ Exec : & actionlint.ExecAction {
597+ Inputs : map [string ]* actionlint.Input {
598+ "foo" : {
599+ Name : & actionlint.String {Value : "foo" },
600+ Value : & actionlint.String {Value : "" },
601+ },
602+ },
603+ },
604+ },
605+ },
606+ want : map [string ]* actionlint.Input {
607+ "foo" : {
608+ Name : & actionlint.String {Value : "foo" },
609+ Value : & actionlint.String {Value : "" },
610+ },
611+ },
612+ },
613+ {
614+ name : "step is nil" ,
615+ args : args {},
616+ want : nil ,
617+ },
618+ {
619+ name : "step is not nil, but with is nil" ,
620+ args : args {
621+ step : & actionlint.Step {
622+ Exec : & actionlint.ExecAction {},
623+ },
624+ },
625+ want : nil ,
626+ },
627+ {
628+ name : "step is not nil, but with is not nil" ,
629+ args : args {
630+ step : & actionlint.Step {},
631+ },
632+ want : nil ,
633+ },
634+ }
635+ for _ , tt := range tests {
636+ tt := tt // Re-initializing variable so it is not changed while executing the closure below
637+ t .Run (tt .name , func (t * testing.T ) {
638+ t .Parallel ()
639+ if got := getWith (tt .args .step ); ! reflect .DeepEqual (got , tt .want ) {
640+ t .Errorf ("getWith() = %v, want %v" , got , tt .want )
641+ }
642+ })
643+ }
644+ }
645+
646+ func Test_getRun (t * testing.T ) {
647+ t .Parallel ()
648+ type args struct {
649+ step * actionlint.Step
650+ }
651+ //nolint
652+ tests := []struct {
653+ name string
654+ args args
655+ want * actionlint.String
656+ }{
657+ {
658+ name : "run" ,
659+ args : args {
660+ step : & actionlint.Step {
661+ Exec : & actionlint.ExecAction {
662+ Inputs : map [string ]* actionlint.Input {
663+ "foo" : {
664+ Name : & actionlint.String {Value : "foo" },
665+ Value : & actionlint.String {Value : "bar" },
666+ },
667+ },
668+ },
669+ },
670+ },
671+ want : nil ,
672+ },
673+ {
674+ name : "run is empty" ,
675+ args : args {
676+ step : & actionlint.Step {
677+ Exec : & actionlint.ExecAction {
678+ Inputs : map [string ]* actionlint.Input {
679+ "foo" : {
680+ Name : & actionlint.String {Value : "foo" },
681+ Value : & actionlint.String {Value : "" },
682+ },
683+ },
684+ },
685+ },
686+ },
687+ want : nil ,
688+ },
689+ {
690+ name : "step is nil" ,
691+ args : args {},
692+ want : nil ,
693+ },
694+ {
695+ name : "step is not nil, but run is nil" ,
696+ args : args {
697+ step : & actionlint.Step {
698+ Exec : & actionlint.ExecAction {},
699+ },
700+ },
701+ want : nil ,
702+ },
703+ {
704+ name : "step is not nil, but run is not nil" ,
705+ args : args {
706+ step : & actionlint.Step {},
707+ },
708+ want : nil ,
709+ },
710+ }
711+
712+ for _ , tt := range tests {
713+ tt := tt // Re-initializing variable so it is not changed while executing the closure below
714+ t .Run (tt .name , func (t * testing.T ) {
715+ t .Parallel ()
716+ if got := getRun (tt .args .step ); ! reflect .DeepEqual (got , tt .want ) {
717+ t .Errorf ("getRun() = %v, want %v for test case %v" , got , tt .want , tt .name )
718+ }
719+ })
720+ }
721+ }
0 commit comments