@@ -707,6 +707,26 @@ func Test_getRun(t *testing.T) {
707707 },
708708 want : nil ,
709709 },
710+ {
711+ name : "run is not empty" ,
712+ args : args {
713+ step : & actionlint.Step {
714+ Exec : & actionlint.ExecRun {
715+ Run : & actionlint.String {Value : "foo" },
716+ },
717+ },
718+ },
719+ want : & actionlint.String {Value : "foo" },
720+ },
721+ {
722+ name : "run is not empty" ,
723+ args : args {
724+ step : & actionlint.Step {
725+ Exec : & actionlint.ExecRun {},
726+ },
727+ },
728+ want : nil ,
729+ },
710730 }
711731
712732 for _ , tt := range tests {
@@ -719,3 +739,178 @@ func Test_getRun(t *testing.T) {
719739 })
720740 }
721741}
742+
743+ func Test_stepsMatch (t * testing.T ) {
744+ t .Parallel ()
745+ type args struct {
746+ stepToMatch * JobMatcherStep
747+ step * actionlint.Step
748+ }
749+ //nolint
750+ tests := []struct {
751+ name string
752+ args args
753+ want bool
754+ }{
755+ {
756+ name : "match" ,
757+ args : args {
758+ stepToMatch : & JobMatcherStep {
759+ Uses : "foo" ,
760+ With : map [string ]string {
761+ "foo" : "bar" ,
762+ },
763+ },
764+ step : & actionlint.Step {
765+ Exec : & actionlint.ExecAction {
766+ Uses : & actionlint.String {
767+ Value : "foo@" ,
768+ },
769+ Inputs : map [string ]* actionlint.Input {
770+ "foo" : {
771+ Name : & actionlint.String {Value : "foo" },
772+ Value : & actionlint.String {Value : "bar" },
773+ },
774+ },
775+ },
776+ },
777+ },
778+ want : true ,
779+ },
780+ {
781+ name : "match with empty" ,
782+ args : args {
783+ stepToMatch : & JobMatcherStep {
784+ Uses : "foo" ,
785+ With : map [string ]string {
786+ "foo" : "bar" ,
787+ },
788+ },
789+ step : & actionlint.Step {
790+ Exec : & actionlint.ExecAction {
791+ Uses : & actionlint.String {
792+ Value : "foo@" ,
793+ },
794+ Inputs : map [string ]* actionlint.Input {
795+ "foo" : {
796+ Name : & actionlint.String {Value : "foo" },
797+ Value : & actionlint.String {Value : "" },
798+ },
799+ },
800+ },
801+ },
802+ },
803+ want : false ,
804+ },
805+ {
806+ name : "match with empty" ,
807+ args : args {
808+ stepToMatch : & JobMatcherStep {
809+ Uses : "foo" ,
810+ With : map [string ]string {
811+ "foo" : "bar" ,
812+ },
813+ },
814+ step : & actionlint.Step {
815+ Exec : & actionlint.ExecAction {
816+ Uses : & actionlint.String {
817+ Value : "foo@" ,
818+ },
819+ Inputs : map [string ]* actionlint.Input {
820+ "foo" : {
821+ Name : & actionlint.String {Value : "foo" },
822+ Value : & actionlint.String {Value : "" },
823+ },
824+ },
825+ },
826+ },
827+ },
828+ want : false ,
829+ },
830+ {
831+ name : "match with empty" ,
832+ args : args {
833+ stepToMatch : & JobMatcherStep {
834+ Uses : "foo" ,
835+ With : map [string ]string {
836+ "foo" : "bar" ,
837+ },
838+ },
839+ step : & actionlint.Step {
840+ Exec : & actionlint.ExecAction {
841+ Uses : & actionlint.String {
842+ Value : "foo@" ,
843+ },
844+ },
845+ },
846+ },
847+ want : false ,
848+ },
849+ {
850+ name : "match with empty" ,
851+ args : args {
852+ stepToMatch : & JobMatcherStep {
853+ Uses : "foo" ,
854+ With : map [string ]string {
855+ "foo" : "bar" ,
856+ },
857+ },
858+ step : & actionlint.Step {
859+ Exec : & actionlint.ExecAction {
860+ Uses : & actionlint.String {
861+ Value : "foo" ,
862+ },
863+ },
864+ },
865+ },
866+ want : false ,
867+ },
868+ {
869+ name : "match with empty" ,
870+ args : args {
871+ stepToMatch : & JobMatcherStep {
872+ Uses : "foo" ,
873+ With : map [string ]string {
874+ "foo" : "bar" ,
875+ },
876+ },
877+ },
878+ want : false ,
879+ },
880+ {
881+ name : "match" ,
882+ args : args {
883+ stepToMatch : & JobMatcherStep {
884+ Uses : "foo" ,
885+ With : map [string ]string {
886+ "foo" : "bar" ,
887+ },
888+ Run : "foo" ,
889+ },
890+ step : & actionlint.Step {
891+ Exec : & actionlint.ExecAction {
892+ Uses : & actionlint.String {
893+ Value : "foo@" ,
894+ },
895+ Inputs : map [string ]* actionlint.Input {
896+ "foo" : {
897+ Name : & actionlint.String {Value : "foo" },
898+ Value : & actionlint.String {Value : "bar" },
899+ },
900+ },
901+ },
902+ },
903+ },
904+ want : false ,
905+ },
906+ }
907+ for _ , tt := range tests {
908+ tt := tt // Re-initializing variable so it is not changed while executing the closure below
909+ t .Run (tt .name , func (t * testing.T ) {
910+ t .Parallel ()
911+ if got := stepsMatch (tt .args .stepToMatch , tt .args .step ); got != tt .want {
912+ t .Errorf ("stepsMatch() = %v, want %v" , got , tt .want )
913+ }
914+ })
915+ }
916+ }
0 commit comments