Import TestBuildIidFileSquash from moby to cli

It's a cli only feature so the test belongs to the cli.

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
This commit is contained in:
Vincent Demeester 2018-06-18 14:09:23 +02:00
parent 0f6936d557
commit 0e83042e54
No known key found for this signature in database
GPG Key ID: 083CC6FD6EB699A3
2 changed files with 53 additions and 0 deletions

View File

@ -2,11 +2,16 @@ package image
import ( import (
"fmt" "fmt"
"io/ioutil"
"path/filepath"
"strings"
"testing" "testing"
"github.com/docker/cli/e2e/internal/fixtures" "github.com/docker/cli/e2e/internal/fixtures"
"github.com/docker/cli/internal/test/environment" "github.com/docker/cli/internal/test/environment"
"github.com/docker/cli/internal/test/output" "github.com/docker/cli/internal/test/output"
"gotest.tools/assert"
is "gotest.tools/assert/cmp"
"gotest.tools/fs" "gotest.tools/fs"
"gotest.tools/icmd" "gotest.tools/icmd"
"gotest.tools/skip" "gotest.tools/skip"
@ -103,6 +108,33 @@ func TestTrustedBuildUntrustedImage(t *testing.T) {
}) })
} }
func TestBuildIidFileSquash(t *testing.T) {
environment.SkipIfNotExperimentalDaemon(t)
dir := fs.NewDir(t, "test-iidfile-squash")
defer dir.Remove()
iidfile := filepath.Join(dir.Path(), "idsquash")
buildDir := fs.NewDir(t, "test-iidfile-squash-build",
fs.WithFile("Dockerfile", fmt.Sprintf(`
FROM %s
ENV FOO FOO
ENV BAR BAR
RUN touch /foop`, fixtures.AlpineImage)),
)
defer buildDir.Remove()
imageTag := "testbuildiidfilesquash"
result := icmd.RunCmd(
icmd.Command("docker", "build", "--iidfile", iidfile, "--squash", "-t", imageTag, "."),
withWorkingDir(buildDir),
)
result.Assert(t, icmd.Success)
id, err := ioutil.ReadFile(iidfile)
assert.NilError(t, err)
result = icmd.RunCommand("docker", "image", "inspect", "-f", "{{.Id}}", imageTag)
result.Assert(t, icmd.Success)
assert.Check(t, is.Equal(string(id), strings.TrimSpace(result.Combined())))
}
func withWorkingDir(dir *fs.Dir) func(*icmd.Cmd) { func withWorkingDir(dir *fs.Dir) func(*icmd.Cmd) {
return func(cmd *icmd.Cmd) { return func(cmd *icmd.Cmd) {
cmd.Dir = dir.Path() cmd.Dir = dir.Path()

View File

@ -1,12 +1,17 @@
package environment package environment
import ( import (
"context"
"os" "os"
"strings" "strings"
"testing"
"time" "time"
"github.com/docker/docker/client"
"github.com/pkg/errors" "github.com/pkg/errors"
"gotest.tools/assert"
"gotest.tools/poll" "gotest.tools/poll"
"gotest.tools/skip"
) )
// Setup a new environment // Setup a new environment
@ -74,5 +79,21 @@ func boolFromString(val string) bool {
} }
} }
func dockerClient(t *testing.T) client.APIClient {
t.Helper()
c, err := client.NewClientWithOpts(client.FromEnv, client.WithVersion("1.37"))
assert.NilError(t, err)
return c
}
// DefaultPollSettings used with gotestyourself/poll // DefaultPollSettings used with gotestyourself/poll
var DefaultPollSettings = poll.WithDelay(100 * time.Millisecond) var DefaultPollSettings = poll.WithDelay(100 * time.Millisecond)
// SkipIfNotExperimentalDaemon returns whether the test docker daemon is in experimental mode
func SkipIfNotExperimentalDaemon(t *testing.T) {
t.Helper()
c := dockerClient(t)
info, err := c.Info(context.Background())
assert.NilError(t, err)
skip.If(t, !info.ExperimentalBuild, "running against a non-experimental daemon")
}