packer-cn/builder/docker/driver_mock.go

108 lines
2.0 KiB
Go
Raw Normal View History

package docker
2013-11-09 16:15:51 -05:00
import (
"io"
)
// MockDriver is a driver implementation that can be used for tests.
type MockDriver struct {
CommitCalled bool
CommitContainerId string
CommitImageId string
CommitErr error
DeleteImageCalled bool
DeleteImageId string
DeleteImageErr error
ImportCalled bool
ImportPath string
ImportRepo string
ImportId string
ImportErr error
PushCalled bool
PushName string
PushErr error
2013-11-09 16:15:51 -05:00
ExportReader io.Reader
ExportError error
PullError error
StartID string
StartError error
StopError error
VerifyError error
2013-11-09 16:15:51 -05:00
ExportCalled bool
ExportID string
PullCalled bool
PullImage string
StartCalled bool
StartConfig *ContainerConfig
StopCalled bool
StopID string
VerifyCalled bool
2013-11-09 16:15:51 -05:00
}
func (d *MockDriver) Commit(id string) (string, error) {
d.CommitCalled = true
d.CommitContainerId = id
return d.CommitImageId, d.CommitErr
}
func (d *MockDriver) DeleteImage(id string) error {
d.DeleteImageCalled = true
d.DeleteImageId = id
return d.DeleteImageErr
}
2013-11-09 16:15:51 -05:00
func (d *MockDriver) Export(id string, dst io.Writer) error {
d.ExportCalled = true
d.ExportID = id
if d.ExportReader != nil {
_, err := io.Copy(dst, d.ExportReader)
if err != nil {
return err
}
}
return d.ExportError
}
func (d *MockDriver) Import(path, repo string) (string, error) {
d.ImportCalled = true
d.ImportPath = path
d.ImportRepo = repo
return d.ImportId, d.ImportErr
}
func (d *MockDriver) Pull(image string) error {
d.PullCalled = true
d.PullImage = image
return d.PullError
}
2013-11-09 16:03:01 -05:00
func (d *MockDriver) Push(name string) error {
d.PushCalled = true
d.PushName = name
return d.PushErr
}
2013-11-09 16:03:01 -05:00
func (d *MockDriver) StartContainer(config *ContainerConfig) (string, error) {
d.StartCalled = true
d.StartConfig = config
return d.StartID, d.StartError
}
func (d *MockDriver) StopContainer(id string) error {
d.StopCalled = true
d.StopID = id
return d.StopError
}
func (d *MockDriver) Verify() error {
d.VerifyCalled = true
return d.VerifyError
}