github.com/sneal/packer@v0.5.2/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 DeleteImageCalled bool 10 DeleteImageId string 11 DeleteImageErr error 12 13 ImportCalled bool 14 ImportPath string 15 ImportRepo string 16 ImportId string 17 ImportErr error 18 19 PushCalled bool 20 PushName string 21 PushErr error 22 23 ExportReader io.Reader 24 ExportError error 25 PullError error 26 StartID string 27 StartError error 28 StopError error 29 VerifyError error 30 31 ExportCalled bool 32 ExportID string 33 PullCalled bool 34 PullImage string 35 StartCalled bool 36 StartConfig *ContainerConfig 37 StopCalled bool 38 StopID string 39 VerifyCalled bool 40 } 41 42 func (d *MockDriver) DeleteImage(id string) error { 43 d.DeleteImageCalled = true 44 d.DeleteImageId = id 45 return d.DeleteImageErr 46 } 47 48 func (d *MockDriver) Export(id string, dst io.Writer) error { 49 d.ExportCalled = true 50 d.ExportID = id 51 52 if d.ExportReader != nil { 53 _, err := io.Copy(dst, d.ExportReader) 54 if err != nil { 55 return err 56 } 57 } 58 59 return d.ExportError 60 } 61 62 func (d *MockDriver) Import(path, repo string) (string, error) { 63 d.ImportCalled = true 64 d.ImportPath = path 65 d.ImportRepo = repo 66 return d.ImportId, d.ImportErr 67 } 68 69 func (d *MockDriver) Pull(image string) error { 70 d.PullCalled = true 71 d.PullImage = image 72 return d.PullError 73 } 74 75 func (d *MockDriver) Push(name string) error { 76 d.PushCalled = true 77 d.PushName = name 78 return d.PushErr 79 } 80 81 func (d *MockDriver) StartContainer(config *ContainerConfig) (string, error) { 82 d.StartCalled = true 83 d.StartConfig = config 84 return d.StartID, d.StartError 85 } 86 87 func (d *MockDriver) StopContainer(id string) error { 88 d.StopCalled = true 89 d.StopID = id 90 return d.StopError 91 } 92 93 func (d *MockDriver) Verify() error { 94 d.VerifyCalled = true 95 return d.VerifyError 96 }