2013-11-09 15:12:23 -05:00
|
|
|
package docker
|
|
|
|
|
2013-11-09 16:15:51 -05:00
|
|
|
import (
|
|
|
|
"io"
|
2015-05-29 12:29:59 -04:00
|
|
|
|
|
|
|
"github.com/hashicorp/go-version"
|
2013-11-09 16:15:51 -05:00
|
|
|
)
|
|
|
|
|
2013-11-09 15:12:23 -05:00
|
|
|
// MockDriver is a driver implementation that can be used for tests.
|
|
|
|
type MockDriver struct {
|
2014-07-20 14:57:10 -04:00
|
|
|
CommitCalled bool
|
|
|
|
CommitContainerId string
|
|
|
|
CommitImageId string
|
|
|
|
CommitErr error
|
|
|
|
|
2014-01-19 22:48:06 -05:00
|
|
|
DeleteImageCalled bool
|
|
|
|
DeleteImageId string
|
|
|
|
DeleteImageErr error
|
|
|
|
|
2014-01-19 22:55:01 -05:00
|
|
|
ImportCalled bool
|
|
|
|
ImportPath string
|
|
|
|
ImportRepo string
|
|
|
|
ImportId string
|
|
|
|
ImportErr error
|
|
|
|
|
2015-06-15 01:09:38 -04:00
|
|
|
IPAddressCalled bool
|
|
|
|
IPAddressID string
|
|
|
|
IPAddressResult string
|
|
|
|
IPAddressErr error
|
|
|
|
|
2020-09-16 04:08:44 -04:00
|
|
|
Sha256Called bool
|
|
|
|
Sha256Id string
|
|
|
|
Sha256Result string
|
|
|
|
Sha256Err error
|
|
|
|
|
2019-03-28 19:55:35 -04:00
|
|
|
KillCalled bool
|
|
|
|
KillID string
|
|
|
|
KillError error
|
|
|
|
|
2014-09-05 17:26:19 -04:00
|
|
|
LoginCalled bool
|
|
|
|
LoginUsername string
|
|
|
|
LoginPassword string
|
|
|
|
LoginRepo string
|
|
|
|
LoginErr error
|
|
|
|
|
|
|
|
LogoutCalled bool
|
|
|
|
LogoutRepo string
|
|
|
|
LogoutErr error
|
|
|
|
|
2014-01-19 23:42:42 -05:00
|
|
|
PushCalled bool
|
|
|
|
PushName string
|
|
|
|
PushErr error
|
|
|
|
|
2014-07-20 16:58:07 -04:00
|
|
|
SaveImageCalled bool
|
|
|
|
SaveImageId string
|
|
|
|
SaveImageReader io.Reader
|
|
|
|
SaveImageError error
|
|
|
|
|
2019-11-22 05:48:36 -05:00
|
|
|
TagImageCalled int
|
2014-07-20 14:58:03 -04:00
|
|
|
TagImageImageId string
|
2019-11-22 05:48:36 -05:00
|
|
|
TagImageRepo []string
|
2015-04-18 00:12:28 -04:00
|
|
|
TagImageForce bool
|
2014-07-20 14:58:03 -04:00
|
|
|
TagImageErr error
|
|
|
|
|
2013-11-09 16:15:51 -05:00
|
|
|
ExportReader io.Reader
|
|
|
|
ExportError error
|
|
|
|
PullError error
|
|
|
|
StartID string
|
|
|
|
StartError error
|
|
|
|
StopError error
|
2013-11-10 00:26:05 -05:00
|
|
|
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
|
2013-11-10 00:26:05 -05:00
|
|
|
VerifyCalled bool
|
2015-05-29 12:29:59 -04:00
|
|
|
|
|
|
|
VersionCalled bool
|
|
|
|
VersionVersion string
|
2013-11-09 16:15:51 -05:00
|
|
|
}
|
|
|
|
|
2016-11-24 07:33:42 -05:00
|
|
|
func (d *MockDriver) Commit(id string, author string, changes []string, message string) (string, error) {
|
2014-07-20 14:57:10 -04:00
|
|
|
d.CommitCalled = true
|
|
|
|
d.CommitContainerId = id
|
|
|
|
return d.CommitImageId, d.CommitErr
|
|
|
|
}
|
|
|
|
|
2014-01-19 22:48:06 -05:00
|
|
|
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
|
2013-11-09 15:12:23 -05:00
|
|
|
}
|
|
|
|
|
2018-12-17 23:13:40 -05:00
|
|
|
func (d *MockDriver) Import(path string, changes []string, repo string) (string, error) {
|
2014-01-19 22:55:01 -05:00
|
|
|
d.ImportCalled = true
|
|
|
|
d.ImportPath = path
|
|
|
|
d.ImportRepo = repo
|
|
|
|
return d.ImportId, d.ImportErr
|
|
|
|
}
|
|
|
|
|
2015-06-15 01:09:38 -04:00
|
|
|
func (d *MockDriver) IPAddress(id string) (string, error) {
|
|
|
|
d.IPAddressCalled = true
|
|
|
|
d.IPAddressID = id
|
|
|
|
return d.IPAddressResult, d.IPAddressErr
|
|
|
|
}
|
|
|
|
|
2020-09-16 04:08:44 -04:00
|
|
|
func (d *MockDriver) Sha256(id string) (string, error) {
|
|
|
|
d.Sha256Called = true
|
|
|
|
d.Sha256Id = id
|
|
|
|
return d.Sha256Result, d.Sha256Err
|
|
|
|
}
|
|
|
|
|
2017-10-25 12:53:51 -04:00
|
|
|
func (d *MockDriver) Login(r, u, p string) error {
|
2014-09-05 17:26:19 -04:00
|
|
|
d.LoginCalled = true
|
|
|
|
d.LoginRepo = r
|
|
|
|
d.LoginUsername = u
|
|
|
|
d.LoginPassword = p
|
|
|
|
return d.LoginErr
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *MockDriver) Logout(r string) error {
|
|
|
|
d.LogoutCalled = true
|
|
|
|
d.LogoutRepo = r
|
|
|
|
return d.LogoutErr
|
|
|
|
}
|
|
|
|
|
2013-11-09 15:12:23 -05:00
|
|
|
func (d *MockDriver) Pull(image string) error {
|
|
|
|
d.PullCalled = true
|
|
|
|
d.PullImage = image
|
|
|
|
return d.PullError
|
|
|
|
}
|
2013-11-09 16:03:01 -05:00
|
|
|
|
2014-01-19 23:42:42 -05:00
|
|
|
func (d *MockDriver) Push(name string) error {
|
|
|
|
d.PushCalled = true
|
|
|
|
d.PushName = name
|
|
|
|
return d.PushErr
|
|
|
|
}
|
|
|
|
|
2014-07-20 16:58:07 -04:00
|
|
|
func (d *MockDriver) SaveImage(id string, dst io.Writer) error {
|
|
|
|
d.SaveImageCalled = true
|
|
|
|
d.SaveImageId = id
|
|
|
|
|
|
|
|
if d.SaveImageReader != nil {
|
|
|
|
_, err := io.Copy(dst, d.SaveImageReader)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return d.SaveImageError
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2019-03-28 19:55:35 -04:00
|
|
|
func (d *MockDriver) KillContainer(id string) error {
|
|
|
|
d.KillCalled = true
|
|
|
|
d.KillID = id
|
|
|
|
return d.KillError
|
|
|
|
}
|
|
|
|
|
2013-11-09 16:03:01 -05:00
|
|
|
func (d *MockDriver) StopContainer(id string) error {
|
|
|
|
d.StopCalled = true
|
|
|
|
d.StopID = id
|
|
|
|
return d.StopError
|
|
|
|
}
|
2013-11-10 00:26:05 -05:00
|
|
|
|
2015-04-18 00:12:28 -04:00
|
|
|
func (d *MockDriver) TagImage(id string, repo string, force bool) error {
|
2019-11-22 05:48:36 -05:00
|
|
|
d.TagImageCalled += 1
|
2014-07-20 14:58:03 -04:00
|
|
|
d.TagImageImageId = id
|
2019-11-22 05:48:36 -05:00
|
|
|
d.TagImageRepo = append(d.TagImageRepo, repo)
|
2015-04-18 00:12:28 -04:00
|
|
|
d.TagImageForce = force
|
2014-07-20 14:58:03 -04:00
|
|
|
return d.TagImageErr
|
|
|
|
}
|
|
|
|
|
2013-11-10 00:26:05 -05:00
|
|
|
func (d *MockDriver) Verify() error {
|
|
|
|
d.VerifyCalled = true
|
|
|
|
return d.VerifyError
|
|
|
|
}
|
2015-05-29 12:29:59 -04:00
|
|
|
|
|
|
|
func (d *MockDriver) Version() (*version.Version, error) {
|
|
|
|
d.VersionCalled = true
|
|
|
|
return version.NewVersion(d.VersionVersion)
|
|
|
|
}
|