|
| 1 | +// Copyright 2025 The Go Authors. All rights reserved. |
| 2 | +// Use of this source code is governed by a BSD-style |
| 3 | +// license that can be found in the LICENSE file. |
| 4 | + |
| 5 | +package integration_test |
| 6 | + |
| 7 | +import ( |
| 8 | + "os" |
| 9 | + "os/exec" |
| 10 | + "path/filepath" |
| 11 | + "strings" |
| 12 | + "testing" |
| 13 | +) |
| 14 | + |
| 15 | +func TestIntegration(t *testing.T) { |
| 16 | + dir, err := os.Getwd() |
| 17 | + if err != nil { |
| 18 | + t.Fatalf("failed to read current dir: %v", err) |
| 19 | + } |
| 20 | + root := filepath.Dir(dir) |
| 21 | + |
| 22 | + // Build docker image. |
| 23 | + // TODO(hxjiang): use Go in PATH instead of env GOVERSION. LUCI will prepare |
| 24 | + // the Go in different version so vscode-go test don't need to worry. |
| 25 | + dockerBuild := exec.Command("docker", "build", "-q", "-f", "./build/Dockerfile", ".") |
| 26 | + // The docker build must be executed at the root of the vscode-go repository |
| 27 | + // to ensure the entire repository is copied into the image. |
| 28 | + dockerBuild.Dir = root |
| 29 | + output, err := dockerBuild.Output() |
| 30 | + if err != nil { |
| 31 | + t.Fatalf("failed to build docker image: %v", err) |
| 32 | + } |
| 33 | + imageID := strings.TrimSpace(string(output)) |
| 34 | + |
| 35 | + // Cleanup the image if built successfully. |
| 36 | + defer func() { |
| 37 | + dockerRmi := exec.Command("docker", "rmi", "-f", imageID) |
| 38 | + output, err := dockerRmi.CombinedOutput() |
| 39 | + if err != nil { |
| 40 | + t.Errorf("failed to remove image %v", imageID) |
| 41 | + } |
| 42 | + t.Logf("image cleanup log:\n%s\n", output) |
| 43 | + }() |
| 44 | + |
| 45 | + // Run integration test using previous build docker image. |
| 46 | + // For debug tests, we need ptrace. |
| 47 | + // TODO(hxjiang): migrate the shell based ci test with go test. |
| 48 | + // TODO(hxjiang): remove ANSI escape codes from npm log. |
| 49 | + dockerRun := exec.Command("docker", "run", "--cap-add", "SYS_PTRACE", "--shm-size=8G", "--workdir=/workspace", imageID, "ci") |
| 50 | + output, err = dockerRun.CombinedOutput() |
| 51 | + t.Logf("integration test log:\n%s\n", output) |
| 52 | + if err != nil { |
| 53 | + t.Errorf("failed to run integration test: %v", err) |
| 54 | + } |
| 55 | +} |
0 commit comments