github.com/kaixiang/packer@v0.5.2-0.20140114230416-1f5786b0d7f1/builder/docker/driver_mock.go (about) 1 package docker 2 3 import ( 4 "io" 5 ) 6 7 // MockDriver is a driver implementation that can be used for tests. 8 type MockDriver struct { 9 ExportReader io.Reader 10 ExportError error 11 PullError error 12 StartID string 13 StartError error 14 StopError error 15 VerifyError error 16 17 ExportCalled bool 18 ExportID string 19 PullCalled bool 20 PullImage string 21 StartCalled bool 22 StartConfig *ContainerConfig 23 StopCalled bool 24 StopID string 25 VerifyCalled bool 26 } 27 28 func (d *MockDriver) Export(id string, dst io.Writer) error { 29 d.ExportCalled = true 30 d.ExportID = id 31 32 if d.ExportReader != nil { 33 _, err := io.Copy(dst, d.ExportReader) 34 if err != nil { 35 return err 36 } 37 } 38 39 return d.ExportError 40 } 41 42 func (d *MockDriver) Pull(image string) error { 43 d.PullCalled = true 44 d.PullImage = image 45 return d.PullError 46 } 47 48 func (d *MockDriver) StartContainer(config *ContainerConfig) (string, error) { 49 d.StartCalled = true 50 d.StartConfig = config 51 return d.StartID, d.StartError 52 } 53 54 func (d *MockDriver) StopContainer(id string) error { 55 d.StopCalled = true 56 d.StopID = id 57 return d.StopError 58 } 59 60 func (d *MockDriver) Verify() error { 61 d.VerifyCalled = true 62 return d.VerifyError 63 }