Skip to content

Commit 523bccb

Browse files
authored
Add Docker-based testing environment (#383)
Introduces reproducible testing infrastructure using Docker containers to ensure consistent test execution across different development environments. Changes: - Add Dockerfile.test for containerized test runs - Add TESTING.md with comprehensive testing documentation - Support for both local and Docker-based workflows Benefits: - Isolated test environment (Go 1.24-alpine) - Layer caching for faster builds - No dependency on local Go installation - Easy CI/CD integration Usage: docker build -f Dockerfile.test -t terraform-provider-civo:test . docker run --rm terraform-provider-civo:test
1 parent 6dd531e commit 523bccb

File tree

2 files changed

+113
-0
lines changed

2 files changed

+113
-0
lines changed

Dockerfile.test

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM golang:1.24-alpine
2+
3+
WORKDIR /workspace
4+
5+
# Install build dependencies
6+
RUN apk add --no-cache git make bash
7+
8+
# Copy go.mod and go.sum first for better caching
9+
COPY go.mod go.sum ./
10+
RUN go mod download
11+
12+
# Copy source code
13+
COPY . .
14+
15+
# Default command runs unit tests
16+
CMD ["make", "test"]

TESTING.md

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# Testing Guide
2+
3+
## Docker-Based Testing
4+
5+
This project includes a Docker-based testing environment for reproducible test runs in an isolated environment.
6+
7+
### Quick Start
8+
9+
```bash
10+
# Build the test image
11+
docker build -f Dockerfile.test -t terraform-provider-civo:test .
12+
13+
# Run unit tests
14+
docker run --rm terraform-provider-civo:test
15+
16+
# Run build verification
17+
docker run --rm terraform-provider-civo:test make build
18+
19+
# Run format check
20+
docker run --rm terraform-provider-civo:test make fmtcheck
21+
```
22+
23+
### Test Environment
24+
25+
- **Base Image**: golang:1.24-alpine
26+
- **Dependencies**: git, make, bash
27+
- **Go Modules**: Pre-downloaded for faster execution
28+
- **Default Command**: `make test` (runs unit test suite)
29+
30+
### Benefits
31+
32+
- **Reproducible**: Same environment for all developers and CI/CD
33+
- **Isolated**: No dependency on local Go installation or system packages
34+
- **Fast**: Layer caching speeds up subsequent builds
35+
- **Clean**: Tests run in a fresh environment every time
36+
37+
### Local Testing (Without Docker)
38+
39+
```bash
40+
# Run unit tests
41+
make test
42+
43+
# Run acceptance tests (requires CIVO_TOKEN)
44+
TF_ACC=1 make testacc
45+
46+
# Build the provider
47+
make build
48+
49+
# Format code
50+
make fmt
51+
52+
# Check formatting
53+
make fmtcheck
54+
```
55+
56+
### CI/CD Integration
57+
58+
The Docker test environment can be integrated into CI/CD pipelines:
59+
60+
```yaml
61+
# Example GitHub Actions workflow
62+
test:
63+
runs-on: ubuntu-latest
64+
steps:
65+
- uses: actions/checkout@v2
66+
- name: Build test image
67+
run: docker build -f Dockerfile.test -t terraform-provider-civo:test .
68+
- name: Run tests
69+
run: docker run --rm terraform-provider-civo:test
70+
```
71+
72+
## Test Coverage
73+
74+
The test suite covers:
75+
76+
- Provider configuration and initialization
77+
- All resource CRUD operations (Create, Read, Update, Delete)
78+
- Data source queries
79+
- Input validation and error handling
80+
- SSH key generation and validation
81+
82+
## Requirements
83+
84+
- Docker (for containerized testing)
85+
- Go 1.24+ (for local testing)
86+
- CIVO API token (for acceptance tests only)
87+
88+
## Contributing
89+
90+
When adding new features:
91+
92+
1. Add unit tests for new functionality
93+
2. Run the full test suite: `make test`
94+
3. Verify formatting: `make fmtcheck`
95+
4. Build verification: `make build`
96+
97+
For acceptance tests that interact with the Civo API, follow existing patterns in the `civo/acceptance` directory.

0 commit comments

Comments
 (0)