mirror of https://github.com/hashicorp/packer
parent
cfb53005ff
commit
cc0f91b41b
@ -0,0 +1,33 @@
|
|||||||
|
package packer
|
||||||
|
|
||||||
|
// MockArtifact is an implementation of Artifact that can be used for tests.
|
||||||
|
type MockArtifact struct {
|
||||||
|
IdValue string
|
||||||
|
DestroyCalled bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*MockArtifact) BuilderId() string {
|
||||||
|
return "bid"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*MockArtifact) Files() []string {
|
||||||
|
return []string{"a", "b"}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *MockArtifact) Id() string {
|
||||||
|
id := a.IdValue
|
||||||
|
if id == "" {
|
||||||
|
id = "id"
|
||||||
|
}
|
||||||
|
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*MockArtifact) String() string {
|
||||||
|
return "string"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *MockArtifact) Destroy() error {
|
||||||
|
a.DestroyCalled = true
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@ -0,0 +1,36 @@
|
|||||||
|
package packer
|
||||||
|
|
||||||
|
// MockBuilder is an implementation of Builder that can be used for tests.
|
||||||
|
// You can set some fake return values and you can keep track of what
|
||||||
|
// methods were called on the builder. It is fairly basic.
|
||||||
|
type MockBuilder struct {
|
||||||
|
ArtifactId string
|
||||||
|
|
||||||
|
PrepareCalled bool
|
||||||
|
PrepareConfig []interface{}
|
||||||
|
RunCalled bool
|
||||||
|
RunCache Cache
|
||||||
|
RunHook Hook
|
||||||
|
RunUi Ui
|
||||||
|
CancelCalled bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func (tb *MockBuilder) Prepare(config ...interface{}) error {
|
||||||
|
tb.PrepareCalled = true
|
||||||
|
tb.PrepareConfig = config
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (tb *MockBuilder) Run(ui Ui, h Hook, c Cache) (Artifact, error) {
|
||||||
|
tb.RunCalled = true
|
||||||
|
tb.RunHook = h
|
||||||
|
tb.RunUi = ui
|
||||||
|
tb.RunCache = c
|
||||||
|
return &MockArtifact{
|
||||||
|
IdValue: tb.ArtifactId,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (tb *MockBuilder) Cancel() {
|
||||||
|
tb.CancelCalled = true
|
||||||
|
}
|
||||||
Loading…
Reference in new issue