90a57c411f
In order that something consuming an artifact can have access to extra builder specific data add the State method which allows the caller to ask for arbitary values by name.
50 lines
841 B
Go
50 lines
841 B
Go
package packer
|
|
|
|
// MockArtifact is an implementation of Artifact that can be used for tests.
|
|
type MockArtifact struct {
|
|
BuilderIdValue string
|
|
FilesValue []string
|
|
IdValue string
|
|
StateValues map[string]interface{}
|
|
DestroyCalled bool
|
|
}
|
|
|
|
func (a *MockArtifact) BuilderId() string {
|
|
if a.BuilderIdValue == "" {
|
|
return "bid"
|
|
}
|
|
|
|
return a.BuilderIdValue
|
|
}
|
|
|
|
func (a *MockArtifact) Files() []string {
|
|
if a.FilesValue == nil {
|
|
return []string{"a", "b"}
|
|
}
|
|
|
|
return a.FilesValue
|
|
}
|
|
|
|
func (a *MockArtifact) Id() string {
|
|
id := a.IdValue
|
|
if id == "" {
|
|
id = "id"
|
|
}
|
|
|
|
return id
|
|
}
|
|
|
|
func (*MockArtifact) String() string {
|
|
return "string"
|
|
}
|
|
|
|
func (a *MockArtifact) State(name string) interface{} {
|
|
value, _ := a.StateValues[name]
|
|
return value
|
|
}
|
|
|
|
func (a *MockArtifact) Destroy() error {
|
|
a.DestroyCalled = true
|
|
return nil
|
|
}
|