github.phpd.cn/hashicorp/packer@v1.3.2/packer/artifact_mock.go (about) 1 package packer 2 3 // MockArtifact is an implementation of Artifact that can be used for tests. 4 type MockArtifact struct { 5 BuilderIdValue string 6 FilesValue []string 7 IdValue string 8 StateValues map[string]interface{} 9 DestroyCalled bool 10 StringValue string 11 } 12 13 func (a *MockArtifact) BuilderId() string { 14 if a.BuilderIdValue == "" { 15 return "bid" 16 } 17 18 return a.BuilderIdValue 19 } 20 21 func (a *MockArtifact) Files() []string { 22 if a.FilesValue == nil { 23 return []string{"a", "b"} 24 } 25 26 return a.FilesValue 27 } 28 29 func (a *MockArtifact) Id() string { 30 id := a.IdValue 31 if id == "" { 32 id = "id" 33 } 34 35 return id 36 } 37 38 func (a *MockArtifact) String() string { 39 str := a.StringValue 40 if str == "" { 41 str = "string" 42 } 43 return str 44 } 45 46 func (a *MockArtifact) State(name string) interface{} { 47 value, _ := a.StateValues[name] 48 return value 49 } 50 51 func (a *MockArtifact) Destroy() error { 52 a.DestroyCalled = true 53 return nil 54 }