integration-cli: remove cli.Build(), cli.Inspect()

They were just small wrappers arround cli.Args(), and the abstraction
made one wonder if they were doing some "magic" things, but they weren't,
so just inlining the `cli.Args()` makes it more transparent what's executed.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2022-02-23 13:19:28 +01:00
parent bc0885f364
commit 940730093b
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
4 changed files with 27 additions and 37 deletions

View file

@ -32,12 +32,12 @@ func DockerCmd(t testing.TB, args ...string) *icmd.Result {
// BuildCmd executes the specified docker build command and expect a success
func BuildCmd(t testing.TB, name string, cmdOperators ...CmdOperator) *icmd.Result {
return Docker(Build(name), cmdOperators...).Assert(t, icmd.Success)
return Docker(Args("build", "-t", name), cmdOperators...).Assert(t, icmd.Success)
}
// InspectCmd executes the specified docker inspect command and expect a success
func InspectCmd(t testing.TB, name string, cmdOperators ...CmdOperator) *icmd.Result {
return Docker(Inspect(name), cmdOperators...).Assert(t, icmd.Success)
return Docker(Args("inspect", name), cmdOperators...).Assert(t, icmd.Success)
}
// WaitRun will wait for the specified container to be running, maximum 5 seconds.
@ -122,16 +122,6 @@ func validateArgs(args ...string) error {
return nil
}
// Build executes the specified docker build command
func Build(name string) icmd.Cmd {
return icmd.Command("build", "-t", name)
}
// Inspect executes the specified docker inspect command
func Inspect(name string) icmd.Cmd {
return icmd.Command("inspect", name)
}
// Format sets the specified format with --format flag
func Format(format string) func(*icmd.Cmd) func() {
return func(cmd *icmd.Cmd) func() {

View file

@ -384,7 +384,7 @@ func (s *DockerCLIBuildSuite) TestBuildCacheAdd(c *testing.T) {
cli.BuildCmd(c, name, build.WithDockerfile(fmt.Sprintf(`FROM scratch
ADD %s/robots.txt /`, server.URL())))
result := cli.Docker(cli.Build(name), build.WithDockerfile(fmt.Sprintf(`FROM scratch
result := cli.Docker(cli.Args("build", "-t", name), build.WithDockerfile(fmt.Sprintf(`FROM scratch
ADD %s/index.html /`, server.URL())))
result.Assert(c, icmd.Success)
if strings.Contains(result.Combined(), "Using cache") {
@ -3777,13 +3777,13 @@ func (s *DockerCLIBuildSuite) TestBuildSpaces(c *testing.T) {
ctx := fakecontext.New(c, "", fakecontext.WithDockerfile("FROM busybox\nCOPY\n"))
defer ctx.Close()
result1 := cli.Docker(cli.Build(name), build.WithExternalBuildContext(ctx))
result1 := cli.Docker(cli.Args("build", "-t", name), build.WithExternalBuildContext(ctx))
result1.Assert(c, icmd.Expected{
ExitCode: 1,
})
ctx.Add("Dockerfile", "FROM busybox\nCOPY ")
result2 := cli.Docker(cli.Build(name), build.WithExternalBuildContext(ctx))
result2 := cli.Docker(cli.Args("build", "-t", name), build.WithExternalBuildContext(ctx))
result2.Assert(c, icmd.Expected{
ExitCode: 1,
})
@ -3802,7 +3802,7 @@ func (s *DockerCLIBuildSuite) TestBuildSpaces(c *testing.T) {
}
ctx.Add("Dockerfile", "FROM busybox\n COPY")
result2 = cli.Docker(cli.Build(name), build.WithoutCache, build.WithExternalBuildContext(ctx))
result2 = cli.Docker(cli.Args("build", "-t", name), build.WithoutCache, build.WithExternalBuildContext(ctx))
result2.Assert(c, icmd.Expected{
ExitCode: 1,
})
@ -3817,7 +3817,7 @@ func (s *DockerCLIBuildSuite) TestBuildSpaces(c *testing.T) {
}
ctx.Add("Dockerfile", "FROM busybox\n COPY ")
result2 = cli.Docker(cli.Build(name), build.WithoutCache, build.WithExternalBuildContext(ctx))
result2 = cli.Docker(cli.Args("build", "-t", name), build.WithoutCache, build.WithExternalBuildContext(ctx))
result2.Assert(c, icmd.Expected{
ExitCode: 1,
})
@ -5677,7 +5677,7 @@ func (s *DockerCLIBuildSuite) TestBuildMultiStageCopyFromErrors(c *testing.T) {
"foo": "abc",
}))
cli.Docker(cli.Build("build1"), build.WithExternalBuildContext(ctx)).Assert(c, icmd.Expected{
cli.Docker(cli.Args("build", "-t", "build1"), build.WithExternalBuildContext(ctx)).Assert(c, icmd.Expected{
ExitCode: 1,
Err: tc.expectedError,
})
@ -5879,7 +5879,7 @@ func (s *DockerCLIBuildSuite) TestBuildCopyFromWindowsIsCaseInsensitive(c *testi
COPY --from=0 c:\\fOo c:\\copied
RUN type c:\\copied
`
cli.Docker(cli.Build("copyfrom-windows-insensitive"), build.WithBuildContext(c,
cli.Docker(cli.Args("build", "-t", "copyfrom-windows-insensitive"), build.WithBuildContext(c,
build.WithFile("Dockerfile", dockerfile),
build.WithFile("foo", "hello world"),
)).Assert(c, icmd.Expected{
@ -5932,7 +5932,7 @@ func (s *DockerCLIBuildSuite) TestBuildIntermediateTarget(c *testing.T) {
res = cli.InspectCmd(c, "build1", cli.Format("json .Config.Cmd")).Combined()
assert.Equal(c, strings.TrimSpace(res), `["/dev"]`)
result := cli.Docker(cli.Build("build1"), build.WithExternalBuildContext(ctx),
result := cli.Docker(cli.Args("build", "-t", "build1"), build.WithExternalBuildContext(ctx),
cli.WithFlags("--target", "nosuchtarget"))
result.Assert(c, icmd.Expected{
ExitCode: 1,
@ -6050,7 +6050,7 @@ func (s *DockerCLIBuildSuite) TestBuildLineErrorOnBuild(c *testing.T) {
// FIXME(vdemeester) should be a unit test
func (s *DockerCLIBuildSuite) TestBuildLineErrorUnknownInstruction(c *testing.T) {
name := "test_build_line_error_unknown_instruction"
cli.Docker(cli.Build(name), build.WithDockerfile(`FROM busybox
cli.Docker(cli.Args("build", "-t", name), build.WithDockerfile(`FROM busybox
RUN echo hello world
NOINSTRUCTION echo ba
RUN echo hello
@ -6064,7 +6064,7 @@ func (s *DockerCLIBuildSuite) TestBuildLineErrorUnknownInstruction(c *testing.T)
// FIXME(vdemeester) should be a unit test
func (s *DockerCLIBuildSuite) TestBuildLineErrorWithEmptyLines(c *testing.T) {
name := "test_build_line_error_with_empty_lines"
cli.Docker(cli.Build(name), build.WithDockerfile(`
cli.Docker(cli.Args("build", "-t", name), build.WithDockerfile(`
FROM busybox
RUN echo hello world
@ -6081,7 +6081,7 @@ func (s *DockerCLIBuildSuite) TestBuildLineErrorWithEmptyLines(c *testing.T) {
// FIXME(vdemeester) should be a unit test
func (s *DockerCLIBuildSuite) TestBuildLineErrorWithComments(c *testing.T) {
name := "test_build_line_error_with_comments"
cli.Docker(cli.Build(name), build.WithDockerfile(`FROM busybox
cli.Docker(cli.Args("build", "-t", name), build.WithDockerfile(`FROM busybox
# This will print hello world
# and then ba
RUN echo hello world
@ -6148,7 +6148,7 @@ func (s *DockerCLIBuildSuite) TestBuildIidFileCleanupOnFail(c *testing.T) {
err = os.WriteFile(tmpIidFile, []byte("Dummy"), 0666)
assert.NilError(c, err)
cli.Docker(cli.Build("testbuildiidfilecleanuponfail"),
cli.Docker(cli.Args("build", "-t", "testbuildiidfilecleanuponfail"),
build.WithDockerfile(`FROM `+minimalBaseImage()+`
RUN /non/existing/command`),
cli.WithFlags("--iidfile", tmpIidFile)).Assert(c, icmd.Expected{

View file

@ -3943,7 +3943,7 @@ func (s *DockerCLIRunSuite) TestRunRm(c *testing.T) {
name := "miss-me-when-im-gone"
cli.DockerCmd(c, "run", "--name="+name, "--rm", "busybox")
cli.Docker(cli.Inspect(name), cli.Format(".name")).Assert(c, icmd.Expected{
cli.Docker(cli.Args("inspect", name), cli.Format(".name")).Assert(c, icmd.Expected{
ExitCode: 1,
Err: "No such object: " + name,
})
@ -3955,7 +3955,7 @@ func (s *DockerCLIRunSuite) TestRunRmPre125Api(c *testing.T) {
envs := appendBaseEnv(os.Getenv("DOCKER_TLS_VERIFY") != "", "DOCKER_API_VERSION=1.24")
cli.Docker(cli.Args("run", "--name="+name, "--rm", "busybox"), cli.WithEnvironmentVariables(envs...)).Assert(c, icmd.Success)
cli.Docker(cli.Inspect(name), cli.Format(".name")).Assert(c, icmd.Expected{
cli.Docker(cli.Args("inspect", name), cli.Format(".name")).Assert(c, icmd.Expected{
ExitCode: 1,
Err: "No such object: " + name,
})

View file

@ -84,7 +84,7 @@ func inspectFieldAndUnmarshall(c *testing.T, name, field string, output interfac
assert.Assert(c, err == nil, "failed to unmarshal: %v", err)
}
// Deprecated: use cli.Inspect
// Deprecated: use cli.Docker
func inspectFilter(name, filter string) (string, error) {
format := fmt.Sprintf("{{%s}}", filter)
result := icmd.RunCommand(dockerBinary, "inspect", "-f", format, name)
@ -94,12 +94,12 @@ func inspectFilter(name, filter string) (string, error) {
return strings.TrimSpace(result.Combined()), nil
}
// Deprecated: use cli.Inspect
// Deprecated: use cli.Docker
func inspectFieldWithError(name, field string) (string, error) {
return inspectFilter(name, "."+field)
}
// Deprecated: use cli.Inspect
// Deprecated: use cli.Docker
func inspectField(c *testing.T, name, field string) string {
c.Helper()
out, err := inspectFilter(name, "."+field)
@ -107,7 +107,7 @@ func inspectField(c *testing.T, name, field string) string {
return out
}
// Deprecated: use cli.Inspect
// Deprecated: use cli.Docker
func inspectFieldJSON(c *testing.T, name, field string) string {
c.Helper()
out, err := inspectFilter(name, "json ."+field)
@ -115,7 +115,7 @@ func inspectFieldJSON(c *testing.T, name, field string) string {
return out
}
// Deprecated: use cli.Inspect
// Deprecated: use cli.Docker
func inspectFieldMap(c *testing.T, name, path, field string) string {
c.Helper()
out, err := inspectFilter(name, fmt.Sprintf("index .%s %q", path, field))
@ -123,7 +123,7 @@ func inspectFieldMap(c *testing.T, name, path, field string) string {
return out
}
// Deprecated: use cli.Inspect
// Deprecated: use cli.Docker
func inspectMountSourceField(name, destination string) (string, error) {
m, err := inspectMountPoint(name, destination)
if err != nil {
@ -132,7 +132,7 @@ func inspectMountSourceField(name, destination string) (string, error) {
return m.Source, nil
}
// Deprecated: use cli.Inspect
// Deprecated: use cli.Docker
func inspectMountPoint(name, destination string) (types.MountPoint, error) {
out, err := inspectFilter(name, "json .Mounts")
if err != nil {
@ -144,7 +144,7 @@ func inspectMountPoint(name, destination string) (types.MountPoint, error) {
var errMountNotFound = errors.New("mount point not found")
// Deprecated: use cli.Inspect
// Deprecated: use cli.Docker
func inspectMountPointJSON(j, destination string) (types.MountPoint, error) {
var mp []types.MountPoint
if err := json.Unmarshal([]byte(j), &mp); err != nil {
@ -173,15 +173,15 @@ func getIDByName(c *testing.T, name string) string {
return id
}
// Deprecated: use cli.Build
// Deprecated: use cli.Docker
func buildImageSuccessfully(c *testing.T, name string, cmdOperators ...cli.CmdOperator) {
c.Helper()
buildImage(name, cmdOperators...).Assert(c, icmd.Success)
}
// Deprecated: use cli.Build
// Deprecated: use cli.Docker
func buildImage(name string, cmdOperators ...cli.CmdOperator) *icmd.Result {
return cli.Docker(cli.Build(name), cmdOperators...)
return cli.Docker(cli.Args("build", "-t", name), cmdOperators...)
}
// Write `content` to the file at path `dst`, creating it if necessary,