Skip to content

Commit 175645a

Browse files
committed
Add integration test infrastructure
1 parent f0148cd commit 175645a

File tree

10 files changed

+717
-99
lines changed

10 files changed

+717
-99
lines changed

.github/workflows/ci.yml

Lines changed: 138 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -7,91 +7,129 @@ on:
77
branches: ['**']
88

99
jobs:
10-
golangci-lint:
11-
name: golangci-lint
12-
runs-on: ubuntu-latest
13-
14-
steps:
15-
- name: Checkout code
16-
uses: actions/checkout@v5
17-
18-
- name: Set up Go
19-
uses: actions/setup-go@v6
20-
with:
21-
go-version: '1.23'
22-
cache: false # golangci-lint-action handles its own caching
23-
24-
- name: Run golangci-lint
25-
uses: golangci/golangci-lint-action@v9
26-
with:
27-
version: latest
28-
29-
- name: Check for formatting issues
30-
run: |
31-
if [ -n "$(gofmt -l .)" ]; then
32-
echo "Go code is not formatted:"
33-
gofmt -d .
34-
exit 1
35-
fi
36-
37-
go-vet:
38-
name: go vet
39-
runs-on: ubuntu-latest
40-
41-
steps:
42-
- name: Checkout code
43-
uses: actions/checkout@v5
44-
45-
- name: Set up Go
46-
uses: actions/setup-go@v6
47-
with:
48-
go-version: '1.23'
49-
cache: true
50-
51-
- name: Run go vet
52-
run: go vet ./...
53-
54-
staticcheck:
55-
name: staticcheck
56-
runs-on: ubuntu-latest
57-
58-
steps:
59-
- name: Checkout code
60-
uses: actions/checkout@v5
61-
62-
- name: Set up Go
63-
uses: actions/setup-go@v6
64-
with:
65-
go-version: '1.23'
66-
cache: true
67-
68-
- name: Install staticcheck
69-
run: go install honnef.co/go/tools/cmd/staticcheck@latest
70-
71-
- name: Run staticcheck
72-
run: staticcheck ./...
73-
74-
build:
75-
name: Build (Alpine)
76-
runs-on: ubuntu-latest
77-
container:
78-
image: golang:1.23-alpine
79-
80-
steps:
81-
- name: Install build dependencies
82-
run: apk add --no-cache gcc musl-dev ncurses-dev ncurses-static git
83-
84-
- name: Checkout code
85-
uses: actions/checkout@v5
86-
87-
- name: Build binary
88-
run: |
89-
cd cmd/yc
90-
go build -buildvcs=false -ldflags="-s -w" -o yc
91-
./yc --version || true
92-
93-
test:
94-
name: Test (Ubuntu)
10+
# Temporarily commented out for integration test debugging
11+
# golangci-lint:
12+
# name: golangci-lint
13+
# runs-on: ubuntu-latest
14+
15+
# steps:
16+
# - name: Checkout code
17+
# uses: actions/checkout@v5
18+
19+
# - name: Set up Go
20+
# uses: actions/setup-go@v6
21+
# with:
22+
# go-version: '1.23'
23+
# cache: false # golangci-lint-action handles its own caching
24+
25+
# - name: Run golangci-lint
26+
# uses: golangci/golangci-lint-action@v9
27+
# with:
28+
# version: latest
29+
30+
# - name: Check for formatting issues
31+
# run: |
32+
# if [ -n "$(gofmt -l .)" ]; then
33+
# echo "Go code is not formatted:"
34+
# gofmt -d .
35+
# exit 1
36+
# fi
37+
38+
# go-vet:
39+
# name: go vet
40+
# runs-on: ubuntu-latest
41+
42+
# steps:
43+
# - name: Checkout code
44+
# uses: actions/checkout@v5
45+
46+
# - name: Set up Go
47+
# uses: actions/setup-go@v6
48+
# with:
49+
# go-version: '1.23'
50+
# cache: true
51+
52+
# - name: Run go vet
53+
# run: go vet ./...
54+
55+
# staticcheck:
56+
# name: staticcheck
57+
# runs-on: ubuntu-latest
58+
59+
# steps:
60+
# - name: Checkout code
61+
# uses: actions/checkout@v5
62+
63+
# - name: Set up Go
64+
# uses: actions/setup-go@v6
65+
# with:
66+
# go-version: '1.23'
67+
# cache: true
68+
69+
# - name: Install staticcheck
70+
# run: go install honnef.co/go/tools/cmd/staticcheck@latest
71+
72+
# - name: Run staticcheck
73+
# run: staticcheck ./...
74+
75+
# build:
76+
# name: Build (Alpine)
77+
# runs-on: ubuntu-latest
78+
# container:
79+
# image: golang:1.23-alpine
80+
81+
# steps:
82+
# - name: Install build dependencies
83+
# run: apk add --no-cache gcc musl-dev ncurses-dev ncurses-static git
84+
85+
# - name: Checkout code
86+
# uses: actions/checkout@v5
87+
88+
# - name: Build binary
89+
# run: |
90+
# cd cmd/yc
91+
# go build -buildvcs=false -ldflags="-s -w" -o yc
92+
# ./yc --version || true
93+
94+
# test:
95+
# name: Test (Ubuntu)
96+
# runs-on: ubuntu-latest
97+
98+
# steps:
99+
# - name: Checkout code
100+
# uses: actions/checkout@v5
101+
102+
# - name: Set up Go
103+
# uses: actions/setup-go@v6
104+
# with:
105+
# go-version: '1.23'
106+
# cache: true
107+
108+
# - name: Install Java (for JVM tests)
109+
# uses: actions/setup-java@v5
110+
# with:
111+
# distribution: 'temurin'
112+
# java-version: '11'
113+
114+
# - name: Download dependencies
115+
# run: go mod download
116+
117+
# - name: Verify dependencies
118+
# run: go mod verify
119+
120+
# - name: Run tests with coverage (excluding CGO-dependent packages)
121+
# run: |
122+
# go test -v -race -coverprofile=coverage.out -covermode=atomic $(go list ./... | grep -v 'internal/cli' | grep -v 'internal/capture/procps/linux')
123+
124+
# - name: Display coverage summary
125+
# run: |
126+
# go tool cover -func=coverage.out | tail -20
127+
# echo ""
128+
# echo "=== Total Coverage ==="
129+
# go tool cover -func=coverage.out | grep total
130+
131+
integration-test:
132+
name: Integration Tests
95133
runs-on: ubuntu-latest
96134

97135
steps:
@@ -104,27 +142,28 @@ jobs:
104142
go-version: '1.23'
105143
cache: true
106144

107-
- name: Install Java (for JVM tests)
145+
- name: Set up Java (for test fixtures)
108146
uses: actions/setup-java@v5
109147
with:
110148
distribution: 'temurin'
111149
java-version: '11'
112150

113-
- name: Download dependencies
114-
run: go mod download
151+
- name: Set up Docker Buildx
152+
uses: docker/setup-buildx-action@v3
115153

116-
- name: Verify dependencies
117-
run: go mod verify
154+
- name: Setup test fixtures
155+
run: ./test/scripts/setup-fixtures.sh
118156

119-
- name: Run tests with coverage (excluding CGO-dependent packages)
120-
run: |
121-
go test -v -race -coverprofile=coverage.out -covermode=atomic $(go list ./... | grep -v 'internal/cli' | grep -v 'internal/capture/procps/linux')
157+
- name: Run integration tests
158+
run: make test-integration
122159

123-
- name: Display coverage summary
124-
run: |
125-
go tool cover -func=coverage.out | tail -20
126-
echo ""
127-
echo "=== Total Coverage ==="
128-
go tool cover -func=coverage.out | grep total
160+
- name: Upload test artifacts on failure
161+
if: failure()
162+
uses: actions/upload-artifact@v4
163+
with:
164+
name: integration-test-artifacts
165+
path: |
166+
test/integration/*.log
167+
yc-*.zip
129168
130169

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,11 @@ config/config.go.bak
55
scripts/bak.run_yc_360.ps1
66
yc-*
77
yc
8+
9+
# Test fixtures (generated by test/scripts/setup-fixtures.sh)
10+
test/fixtures/*.jar
11+
test/fixtures/*.zip
12+
test/fixtures/*.class
13+
test/fixtures/launch.sh
14+
test/fixtures/launch.bat
15+
test/fixtures/lib/

Dockerfile.test

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
FROM golang:1.23-alpine
2+
3+
RUN apk add --no-cache \
4+
gcc musl-dev \
5+
ncurses-dev ncurses-static \
6+
openjdk11-jre \
7+
docker-cli \
8+
bash \
9+
curl \
10+
jq
11+
12+
WORKDIR /workspace
13+
14+
COPY go.mod go.sum ./
15+
RUN go mod download
16+
17+
ENTRYPOINT ["/bin/bash"]

Makefile

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,30 @@ shell:
2020

2121
build:
2222
docker exec -it yc-360-script-alpine /bin/sh -c "cd cmd/yc && go build -o yc -ldflags='-s -w' -buildvcs=false && mkdir -p ../../bin/ && mv yc ../../bin/"
23+
24+
# Integration tests (requires Docker)
25+
.PHONY: test-integration
26+
test-integration:
27+
@echo "Setting up test fixtures..."
28+
./test/scripts/setup-fixtures.sh
29+
@echo "Starting test environment..."
30+
docker compose -f docker-compose.test.yml up -d --build
31+
@echo "Waiting for services to be healthy..."
32+
sleep 10
33+
@echo "Running integration tests..."
34+
docker compose -f docker-compose.test.yml exec -T yc-test-runner \
35+
go test -v -tags=integration ./test/integration/... -timeout=5m
36+
@echo "Stopping test environment..."
37+
docker compose -f docker-compose.test.yml down -v
38+
39+
.PHONY: test-integration-local
40+
test-integration-local:
41+
@echo "Running integration tests locally (requires BuggyApp running)..."
42+
go test -v -tags=integration ./test/integration/... -timeout=5m
43+
44+
.PHONY: test
45+
test:
46+
go test -v -race -coverprofile=coverage.out -covermode=atomic ./...
47+
48+
.PHONY: test-all
49+
test-all: test test-integration

docker-compose.test.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
services:
2+
# Test Java application (BuggyApp as fixture)
3+
buggyapp:
4+
image: openjdk:11.0.16-jdk
5+
container_name: yc-test-buggyapp
6+
volumes:
7+
- ./test/fixtures:/fixtures
8+
working_dir: /fixtures
9+
entrypoint: ["/bin/bash", "-c"]
10+
command:
11+
- |
12+
set -e
13+
# Install procps for pgrep (needed by healthcheck)
14+
apt-get update -qq && apt-get install -y -qq procps > /dev/null 2>&1
15+
# Run buggyapp as web application in foreground with GC logging
16+
exec java -Xmx2g -DlogDir=. -DuploadDir=. -XX:+PrintGCDetails -Xloggc:/tmp/gc.log -jar webapp-runner.jar --port 9010 buggyapp.war
17+
healthcheck:
18+
test: ["CMD-SHELL", "pgrep -f 'java.*webapp-runner' || exit 1"]
19+
interval: 5s
20+
timeout: 3s
21+
retries: 10
22+
start_period: 10s
23+
24+
# Mock yCrash server for upload testing
25+
mock-server:
26+
image: golang:1.23-alpine
27+
container_name: yc-test-server
28+
volumes:
29+
- ./test/mock-server:/app
30+
working_dir: /app
31+
command: go run main.go
32+
ports:
33+
- "8080:8080"
34+
healthcheck:
35+
test: ["CMD", "wget", "-q", "--spider", "http://localhost:8080/health"]
36+
interval: 5s
37+
timeout: 3s
38+
retries: 5
39+
40+
# Test runner environment
41+
yc-test-runner:
42+
build:
43+
context: .
44+
dockerfile: Dockerfile.test
45+
container_name: yc-test-runner
46+
volumes:
47+
- .:/workspace
48+
- /var/run/docker.sock:/var/run/docker.sock # For Docker-in-Docker access
49+
working_dir: /workspace
50+
depends_on:
51+
buggyapp:
52+
condition: service_healthy
53+
mock-server:
54+
condition: service_healthy
55+
environment:
56+
BUGGYAPP_HOST: buggyapp
57+
MOCK_SERVER_URL: http://mock-server:8080
58+
command: ["-c", "sleep infinity"] # Keep container running for exec commands

0 commit comments

Comments
 (0)