github.com/askholme/packer@v0.7.2-0.20140924152349-70d9566a6852/packer/builder_mock.go (about) 1 package packer 2 3 import ( 4 "errors" 5 ) 6 7 // MockBuilder is an implementation of Builder that can be used for tests. 8 // You can set some fake return values and you can keep track of what 9 // methods were called on the builder. It is fairly basic. 10 type MockBuilder struct { 11 ArtifactId string 12 PrepareWarnings []string 13 RunErrResult bool 14 RunNilResult bool 15 16 PrepareCalled bool 17 PrepareConfig []interface{} 18 RunCalled bool 19 RunCache Cache 20 RunHook Hook 21 RunUi Ui 22 CancelCalled bool 23 } 24 25 func (tb *MockBuilder) Prepare(config ...interface{}) ([]string, error) { 26 tb.PrepareCalled = true 27 tb.PrepareConfig = config 28 return tb.PrepareWarnings, nil 29 } 30 31 func (tb *MockBuilder) Run(ui Ui, h Hook, c Cache) (Artifact, error) { 32 tb.RunCalled = true 33 tb.RunHook = h 34 tb.RunUi = ui 35 tb.RunCache = c 36 37 if tb.RunErrResult { 38 return nil, errors.New("foo") 39 } 40 41 if tb.RunNilResult { 42 return nil, nil 43 } 44 45 return &MockArtifact{ 46 IdValue: tb.ArtifactId, 47 }, nil 48 } 49 50 func (tb *MockBuilder) Cancel() { 51 tb.CancelCalled = true 52 }