@@ -198,8 +198,8 @@ func (o *runCmdOptions) runTest(cmd *cobra.Command, source string, results *v1al
198
198
handleError := func (err error ) {
199
199
handleTestError (runConfig .Config .Namespace .Name , source , results , err )
200
200
}
201
- defer runSteps (runConfig .Post , runConfig .Config .Namespace .Name , runConfig .BaseDir , results , handleError )
202
- if ! runSteps (runConfig .Pre , runConfig .Config .Namespace .Name , runConfig .BaseDir , results , handleError ) {
201
+ defer runSteps (runConfig .Post , runConfig .Config .Namespace .Name , runConfig .BaseDir , source , results , handleError )
202
+ if ! runSteps (runConfig .Pre , runConfig .Config .Namespace .Name , runConfig .BaseDir , source , results , handleError ) {
203
203
return
204
204
}
205
205
@@ -254,8 +254,8 @@ func (o *runCmdOptions) runTestGroup(cmd *cobra.Command, source string, results
254
254
handleError := func (err error ) {
255
255
handleTestError (runConfig .Config .Namespace .Name , source , results , err )
256
256
}
257
- defer runSteps (runConfig .Post , runConfig .Config .Namespace .Name , runConfig .BaseDir , results , handleError )
258
- if ! runSteps (runConfig .Pre , runConfig .Config .Namespace .Name , runConfig .BaseDir , results , handleError ) {
257
+ defer runSteps (runConfig .Post , runConfig .Config .Namespace .Name , runConfig .BaseDir , source , results , handleError )
258
+ if ! runSteps (runConfig .Pre , runConfig .Config .Namespace .Name , runConfig .BaseDir , source , results , handleError ) {
259
259
return
260
260
}
261
261
@@ -352,7 +352,7 @@ func (o *runCmdOptions) createTempNamespace(runConfig *config.RunConfig, cmd *co
352
352
instance , err = v1alpha1 .FindGlobalInstance (o .Context , c )
353
353
354
354
if err != nil && k8serrors .IsForbidden (err ) {
355
- // not allowed to list all instances on the clusterr
355
+ // not allowed to list all instances on the cluster
356
356
return namespace , nil
357
357
} else if err != nil {
358
358
return namespace , err
@@ -548,9 +548,7 @@ func (o *runCmdOptions) createAndRunTest(ctx context.Context, c client.Client, c
548
548
}
549
549
550
550
if runConfig .Config .Dump .Enabled {
551
- if runConfig .Config .Dump .FailedOnly &&
552
- test .Status .Phase != v1alpha1 .TestPhaseFailed && test .Status .Phase != v1alpha1 .TestPhaseError &&
553
- len (test .Status .Errors ) == 0 && ! hasSuiteErrors (& test .Status .Results ) {
551
+ if runConfig .Config .Dump .FailedOnly && ! isFailed (& test ) {
554
552
fmt .Println ("Skip dump for successful test" )
555
553
} else {
556
554
var fileName string
@@ -766,13 +764,24 @@ func (o *runCmdOptions) newSettings(ctx context.Context, runConfig *config.RunCo
766
764
return nil , nil
767
765
}
768
766
769
- func runSteps (steps []config.StepConfig , namespace , baseDir string , results * v1alpha1.TestResults , handleError func (err error )) bool {
767
+ func runSteps (steps []config.StepConfig , namespace , baseDir string , name string , results * v1alpha1.TestResults , handleError func (err error )) bool {
768
+ fileNames := make ([]string , 0 )
769
+
770
+ defer func () {
771
+ for _ , fileName := range fileNames {
772
+ err := os .Remove (fileName )
773
+ if err != nil {
774
+ handleError (fmt .Errorf (fmt .Sprintf ("Failed to remove temporary script file %s: %v" , fileName , err )))
775
+ }
776
+ }
777
+ }()
778
+
770
779
for idx , step := range steps {
771
780
if len (step .Name ) == 0 {
772
781
step .Name = fmt .Sprintf ("step-%d" , idx )
773
782
}
774
783
775
- if skipStep (step , results ) {
784
+ if skipStep (step , name , results ) {
776
785
fmt .Printf ("Skip %s\n " , step .Name )
777
786
continue
778
787
}
@@ -782,7 +791,7 @@ func runSteps(steps []config.StepConfig, namespace, baseDir string, results *v1a
782
791
if desc == "" {
783
792
desc = fmt .Sprintf ("script %s" , step .Script )
784
793
}
785
- if err := runScript (step .Script , desc , namespace , baseDir , hasErrors ( results ), step .Timeout ); err != nil {
794
+ if err := runScript (step .Script , desc , namespace , baseDir , hasError ( name , results ), step .Timeout ); err != nil {
786
795
handleError (fmt .Errorf (fmt .Sprintf ("Failed to run %s: %v" , desc , err )))
787
796
return false
788
797
}
@@ -795,7 +804,7 @@ func runSteps(steps []config.StepConfig, namespace, baseDir string, results *v1a
795
804
handleError (err )
796
805
return false
797
806
}
798
- defer os . Remove ( file .Name ())
807
+ fileNames = append ( fileNames , file .Name ())
799
808
800
809
_ , err = file .WriteString ("#!/bin/bash\n \n set -e\n \n " )
801
810
if err != nil {
@@ -824,7 +833,7 @@ func runSteps(steps []config.StepConfig, namespace, baseDir string, results *v1a
824
833
if desc == "" {
825
834
desc = fmt .Sprintf ("inline command %d" , idx )
826
835
}
827
- if err := runScript (file .Name (), desc , namespace , baseDir , hasErrors ( results ), step .Timeout ); err != nil {
836
+ if err := runScript (file .Name (), desc , namespace , baseDir , hasError ( name , results ), step .Timeout ); err != nil {
828
837
handleError (fmt .Errorf (fmt .Sprintf ("Failed to run %s: %v" , desc , err )))
829
838
return false
830
839
}
@@ -834,7 +843,7 @@ func runSteps(steps []config.StepConfig, namespace, baseDir string, results *v1a
834
843
return true
835
844
}
836
845
837
- func skipStep (step config.StepConfig , results * v1alpha1.TestResults ) bool {
846
+ func skipStep (step config.StepConfig , name string , results * v1alpha1.TestResults ) bool {
838
847
if step .If == "" {
839
848
return false
840
849
}
@@ -867,7 +876,7 @@ func skipStep(step config.StepConfig, results *v1alpha1.TestResults) bool {
867
876
case "os" :
868
877
skipStep = (keyValue )[1 ] != r .GOOS
869
878
case "failure()" :
870
- skipStep = ! hasErrors ( results )
879
+ skipStep = ! hasError ( name , results )
871
880
}
872
881
873
882
if skipStep {
0 commit comments