github.com/hashicorp/packer@v1.14.3/packer/telemetry_test.go (about) 1 // Copyright (c) HashiCorp, Inc. 2 // SPDX-License-Identifier: BUSL-1.1 3 4 package packer 5 6 import ( 7 "errors" 8 "testing" 9 10 "github.com/stretchr/testify/assert" 11 ) 12 13 func TestFlattenConfigKeys_nil(t *testing.T) { 14 f := flattenConfigKeys(nil) 15 assert.Zero(t, f, "Expected empty list.") 16 } 17 18 func TestFlattenConfigKeys_nested(t *testing.T) { 19 inp := make(map[string]interface{}) 20 inp["A"] = "" 21 inp["B"] = []string{} 22 23 c := make(map[string]interface{}) 24 c["X"] = "" 25 d := make(map[string]interface{}) 26 d["a"] = "" 27 28 c["Y"] = d 29 inp["C"] = c 30 31 assert.Equal(t, 32 []string{"A", "B", "C/X", "C/Y/a"}, 33 flattenConfigKeys(inp), 34 "Input didn't flatten correctly.", 35 ) 36 } 37 38 func TestCheckpointTelemetry(t *testing.T) { 39 defer func() { 40 if r := recover(); r != nil { 41 t.Error("a noop CheckpointTelemetry should not to panic but it did\n", r) 42 } 43 }() 44 45 // A null CheckpointTelemetry obtained in Packer when the CHECKPOINT_DISABLE env var is set results in a NOOP reporter 46 // The null reporter can be executable as a configured reporter but does not report any telemetry data. 47 var c *CheckpointTelemetry 48 c.SetTemplateType(HCL2Template) 49 c.SetBundledUsage() 50 c.AddSpan("mockprovisioner", "provisioner", nil) 51 if err := c.ReportPanic("Bogus Panic"); err != nil { 52 t.Errorf("calling ReportPanic on a nil checkpoint reporter should not error") 53 } 54 if err := c.Finalize("test", 1, errors.New("Bogus Error")); err != nil { 55 t.Errorf("calling Finalize on a nil checkpoint reporter should not error") 56 } 57 }