Skip to content

Commit df75712

Browse files
authored
chore: add integration test for provider (#233)
This PR adds integration tests for the provider against an arbitrary version of Coder. Example usage: ``` CODER_VERSION="v2.10.0-devel-3a9a7d199-amd64" go test -v ./integration Testing methodology: ``` - Create an ephemeral Coder instance running in a container - Perform initial setup - Import a predefined template that creates a single file - Create a workspace that populates the file with the actual output - Compare the actual versus expected output
1 parent 4f417ad commit df75712

File tree

6 files changed

+506
-39
lines changed

6 files changed

+506
-39
lines changed

Makefile

+13-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,19 @@ fmt:
66
gen:
77
go run github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs@latest
88

9+
build: terraform-provider-coder
10+
11+
# Builds the provider. Note that as coder/coder is based on
12+
# alpine, we need to disable cgo.
13+
terraform-provider-coder: provider/*.go main.go
14+
CGO_ENABLED=0 go build .
15+
16+
# Run integration tests
17+
.PHONY: test-integration
18+
test-integration: terraform-provider-coder
19+
go test -v ./integration
20+
921
# Run acceptance tests
1022
.PHONY: testacc
1123
testacc:
12-
TF_ACC=1 go test ./... -v $(TESTARGS) -timeout 120m
24+
TF_ACC=1 go test ./... -v $(TESTARGS) -timeout 120m

README.md

+40-11
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ to setup your local Terraform to use your local version rather than the registry
2020

2121
1. Create a file named `.terraformrc` in your `$HOME` directory
2222
2. Add the following content:
23+
2324
```hcl
2425
provider_installation {
2526
# Override the coder/coder provider to use your local version
@@ -33,18 +34,46 @@ to setup your local Terraform to use your local version rather than the registry
3334
direct {}
3435
}
3536
```
37+
3638
3. (optional, but recommended) Validate your configuration:
37-
1. Create a new `main.tf` file and include:
38-
```hcl
39-
terraform {
40-
required_providers {
41-
coder = {
42-
source = "coder/coder"
43-
}
44-
}
45-
}
46-
```
39+
1. Create a new `main.tf` file and include:
40+
```hcl
41+
terraform {
42+
required_providers {
43+
coder = {
44+
source = "coder/coder"
45+
}
46+
}
47+
}
48+
```
4749
2. Run `terraform init` and observe a warning like `Warning: Provider development overrides are in effect`
4850
4. Run `go build -o terraform-provider-coder` to build the provider binary, which Terraform will try locate and execute
4951
5. All local Terraform runs will now use your local provider!
50-
6. _**NOTE**: we vendor in this provider into `github.com/coder/coder`, so if you're testing with a local clone then you should also run `go mod edit -replace github.com/coder/terraform-provider-coder=/path/to/terraform-provider-coder` in your clone._
52+
6. _**NOTE**: we vendor in this provider into `github.com/coder/coder`, so if you're testing with a local clone then you should also run `go mod edit -replace github.com/coder/terraform-provider-coder=/path/to/terraform-provider-coder` in your clone._
53+
54+
#### Terraform Acceptance Tests
55+
56+
To run Terraform acceptance tests, run `make testacc`. This will test the provider against the locally installed version of Terraform.
57+
58+
> **Note:** our [CI workflow](./github/workflows/test.yml) runs a test matrix against multiple Terraform versions.
59+
60+
#### Integration Tests
61+
62+
The tests under the `./integration` directory perform the following steps:
63+
64+
- Build the local version of the provider,
65+
- Run an in-memory Coder instance with a specified version,
66+
- Validate the behaviour of the local provider against that specific version of Coder.
67+
68+
To run these integration tests locally:
69+
70+
1. Pull the version of the Coder image you wish to test:
71+
72+
```console
73+
docker pull ghcr.io/coder/coder:main-x.y.z-devel-abcd1234
74+
```
75+
76+
1. Run `CODER_VERSION=main-x.y.z-devel-abcd1234 make test-integration`.
77+
78+
> **Note:** you can specify `CODER_IMAGE` if the Coder image you wish to test is hosted somewhere other than `ghcr.io/coder/coder`.
79+
> For example, `CODER_IMAGE=example.com/repo/coder CODER_VERSION=foobar make test-integration`.

go.mod

+32-9
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ go 1.22
55
toolchain go1.22.3
66

77
require (
8+
github.com/docker/docker v26.1.3+incompatible
89
github.com/google/uuid v1.6.0
910
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
1011
github.com/hashicorp/terraform-plugin-sdk/v2 v2.20.0
@@ -18,10 +19,18 @@ require (
1819
github.com/Microsoft/go-winio v0.5.2 // indirect
1920
github.com/agext/levenshtein v1.2.3 // indirect
2021
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
22+
github.com/containerd/log v0.1.0 // indirect
2123
github.com/davecgh/go-spew v1.1.1 // indirect
24+
github.com/distribution/reference v0.6.0 // indirect
25+
github.com/docker/go-connections v0.5.0 // indirect
26+
github.com/docker/go-units v0.5.0 // indirect
2227
github.com/fatih/color v1.13.0 // indirect
23-
github.com/golang/protobuf v1.5.3 // indirect
24-
github.com/google/go-cmp v0.5.9 // indirect
28+
github.com/felixge/httpsnoop v1.0.4 // indirect
29+
github.com/go-logr/logr v1.4.1 // indirect
30+
github.com/go-logr/stdr v1.2.2 // indirect
31+
github.com/gogo/protobuf v1.3.2 // indirect
32+
github.com/golang/protobuf v1.5.4 // indirect
33+
github.com/google/go-cmp v0.6.0 // indirect
2534
github.com/hashicorp/errwrap v1.1.0 // indirect
2635
github.com/hashicorp/go-checkpoint v0.5.0 // indirect
2736
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
@@ -47,20 +56,34 @@ require (
4756
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
4857
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
4958
github.com/mitchellh/reflectwalk v1.0.2 // indirect
59+
github.com/moby/docker-image-spec v1.3.1 // indirect
60+
github.com/moby/term v0.5.0 // indirect
61+
github.com/morikuni/aec v1.0.0 // indirect
5062
github.com/oklog/run v1.0.0 // indirect
63+
github.com/opencontainers/go-digest v1.0.0 // indirect
64+
github.com/opencontainers/image-spec v1.1.0 // indirect
65+
github.com/pkg/errors v0.9.1 // indirect
5166
github.com/pmezard/go-difflib v1.0.0 // indirect
5267
github.com/rogpeppe/go-internal v1.8.0 // indirect
5368
github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect
5469
github.com/vmihailenco/msgpack/v4 v4.3.12 // indirect
5570
github.com/vmihailenco/tagparser v0.1.1 // indirect
5671
github.com/zclconf/go-cty v1.10.0 // indirect
57-
golang.org/x/crypto v0.21.0 // indirect
58-
golang.org/x/net v0.23.0 // indirect
59-
golang.org/x/sys v0.18.0 // indirect
60-
golang.org/x/text v0.14.0 // indirect
61-
google.golang.org/appengine v1.6.7 // indirect
72+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.52.0 // indirect
73+
go.opentelemetry.io/otel v1.27.0 // indirect
74+
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.27.0 // indirect
75+
go.opentelemetry.io/otel/metric v1.27.0 // indirect
76+
go.opentelemetry.io/otel/sdk v1.27.0 // indirect
77+
go.opentelemetry.io/otel/trace v1.27.0 // indirect
78+
golang.org/x/crypto v0.23.0 // indirect
79+
golang.org/x/net v0.25.0 // indirect
80+
golang.org/x/sys v0.20.0 // indirect
81+
golang.org/x/text v0.15.0 // indirect
82+
golang.org/x/time v0.5.0 // indirect
83+
google.golang.org/appengine v1.6.8 // indirect
6284
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
63-
google.golang.org/grpc v1.56.3 // indirect
64-
google.golang.org/protobuf v1.33.0 // indirect
85+
google.golang.org/grpc v1.64.0 // indirect
86+
google.golang.org/protobuf v1.34.1 // indirect
6587
gopkg.in/yaml.v3 v3.0.1 // indirect
88+
gotest.tools/v3 v3.5.1 // indirect
6689
)

0 commit comments

Comments
 (0)