2018-03-19 18:56:51 -04:00
|
|
|
package engine
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
2018-09-28 17:06:28 -04:00
|
|
|
"github.com/docker/cli/internal/test"
|
2018-09-11 08:46:30 -04:00
|
|
|
clitypes "github.com/docker/cli/types"
|
2018-09-28 17:06:28 -04:00
|
|
|
"github.com/docker/docker/api/types"
|
|
|
|
"github.com/docker/docker/client"
|
2020-02-22 12:12:14 -05:00
|
|
|
"gotest.tools/v3/assert"
|
2018-03-19 18:56:51 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestUpdateNoContainerd(t *testing.T) {
|
|
|
|
testCli.SetContainerizedEngineClient(
|
2018-09-11 08:46:30 -04:00
|
|
|
func(string) (clitypes.ContainerizedClient, error) {
|
2018-03-19 18:56:51 -04:00
|
|
|
return nil, fmt.Errorf("some error")
|
|
|
|
},
|
|
|
|
)
|
|
|
|
cmd := newUpdateCommand(testCli)
|
|
|
|
cmd.SilenceUsage = true
|
|
|
|
cmd.SilenceErrors = true
|
|
|
|
err := cmd.Execute()
|
|
|
|
assert.ErrorContains(t, err, "unable to access local containerd")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUpdateHappy(t *testing.T) {
|
2018-09-28 17:06:28 -04:00
|
|
|
c := test.NewFakeCli(&verClient{client.Client{}, types.Version{Version: "1.1.0"}, nil, types.Info{ServerVersion: "1.1.0"}, nil})
|
|
|
|
c.SetContainerizedEngineClient(
|
2018-09-11 08:46:30 -04:00
|
|
|
func(string) (clitypes.ContainerizedClient, error) {
|
2018-03-19 18:56:51 -04:00
|
|
|
return &fakeContainerizedEngineClient{}, nil
|
|
|
|
},
|
|
|
|
)
|
2018-09-28 17:06:28 -04:00
|
|
|
cmd := newUpdateCommand(c)
|
2018-09-20 14:02:11 -04:00
|
|
|
cmd.Flags().Set("registry-prefix", clitypes.RegistryPrefix)
|
2018-03-19 18:56:51 -04:00
|
|
|
cmd.Flags().Set("version", "someversion")
|
2018-09-28 17:06:28 -04:00
|
|
|
cmd.Flags().Set("engine-image", "someimage")
|
2018-03-19 18:56:51 -04:00
|
|
|
err := cmd.Execute()
|
|
|
|
assert.NilError(t, err)
|
|
|
|
}
|