Skip to content

Commit

Permalink
fix: reports creation and potential nil ref panic (#965)
Browse files Browse the repository at this point in the history
Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
  • Loading branch information
eddycharly authored Feb 24, 2024
1 parent 8cbf418 commit 6168cf1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 17 deletions.
27 changes: 18 additions & 9 deletions pkg/runner/processors/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,9 @@ func (p *stepProcessor) applyOperation(ctx context.Context, bindings binding.Bin
return nil, err
}
var ops []operation
operationReport := report.NewOperation("Apply "+op.File, report.OperationTypeApply)
var operationReport *report.OperationReport
if p.stepReport != nil {
operationReport = report.NewOperation("Apply "+op.File, report.OperationTypeApply)
p.stepReport.AddOperation(operationReport)
}
dryRun := op.DryRun != nil && *op.DryRun
Expand Down Expand Up @@ -344,8 +345,9 @@ func (p *stepProcessor) assertOperation(ctx context.Context, bindings binding.Bi
return nil, err
}
var ops []operation
operationReport := report.NewOperation("Assert ", report.OperationTypeAssert)
var operationReport *report.OperationReport
if p.stepReport != nil {
operationReport = report.NewOperation("Assert ", report.OperationTypeAssert)
p.stepReport.AddOperation(operationReport)
}
template := runnertemplate.Get(op.Template, p.step.Template, p.test.Spec.Template, p.config.Template)
Expand All @@ -365,8 +367,9 @@ func (p *stepProcessor) assertOperation(ctx context.Context, bindings binding.Bi
}

func (p *stepProcessor) commandOperation(ctx context.Context, bindings binding.Bindings, op v1alpha1.Command) operation {
operationReport := report.NewOperation("Command ", report.OperationTypeCommand)
var operationReport *report.OperationReport
if p.stepReport != nil {
operationReport = report.NewOperation("Command ", report.OperationTypeCommand)
p.stepReport.AddOperation(operationReport)
}
ns := ""
Expand All @@ -390,8 +393,9 @@ func (p *stepProcessor) createOperation(ctx context.Context, bindings binding.Bi
return nil, err
}
var ops []operation
operationReport := report.NewOperation("Create ", report.OperationTypeCreate)
var operationReport *report.OperationReport
if p.stepReport != nil {
operationReport = report.NewOperation("Create ", report.OperationTypeCreate)
p.stepReport.AddOperation(operationReport)
}
dryRun := op.DryRun != nil && *op.DryRun
Expand Down Expand Up @@ -421,8 +425,9 @@ func (p *stepProcessor) deleteOperation(ctx context.Context, bindings binding.Bi
resource.SetName(op.Name)
resource.SetNamespace(op.Namespace)
resource.SetLabels(op.Labels)
operationReport := report.NewOperation("Delete ", report.OperationTypeDelete)
var operationReport *report.OperationReport
if p.stepReport != nil {
operationReport = report.NewOperation("Delete ", report.OperationTypeDelete)
p.stepReport.AddOperation(operationReport)
}
template := runnertemplate.Get(op.Template, p.step.Template, p.test.Spec.Template, p.config.Template)
Expand All @@ -444,8 +449,9 @@ func (p *stepProcessor) errorOperation(ctx context.Context, bindings binding.Bin
return nil, err
}
var ops []operation
operationReport := report.NewOperation("Error ", report.OperationTypeCommand)
var operationReport *report.OperationReport
if p.stepReport != nil {
operationReport = report.NewOperation("Error ", report.OperationTypeCommand)
p.stepReport.AddOperation(operationReport)
}
template := runnertemplate.Get(op.Template, p.step.Template, p.test.Spec.Template, p.config.Template)
Expand All @@ -470,8 +476,9 @@ func (p *stepProcessor) patchOperation(ctx context.Context, bindings binding.Bin
return nil, err
}
var ops []operation
operationReport := report.NewOperation("Patch ", report.OperationTypeCreate)
var operationReport *report.OperationReport
if p.stepReport != nil {
operationReport = report.NewOperation("Patch ", report.OperationTypeCreate)
p.stepReport.AddOperation(operationReport)
}
dryRun := op.DryRun != nil && *op.DryRun
Expand All @@ -495,8 +502,9 @@ func (p *stepProcessor) patchOperation(ctx context.Context, bindings binding.Bin
}

func (p *stepProcessor) scriptOperation(ctx context.Context, bindings binding.Bindings, op v1alpha1.Script) operation {
operationReport := report.NewOperation("Script ", report.OperationTypeScript)
var operationReport *report.OperationReport
if p.stepReport != nil {
operationReport = report.NewOperation("Script ", report.OperationTypeScript)
p.stepReport.AddOperation(operationReport)
}
ns := ""
Expand All @@ -515,8 +523,9 @@ func (p *stepProcessor) scriptOperation(ctx context.Context, bindings binding.Bi
}

func (p *stepProcessor) sleepOperation(ctx context.Context, bindings binding.Bindings, op v1alpha1.Sleep) operation {
operationReport := report.NewOperation("Sleep ", report.OperationTypeSleep)
var operationReport *report.OperationReport
if p.stepReport != nil {
operationReport = report.NewOperation("Sleep ", report.OperationTypeSleep)
p.stepReport.AddOperation(operationReport)
}
return newOperation(
Expand Down
17 changes: 9 additions & 8 deletions pkg/runner/processors/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ type testProcessor struct {

func (p *testProcessor) Run(ctx context.Context, nspacer namespacer.Namespacer) {
t := testing.FromContext(ctx)
t.Cleanup(func() {
if t.Failed() {
p.testReport.NewFailure("test failed")
}
if p.testReport != nil {
if p.testReport != nil {
t.Cleanup(func() {
if t.Failed() {
p.testReport.NewFailure("test failed")
}
p.testReport.MarkTestEnd()
}
})
})
}
size := len("@cleanup")
for i, step := range p.test.Spec.Steps {
name := step.Name
Expand Down Expand Up @@ -191,8 +191,9 @@ func (p *testProcessor) Run(ctx context.Context, nspacer namespacer.Namespacer)
}

func (p *testProcessor) CreateStepProcessor(nspacer namespacer.Namespacer, bindings binding.Bindings, cleaner *cleaner, step v1alpha1.TestSpecStep) StepProcessor {
stepReport := report.NewTestSpecStep(step.Name)
var stepReport *report.TestSpecStepReport
if p.testReport != nil {
stepReport = report.NewTestSpecStep(step.Name)
p.testReport.AddTestStep(stepReport)
}
return NewStepProcessor(p.config, p.clusters, nspacer, p.clock, p.test, step, stepReport, cleaner, bindings)
Expand Down

0 comments on commit 6168cf1

Please sign in to comment.