Skip to content

Commit 2e07aa3

Browse files
h9jianggopherbot
authored andcommitted
build: migrate script trigger test to go test trigger
Kokoro triggers the test through: - sudo chown -R 1000:1000 - build docker image with all required tools - mount vscode-go repo to docker image - run npm test and go test in docker This go test is slightly different than Kokoro: - build docker image with the vscode-go copied and owner modified to 1000:1000. - run npm test and go test in docker without mounting. - cleanup image. LUCI test run https://ci.chromium.org/b/8724574170882251953 For #3533 Change-Id: If31e13d9b121fb0cfa56c65ec3c801989b9f0ebe Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/642917 Auto-Submit: Hongxiang Jiang <[email protected]> kokoro-CI: kokoro <[email protected]> Commit-Queue: Hongxiang Jiang <[email protected]> Reviewed-by: Robert Findley <[email protected]>
1 parent 7df3953 commit 2e07aa3

File tree

3 files changed

+63
-1
lines changed

3 files changed

+63
-1
lines changed

build/Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ RUN mkdir /go
1616
COPY --from=gobuilder /gobin /go/bin
1717
COPY --from=gobuilder /usr/local/go /usr/local/go
1818

19+
# Copy vscode-go repo from host machine to docker image.
20+
COPY . /workspace
21+
22+
# Tests run in a Docker container as user 'node' (uid 1000), so file ownership
23+
# is changed to uid 1000 to prevent permission issues.
24+
RUN chown -R 1000:1000 /workspace
25+
1926
# Add the default GOPATH/bin to the PATH.
2027
# Add the directories of the go tool chains to PATH.
2128
ENV PATH /go/bin:/usr/local/go/bin:${PATH}

build/all.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ run_test_in_docker() {
7474
docker build -t vscode-test-env ${GOVERSION:+ --build-arg GOVERSION="${GOVERSION}"} -f ./build/Dockerfile .
7575

7676
# For debug tests, we need ptrace.
77-
docker run --cap-add SYS_PTRACE --shm-size=8G --workdir=/workspace -v "$(pwd):/workspace" vscode-test-env ci
77+
docker run --cap-add SYS_PTRACE --shm-size=8G --workdir=/workspace vscode-test-env ci
7878
}
7979

8080
main() {

build/integration_test.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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

Comments
 (0)