2018-03-19 18:56:51 -04:00
|
|
|
package engine
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/containerd/containerd"
|
|
|
|
registryclient "github.com/docker/cli/cli/registry/client"
|
2018-09-11 08:46:30 -04:00
|
|
|
clitypes "github.com/docker/cli/types"
|
2018-03-19 18:56:51 -04:00
|
|
|
"github.com/docker/docker/api/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
type (
|
|
|
|
fakeContainerizedEngineClient struct {
|
|
|
|
closeFunc func() error
|
|
|
|
activateEngineFunc func(ctx context.Context,
|
2018-09-11 08:46:30 -04:00
|
|
|
opts clitypes.EngineInitOptions,
|
|
|
|
out clitypes.OutStream,
|
2018-10-01 18:12:09 -04:00
|
|
|
authConfig *types.AuthConfig) error
|
2018-03-19 18:56:51 -04:00
|
|
|
initEngineFunc func(ctx context.Context,
|
2018-09-11 08:46:30 -04:00
|
|
|
opts clitypes.EngineInitOptions,
|
|
|
|
out clitypes.OutStream,
|
2018-03-19 18:56:51 -04:00
|
|
|
authConfig *types.AuthConfig,
|
|
|
|
healthfn func(context.Context) error) error
|
|
|
|
doUpdateFunc func(ctx context.Context,
|
2018-09-11 08:46:30 -04:00
|
|
|
opts clitypes.EngineInitOptions,
|
|
|
|
out clitypes.OutStream,
|
2018-10-01 18:12:09 -04:00
|
|
|
authConfig *types.AuthConfig) error
|
2018-03-19 18:56:51 -04:00
|
|
|
getEngineVersionsFunc func(ctx context.Context,
|
|
|
|
registryClient registryclient.RegistryClient,
|
|
|
|
currentVersion,
|
2018-09-11 08:46:30 -04:00
|
|
|
imageName string) (clitypes.AvailableVersions, error)
|
2018-03-19 18:56:51 -04:00
|
|
|
|
|
|
|
getEngineFunc func(ctx context.Context) (containerd.Container, error)
|
2018-09-11 08:46:30 -04:00
|
|
|
removeEngineFunc func(ctx context.Context) error
|
|
|
|
getCurrentEngineVersionFunc func(ctx context.Context) (clitypes.EngineInitOptions, error)
|
2018-03-19 18:56:51 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
func (w *fakeContainerizedEngineClient) Close() error {
|
|
|
|
if w.closeFunc != nil {
|
|
|
|
return w.closeFunc()
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *fakeContainerizedEngineClient) ActivateEngine(ctx context.Context,
|
2018-09-11 08:46:30 -04:00
|
|
|
opts clitypes.EngineInitOptions,
|
|
|
|
out clitypes.OutStream,
|
2018-10-01 18:12:09 -04:00
|
|
|
authConfig *types.AuthConfig) error {
|
2018-03-19 18:56:51 -04:00
|
|
|
if w.activateEngineFunc != nil {
|
2018-10-01 18:12:09 -04:00
|
|
|
return w.activateEngineFunc(ctx, opts, out, authConfig)
|
2018-03-19 18:56:51 -04:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
func (w *fakeContainerizedEngineClient) InitEngine(ctx context.Context,
|
2018-09-11 08:46:30 -04:00
|
|
|
opts clitypes.EngineInitOptions,
|
|
|
|
out clitypes.OutStream,
|
2018-03-19 18:56:51 -04:00
|
|
|
authConfig *types.AuthConfig,
|
|
|
|
healthfn func(context.Context) error) error {
|
|
|
|
if w.initEngineFunc != nil {
|
|
|
|
return w.initEngineFunc(ctx, opts, out, authConfig, healthfn)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
func (w *fakeContainerizedEngineClient) DoUpdate(ctx context.Context,
|
2018-09-11 08:46:30 -04:00
|
|
|
opts clitypes.EngineInitOptions,
|
|
|
|
out clitypes.OutStream,
|
2018-10-01 18:12:09 -04:00
|
|
|
authConfig *types.AuthConfig) error {
|
2018-03-19 18:56:51 -04:00
|
|
|
if w.doUpdateFunc != nil {
|
2018-10-01 18:12:09 -04:00
|
|
|
return w.doUpdateFunc(ctx, opts, out, authConfig)
|
2018-03-19 18:56:51 -04:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
func (w *fakeContainerizedEngineClient) GetEngineVersions(ctx context.Context,
|
|
|
|
registryClient registryclient.RegistryClient,
|
2018-09-11 08:46:30 -04:00
|
|
|
currentVersion, imageName string) (clitypes.AvailableVersions, error) {
|
2018-03-19 18:56:51 -04:00
|
|
|
|
|
|
|
if w.getEngineVersionsFunc != nil {
|
|
|
|
return w.getEngineVersionsFunc(ctx, registryClient, currentVersion, imageName)
|
|
|
|
}
|
2018-09-11 08:46:30 -04:00
|
|
|
return clitypes.AvailableVersions{}, nil
|
2018-03-19 18:56:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (w *fakeContainerizedEngineClient) GetEngine(ctx context.Context) (containerd.Container, error) {
|
|
|
|
if w.getEngineFunc != nil {
|
|
|
|
return w.getEngineFunc(ctx)
|
|
|
|
}
|
|
|
|
return nil, nil
|
|
|
|
}
|
2018-09-11 08:46:30 -04:00
|
|
|
func (w *fakeContainerizedEngineClient) RemoveEngine(ctx context.Context) error {
|
2018-03-19 18:56:51 -04:00
|
|
|
if w.removeEngineFunc != nil {
|
2018-09-11 08:46:30 -04:00
|
|
|
return w.removeEngineFunc(ctx)
|
2018-03-19 18:56:51 -04:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2018-09-11 08:46:30 -04:00
|
|
|
func (w *fakeContainerizedEngineClient) GetCurrentEngineVersion(ctx context.Context) (clitypes.EngineInitOptions, error) {
|
2018-03-19 18:56:51 -04:00
|
|
|
if w.getCurrentEngineVersionFunc != nil {
|
|
|
|
return w.getCurrentEngineVersionFunc(ctx)
|
|
|
|
}
|
2018-09-11 08:46:30 -04:00
|
|
|
return clitypes.EngineInitOptions{}, nil
|
2018-03-19 18:56:51 -04:00
|
|
|
}
|