Run executes the scorecard tests as configured
(ctx context.Context)
| 71 | |
| 72 | // Run executes the scorecard tests as configured |
| 73 | func (o Scorecard) Run(ctx context.Context) (testOutput v1alpha3.TestList, err error) { |
| 74 | testOutput = v1alpha3.NewTestList() |
| 75 | |
| 76 | if err := o.TestRunner.Initialize(ctx); err != nil { |
| 77 | return testOutput, err |
| 78 | } |
| 79 | |
| 80 | for _, stage := range o.Config.Stages { |
| 81 | tests := o.selectTests(stage) |
| 82 | if len(tests) == 0 { |
| 83 | continue |
| 84 | } |
| 85 | tests = o.setTestDefaults(tests) |
| 86 | |
| 87 | output := make(chan v1alpha3.Test, len(tests)) |
| 88 | if stage.Parallel { |
| 89 | o.runStageParallel(ctx, tests, output) |
| 90 | } else { |
| 91 | o.runStageSequential(ctx, tests, output) |
| 92 | } |
| 93 | close(output) |
| 94 | for o := range output { |
| 95 | testOutput.Items = append(testOutput.Items, o) |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | // Get timeout error, if any, before calling Cleanup() so deletes don't cause a timeout. |
| 100 | select { |
| 101 | case <-ctx.Done(): |
| 102 | err = ctx.Err() |
| 103 | default: |
| 104 | } |
| 105 | |
| 106 | if !o.SkipCleanup { |
| 107 | // Use a separate context for cleanup, which needs to run regardless of a prior timeout. |
| 108 | clctx, cancel := context.WithTimeout(context.Background(), cleanupTimeout) |
| 109 | defer cancel() |
| 110 | if err := o.TestRunner.Cleanup(clctx); err != nil { |
| 111 | return testOutput, err |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | return testOutput, err |
| 116 | } |
| 117 | |
| 118 | func (o Scorecard) setTestDefaults(tests []v1alpha3.TestConfiguration) []v1alpha3.TestConfiguration { |
| 119 | for i := range tests { |