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

Lines changed: 13 additions & 1 deletion
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

Lines changed: 40 additions & 11 deletions
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

Lines changed: 32 additions & 9 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy