2018-11-09 09:10:41 -05:00
|
|
|
package context
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/docker/cli/cli/command"
|
|
|
|
"github.com/docker/cli/cli/context/docker"
|
2020-02-22 12:12:14 -05:00
|
|
|
"gotest.tools/v3/assert"
|
|
|
|
"gotest.tools/v3/assert/cmp"
|
2018-11-09 09:10:41 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestUpdateDescriptionOnly(t *testing.T) {
|
2022-02-25 07:07:16 -05:00
|
|
|
cli := makeFakeCli(t)
|
2019-01-21 03:37:20 -05:00
|
|
|
err := RunCreate(cli, &CreateOptions{
|
2022-02-24 06:59:15 -05:00
|
|
|
Name: "test",
|
|
|
|
Docker: map[string]string{},
|
2018-11-09 09:10:41 -05:00
|
|
|
})
|
|
|
|
assert.NilError(t, err)
|
|
|
|
cli.OutBuffer().Reset()
|
|
|
|
cli.ErrBuffer().Reset()
|
2019-01-21 03:37:20 -05:00
|
|
|
assert.NilError(t, RunUpdate(cli, &UpdateOptions{
|
|
|
|
Name: "test",
|
|
|
|
Description: "description",
|
2018-11-09 09:10:41 -05:00
|
|
|
}))
|
2019-04-18 09:12:30 -04:00
|
|
|
c, err := cli.ContextStore().GetMetadata("test")
|
2018-11-09 09:10:41 -05:00
|
|
|
assert.NilError(t, err)
|
|
|
|
dc, err := command.GetDockerContext(c)
|
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Equal(t, dc.Description, "description")
|
|
|
|
|
|
|
|
assert.Equal(t, "test\n", cli.OutBuffer().String())
|
|
|
|
assert.Equal(t, "Successfully updated context \"test\"\n", cli.ErrBuffer().String())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUpdateDockerOnly(t *testing.T) {
|
2022-02-25 07:07:16 -05:00
|
|
|
cli := makeFakeCli(t)
|
2022-02-24 06:59:15 -05:00
|
|
|
createTestContext(t, cli, "test")
|
2019-01-21 03:37:20 -05:00
|
|
|
assert.NilError(t, RunUpdate(cli, &UpdateOptions{
|
|
|
|
Name: "test",
|
|
|
|
Docker: map[string]string{
|
2018-11-09 09:10:41 -05:00
|
|
|
keyHost: "tcp://some-host",
|
|
|
|
},
|
|
|
|
}))
|
2019-04-18 09:12:30 -04:00
|
|
|
c, err := cli.ContextStore().GetMetadata("test")
|
2018-11-09 09:10:41 -05:00
|
|
|
assert.NilError(t, err)
|
|
|
|
dc, err := command.GetDockerContext(c)
|
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Equal(t, dc.Description, "description of test")
|
|
|
|
assert.Check(t, cmp.Contains(c.Endpoints, docker.DockerEndpoint))
|
|
|
|
assert.Equal(t, c.Endpoints[docker.DockerEndpoint].(docker.EndpointMeta).Host, "tcp://some-host")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUpdateInvalidDockerHost(t *testing.T) {
|
2022-02-25 07:07:16 -05:00
|
|
|
cli := makeFakeCli(t)
|
2019-01-21 03:37:20 -05:00
|
|
|
err := RunCreate(cli, &CreateOptions{
|
|
|
|
Name: "test",
|
|
|
|
Docker: map[string]string{},
|
2018-11-09 09:10:41 -05:00
|
|
|
})
|
|
|
|
assert.NilError(t, err)
|
2019-01-21 03:37:20 -05:00
|
|
|
err = RunUpdate(cli, &UpdateOptions{
|
|
|
|
Name: "test",
|
|
|
|
Docker: map[string]string{
|
2018-11-09 09:10:41 -05:00
|
|
|
keyHost: "some///invalid/host",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
assert.ErrorContains(t, err, "unable to parse docker host")
|
|
|
|
}
|