Skip to content

Commit

Permalink
Merge pull request #12594 from hashicorp/backport/nywilken/catch-nil-…
Browse files Browse the repository at this point in the history
…checkpoint-reporter/poorly-generous-puma

This pull request was automerged via backport-assistant
  • Loading branch information
hc-github-team-packer authored Aug 18, 2023
2 parents bff91f4 + b746ad2 commit e92e9ac
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packer/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ func (c *CheckpointTelemetry) SetTemplateType(t PackerTemplateType) {

// SetBundledUsage marks the template as using bundled plugins
func (c *CheckpointTelemetry) SetBundledUsage() {
if c == nil {
return
}
c.useBundled = true
}

Expand Down
22 changes: 22 additions & 0 deletions packer/telemetry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package packer

import (
"errors"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -33,3 +34,24 @@ func TestFlattenConfigKeys_nested(t *testing.T) {
"Input didn't flatten correctly.",
)
}

func TestCheckpointTelemetry(t *testing.T) {
defer func() {
if r := recover(); r != nil {
t.Error("a noop CheckpointTelemetry should not to panic but it did\n", r)
}
}()

// A null CheckpointTelemetry obtained in Packer when the CHECKPOINT_DISABLE env var is set results in a NOOP reporter
// The null reporter can be executable as a configured reporter but does not report any telemetry data.
var c *CheckpointTelemetry
c.SetTemplateType(HCL2Template)
c.SetBundledUsage()
c.AddSpan("mockprovisioner", "provisioner", nil)
if err := c.ReportPanic("Bogus Panic"); err != nil {
t.Errorf("calling ReportPanic on a nil checkpoint reporter should not error")
}
if err := c.Finalize("test", 1, errors.New("Bogus Error")); err != nil {
t.Errorf("calling Finalize on a nil checkpoint reporter should not error")
}
}

0 comments on commit e92e9ac

Please sign in to comment.