2020-12-09 06:39:54 -05:00
|
|
|
//go:generate mapstructure-to-hcl2 -type MockPostProcessor
|
2015-05-26 12:28:59 -04:00
|
|
|
package packer
|
|
|
|
|
2019-12-17 05:25:56 -05:00
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/hashicorp/hcl/v2/hcldec"
|
2020-11-19 14:54:31 -05:00
|
|
|
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
2019-12-17 05:25:56 -05:00
|
|
|
)
|
2019-03-22 09:56:02 -04:00
|
|
|
|
2015-05-26 12:28:59 -04:00
|
|
|
// MockPostProcessor is an implementation of PostProcessor that can be
|
|
|
|
// used for tests.
|
|
|
|
type MockPostProcessor struct {
|
2019-04-02 19:51:58 -04:00
|
|
|
ArtifactId string
|
|
|
|
Keep bool
|
|
|
|
ForceOverride bool
|
|
|
|
Error error
|
2015-05-26 12:28:59 -04:00
|
|
|
|
|
|
|
ConfigureCalled bool
|
|
|
|
ConfigureConfigs []interface{}
|
|
|
|
ConfigureError error
|
|
|
|
|
|
|
|
PostProcessCalled bool
|
2020-11-19 15:17:11 -05:00
|
|
|
PostProcessArtifact packersdk.Artifact
|
2020-11-19 14:54:31 -05:00
|
|
|
PostProcessUi packersdk.Ui
|
2015-05-26 12:28:59 -04:00
|
|
|
}
|
|
|
|
|
2019-12-17 05:25:56 -05:00
|
|
|
func (t *MockPostProcessor) ConfigSpec() hcldec.ObjectSpec { return t.FlatMapstructure().HCL2Spec() }
|
|
|
|
|
2015-05-26 12:28:59 -04:00
|
|
|
func (t *MockPostProcessor) Configure(configs ...interface{}) error {
|
|
|
|
t.ConfigureCalled = true
|
|
|
|
t.ConfigureConfigs = configs
|
|
|
|
return t.ConfigureError
|
|
|
|
}
|
|
|
|
|
2020-11-19 15:17:11 -05:00
|
|
|
func (t *MockPostProcessor) PostProcess(ctx context.Context, ui packersdk.Ui, a packersdk.Artifact) (packersdk.Artifact, bool, bool, error) {
|
2015-05-26 12:28:59 -04:00
|
|
|
t.PostProcessCalled = true
|
|
|
|
t.PostProcessArtifact = a
|
|
|
|
t.PostProcessUi = ui
|
|
|
|
|
2020-11-19 15:17:11 -05:00
|
|
|
return &packersdk.MockArtifact{
|
2015-05-26 12:28:59 -04:00
|
|
|
IdValue: t.ArtifactId,
|
2019-04-02 19:51:58 -04:00
|
|
|
}, t.Keep, t.ForceOverride, t.Error
|
2015-05-26 12:28:59 -04:00
|
|
|
}
|