Skip to content

Commit 052caaa

Browse files
committed
test: details link support in experimental mode
Signed-off-by: CrazyMax <[email protected]>
1 parent d353f5f commit 052caaa

File tree

2 files changed

+26
-18
lines changed

2 files changed

+26
-18
lines changed

tests/build.go

+15-17
Original file line numberDiff line numberDiff line change
@@ -461,47 +461,45 @@ RUN busybox | head -1 | grep v1.36.1
461461

462462
func testBuildDetailsLink(t *testing.T, sb integration.Sandbox) {
463463
skipNoCompatBuildKit(t, sb, ">= 0.11.0-0", "build details link")
464+
home := t.TempDir()
464465
buildDetailsPattern := regexp.MustCompile(`(?m)^View build details: docker-desktop://dashboard/build/[^/]+/[^/]+/[^/]+\n$`)
465466

466467
// build simple dockerfile
467468
dockerfile := []byte(`FROM busybox:latest
468469
RUN echo foo > /bar`)
469470
dir := tmpdir(t, fstest.CreateFile("Dockerfile", dockerfile, 0600))
470-
cmd := buildxCmd(sb, withArgs("build", "--output=type=cacheonly", dir))
471+
cmd := buildxCmd(sb,
472+
withArgs("build", "--output=type=cacheonly", dir),
473+
withEnv(fmt.Sprintf("HOME=%s", home)),
474+
)
471475
out, err := cmd.CombinedOutput()
472476
require.NoError(t, err, string(out))
473477
require.False(t, buildDetailsPattern.MatchString(string(out)), fmt.Sprintf("build details link not expected in output, got %q", out))
474478

475479
// create desktop-build .lastaccess file
476-
home, err := os.UserHomeDir() // TODO: sandbox should create a temp home dir and expose it through its interface
477-
require.NoError(t, err)
478480
dbDir := path.Join(home, ".docker", "desktop-build")
479481
require.NoError(t, os.MkdirAll(dbDir, 0755))
480-
dblaFile, err := os.Create(path.Join(dbDir, ".lastaccess"))
482+
dblaLastaccess, err := os.Create(path.Join(dbDir, ".lastaccess"))
481483
require.NoError(t, err)
482-
defer func() {
483-
dblaFile.Close()
484-
if err := os.Remove(dblaFile.Name()); err != nil {
485-
t.Fatal(err)
486-
}
487-
}()
484+
require.NoError(t, dblaLastaccess.Close())
488485

489486
// build again
490-
cmd = buildxCmd(sb, withArgs("build", "--output=type=cacheonly", dir))
487+
cmd = buildxCmd(sb,
488+
withArgs("build", "--output=type=cacheonly", dir),
489+
withEnv(fmt.Sprintf("HOME=%s", home)),
490+
)
491491
out, err = cmd.CombinedOutput()
492492
require.NoError(t, err, string(out))
493493
require.True(t, buildDetailsPattern.MatchString(string(out)), fmt.Sprintf("expected build details link in output, got %q", out))
494494

495-
if isExperimental() {
496-
// FIXME: https://github.com/docker/buildx/issues/2382
497-
t.Skip("build details link not displayed in experimental mode when build fails: https://github.com/docker/buildx/issues/2382")
498-
}
499-
500495
// build erroneous dockerfile
501496
dockerfile = []byte(`FROM busybox:latest
502497
RUN exit 1`)
503498
dir = tmpdir(t, fstest.CreateFile("Dockerfile", dockerfile, 0600))
504-
cmd = buildxCmd(sb, withArgs("build", "--output=type=cacheonly", dir))
499+
cmd = buildxCmd(sb,
500+
withArgs("build", "--output=type=cacheonly", dir),
501+
withEnv(fmt.Sprintf("HOME=%s", home)),
502+
)
505503
out, err = cmd.CombinedOutput()
506504
require.Error(t, err, string(out))
507505
require.True(t, buildDetailsPattern.MatchString(string(out)), fmt.Sprintf("expected build details link in output, got %q", out))

tests/integration.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ func buildxCmd(sb integration.Sandbox, opts ...cmdOpt) *exec.Cmd {
6262
)
6363
}
6464
if context := sb.DockerAddress(); context != "" {
65-
cmd.Env = append(cmd.Env, "DOCKER_CONTEXT="+context)
65+
cmd.Env = append(cmd.Env,
66+
"DOCKER_CONFIG="+dockerConfig(sb),
67+
"DOCKER_CONTEXT="+context,
68+
)
6669
}
6770
if isExperimental() {
6871
cmd.Env = append(cmd.Env, "BUILDX_EXPERIMENTAL=1")
@@ -94,6 +97,13 @@ func buildxConfig(sb integration.Sandbox) string {
9497
return ""
9598
}
9699

100+
func dockerConfig(sb integration.Sandbox) string {
101+
if context := sb.DockerAddress(); context != "" {
102+
return "/tmp/docker-" + context
103+
}
104+
return ""
105+
}
106+
97107
func isMobyWorker(sb integration.Sandbox) bool {
98108
name, hasFeature := driverName(sb.Name())
99109
return name == "docker" && !hasFeature

0 commit comments

Comments
 (0)