github.com/hashicorp/packer@v1.14.3/packer/post_processor_mock.go (about) 1 // Copyright (c) HashiCorp, Inc. 2 // SPDX-License-Identifier: BUSL-1.1 3 4 //go:generate packer-sdc mapstructure-to-hcl2 -type MockPostProcessor 5 package packer 6 7 import ( 8 "context" 9 10 "github.com/hashicorp/hcl/v2/hcldec" 11 packersdk "github.com/hashicorp/packer-plugin-sdk/packer" 12 ) 13 14 // MockPostProcessor is an implementation of PostProcessor that can be 15 // used for tests. 16 type MockPostProcessor struct { 17 ArtifactId string 18 Keep bool 19 ForceOverride bool 20 Error error 21 22 ConfigureCalled bool 23 ConfigureConfigs []interface{} 24 ConfigureError error 25 26 PostProcessCalled bool 27 PostProcessArtifact packersdk.Artifact 28 PostProcessUi packersdk.Ui 29 } 30 31 func (t *MockPostProcessor) ConfigSpec() hcldec.ObjectSpec { return t.FlatMapstructure().HCL2Spec() } 32 33 func (t *MockPostProcessor) Configure(configs ...interface{}) error { 34 t.ConfigureCalled = true 35 t.ConfigureConfigs = configs 36 return t.ConfigureError 37 } 38 39 func (t *MockPostProcessor) PostProcess(ctx context.Context, ui packersdk.Ui, a packersdk.Artifact) (packersdk.Artifact, bool, bool, error) { 40 t.PostProcessCalled = true 41 t.PostProcessArtifact = a 42 t.PostProcessUi = ui 43 44 return &packersdk.MockArtifact{ 45 IdValue: t.ArtifactId, 46 }, t.Keep, t.ForceOverride, t.Error 47 }