diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml new file mode 100644 index 0000000..e378971 --- /dev/null +++ b/.github/workflows/build-test.yml @@ -0,0 +1,33 @@ +name: build & test +on: + push: + branches: main + paths: + - "**.go" + - .github/workflows/build-test.yml + - "go.mod" + - "go.sum" + - "docs/**" + - "examples/**" + pull_request: + branches: main +jobs: + build-test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v4 + with: + go-version: "1.x" + - uses: actions/cache@v3 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + - name: build + run: make build + - name: test + run: make test + - name: lint + run: sudo make lint diff --git a/Makefile b/Makefile index abe78e2..231305e 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,7 @@ VERSION ?= $(shell cat $(CURDIR)/VERSION) BINARY ?= terraform-provider-oxide_$(VERSION) BINARY_LOCATION ?= bin/$(BINARY) OS_ARCH ?= $(shell go env GOOS)_$(shell go env GOARCH) +export GOBIN = $(shell pwd)/bin # Terraform currently does not have a binary for Illumos. # The one for Solaris works fine with Illumos, so we'll need @@ -15,11 +16,15 @@ PROVIDER_PATH ?= registry.terraform.io/oxidecomputer/oxide/$(VERSION)/$(OS_ARCH) PLUGIN_LOCATION ?= ~/.terraform.d/plugins/$(PROVIDER_PATH) # Acceptance test variables -TEST_COUNT ?= 1 +TEST_ACC_COUNT ?= 1 TEST_ACC ?= github.com/oxidecomputer/terraform-provider-oxide/oxide -TEST_NAME ?= TestAcc +TEST_ACC_NAME ?= TestAcc TEST_ACC_PARALLEL = 6 +# Unit test variables +TEST_ARGS ?= -timeout 10m -race -cover +TEST_PACKAGE ?= ./oxide + include Makefile.tools ### Build targets @@ -37,16 +42,20 @@ install: build @ mkdir -p $(PLUGIN_LOCATION) @ cp $(BINARY_LOCATION) $(PLUGIN_LOCATION) +## Run unit tests. Use TEST_ARGS to set `go test` CLI arguments, and TEST_UNIT_DIR to set packages to be tested +.PHONY: test +test: + @ echo "-> Running unit tests for $(BINARY)..." + @ go test $(TEST_PACKAGE) $(TEST_ARGS) $(TESTUNITARGS) + ## Lints all of the source files .PHONY: lint -lint: golint golangci-lint tfproviderdocs terrafmt configfmt # tfproviderlint +lint: golint golangci-lint tfproviderdocs terrafmt tfproviderlint # configfmt -# tf providerlint currently has a bug with the latest stable go version (1.18), will uncomment -# when this issue is solved https://github.com/bflad/tfproviderlint/issues/255 -# .PHONY: tfproviderlint -# tfproviderlint: tools -# @ echo "-> Checking source code against terraform provider linters..." -# @ $(GOBIN)/tfproviderlint ./... +.PHONY: tfproviderlint +tfproviderlint: tools + @ echo "-> Checking source code against terraform provider linters..." + @ $(GOBIN)/tfproviderlint ./... .PHONY: tfproviderdocs tfproviderdocs: tools @@ -66,17 +75,17 @@ golint: tools .PHONY: terrafmt terrafmt: tools @ echo "-> Checking that the terraform docs codeblocks are formatted..." - @ find ./docs -type f -name "*.md" -exec $(GOBIN)/terrafmt diff -c -q {} \; + @ find ./docs -type f -name "*.md" -exec $(GOBIN)/terrafmt diff -f {} \; configfmt: @ echo "-> Checking that the terraform .tf files are formatted..." @ terraform fmt -write=false -recursive -check .PHONY: testacc -## Runs the Terraform acceptance tests. Use TEST_NAME, TESTARGS, TEST_COUNT and TEST_ACC_PARALLEL to control execution. +## Runs the Terraform acceptance tests. Use TEST_ACC_NAME, TEST_ACC_ARGS, TEST_ACC_COUNT and TEST_ACC_PARALLEL for acceptance testing settings. testacc: @ echo "-> Running terraform acceptance tests..." - @ TF_ACC=1 go test $(TEST_ACC) -v -count $(TEST_COUNT) -parallel $(TEST_ACC_PARALLEL) $(TESTARGS) -timeout 20m -run $(TEST_NAME) + @ TF_ACC=1 go test $(TEST_ACC) -v -count $(TEST_ACC_COUNT) -parallel $(TEST_ACC_PARALLEL) $(TEST_ACC_ARGS) -timeout 20m -run $(TEST_ACC_NAME) .PHONY: local-api ## Use local API language client diff --git a/Makefile.tools b/Makefile.tools index bc5cf70..5dc04a2 100644 --- a/Makefile.tools +++ b/Makefile.tools @@ -2,14 +2,12 @@ OS:=$(shell uname -s | tr '[:upper:]' '[:lower:]') VERSION_DIR:=$(GOBIN)/versions VERSION_GOLINT:=v0.0.0-20210508222113-6edffad5e616 -VERSION_GOLANGCILINT:=v1.46.2 +VERSION_GOLANGCILINT:=v1.52.2 VERSION_TFPROVIDERDOCS:=v0.9.1 -VERSION_TERRAFMT:=v0.4.0 -VERSION_TFPROVIDERLINT:=v0.28.1 +VERSION_TERRAFMT:=v0.5.2 +VERSION_TFPROVIDERLINT:=v0.29.0 -tools: $(GOBIN)/golint $(GOBIN)/golangci-lint $(GOBIN)/tfproviderdocs $(GOBIN)/terrafmt -# tfproviderlint currently has a bug https://github.com/bflad/tfproviderlint/issues/255 will uncomment when resolved. -# $(GOBIN)/tfproviderlint +tools: $(GOBIN)/golint $(GOBIN)/golangci-lint $(GOBIN)/tfproviderdocs $(GOBIN)/terrafmt $(GOBIN)/tfproviderlint $(GOBIN): @ mkdir -p $(GOBIN) @@ -49,10 +47,10 @@ $(GOBIN)/terrafmt: $(VERSION_DIR)/.version-terrafmt-$(VERSION_TERRAFMT) | $(GOBI @ echo "-> Installing terrafmt..." @ go install github.com/katbyte/terrafmt@$(VERSION_TERRAFMT) -# $(VERSION_DIR)/.version-tfproviderlint-$(VERSION_TFPROVIDERLINT): | $(VERSION_DIR) -# @ rm -f $(VERSION_DIR)/.version-tfproviderlint-* -# @ echo $(VERSION_TFPROVIDERLINT) > $(VERSION_DIR)/.version-tfproviderlint-$(VERSION_TFPROVIDERLINT) +$(VERSION_DIR)/.version-tfproviderlint-$(VERSION_TFPROVIDERLINT): | $(VERSION_DIR) + @ rm -f $(VERSION_DIR)/.version-tfproviderlint-* + @ echo $(VERSION_TFPROVIDERLINT) > $(VERSION_DIR)/.version-tfproviderlint-$(VERSION_TFPROVIDERLINT) -# $(GOBIN)/tfproviderlint: $(VERSION_DIR)/.version-tfproviderlint-$(VERSION_TFPROVIDERLINT) | $(GOBIN) -# @ echo "-> Installing tfproviderlint..." -# @ go install github.com/bflad/tfproviderlint/cmd/tfproviderlint@$(VERSION_TFPROVIDERLINT) +$(GOBIN)/tfproviderlint: $(VERSION_DIR)/.version-tfproviderlint-$(VERSION_TFPROVIDERLINT) | $(GOBIN) + @ echo "-> Installing tfproviderlint..." + @ go install github.com/bflad/tfproviderlint/cmd/tfproviderlint@$(VERSION_TFPROVIDERLINT) diff --git a/README.md b/README.md index ab6b8da..7423e6f 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ ## Requirements - [Terraform](https://www.terraform.io/downloads) 0.1.x and above, we recommend using the latest stable release whenever possible. When installing on an Illumos machine use the Solaris binary. -- [Go](https://go.dev/dl/) 1.19.x and above (to build the provider plugin) +- [Go](https://go.dev/dl/) 1.20.x and above (to build the provider plugin) ## Building the provider diff --git a/docs/resources/oxide_disk.md b/docs/resources/oxide_disk.md index 7370b35..fe2d8cd 100644 --- a/docs/resources/oxide_disk.md +++ b/docs/resources/oxide_disk.md @@ -12,19 +12,19 @@ This resource manages disks. ```hcl resource "oxide_disk" "example" { - project_id = "c1dee930-a8e4-11ed-afa1-0242ac120002" - description = "a test disk" - name = "mydisk" - size = 1073741824 - disk_source = { blank = 512 } + project_id = "c1dee930-a8e4-11ed-afa1-0242ac120002" + description = "a test disk" + name = "mydisk" + size = 1073741824 + disk_source = { blank = 512 } } resource "oxide_disk" "example2" { - project_id = "c1dee930-a8e4-11ed-afa1-0242ac120002" - description = "a test disk" - name = "mydisk2" - size = 1073741824 - disk_source = { global_image = "611bb17d-6883-45be-b3aa-8a186fdeafe8" } + project_id = "c1dee930-a8e4-11ed-afa1-0242ac120002" + description = "a test disk" + name = "mydisk2" + size = 1073741824 + disk_source = { global_image = "611bb17d-6883-45be-b3aa-8a186fdeafe8" } } ``` diff --git a/docs/resources/oxide_instance.md b/docs/resources/oxide_instance.md index 9b04bb9..d54a15c 100644 --- a/docs/resources/oxide_instance.md +++ b/docs/resources/oxide_instance.md @@ -14,12 +14,12 @@ This resource manages instances. ```hcl resource "oxide_instance" "example" { - project_id = "c1dee930-a8e4-11ed-afa1-0242ac120002" - description = "a test instance" - name = "myinstance" - host_name = "" - memory = 1073741824 - ncpus = 1 + project_id = "c1dee930-a8e4-11ed-afa1-0242ac120002" + description = "a test instance" + name = "myinstance" + host_name = "" + memory = 1073741824 + ncpus = 1 } ``` @@ -27,13 +27,13 @@ resource "oxide_instance" "example" { ```hcl resource "oxide_instance" "example" { - project_id = "c1dee930-a8e4-11ed-afa1-0242ac120002" - description = "a test instance" - name = "myinstance" - host_name = "" - memory = 1073741824 - ncpus = 1 - external_ips = ["myippool"] + project_id = "c1dee930-a8e4-11ed-afa1-0242ac120002" + description = "a test instance" + name = "myinstance" + host_name = "" + memory = 1073741824 + ncpus = 1 + external_ips = ["myippool"] } ``` @@ -41,13 +41,13 @@ resource "oxide_instance" "example" { ```hcl resource "oxide_instance" "example" { - project_id = "c1dee930-a8e4-11ed-afa1-0242ac120002" - description = "a test instance" - name = "myinstance" - host_name = "" - memory = 1073741824 - ncpus = 1 - attach_to_disks = ["disk1", "disk2"] + project_id = "c1dee930-a8e4-11ed-afa1-0242ac120002" + description = "a test instance" + name = "myinstance" + host_name = "" + memory = 1073741824 + ncpus = 1 + attach_to_disks = ["disk1", "disk2"] } ``` @@ -55,12 +55,12 @@ resource "oxide_instance" "example" { ```hcl resource "oxide_instance" "example" { - project_id = "c1dee930-a8e4-11ed-afa1-0242ac120002" - description = "a test instance" - name = "myinstance" - host_name = "" - memory = 1073741824 - ncpus = 1 + project_id = "c1dee930-a8e4-11ed-afa1-0242ac120002" + description = "a test instance" + name = "myinstance" + host_name = "" + memory = 1073741824 + ncpus = 1 network_interface = [ { description = "a network interface" diff --git a/docs/resources/oxide_ip_pool.md b/docs/resources/oxide_ip_pool.md index 35d273b..3c85843 100644 --- a/docs/resources/oxide_ip_pool.md +++ b/docs/resources/oxide_ip_pool.md @@ -12,13 +12,13 @@ This resource manages IP pools. ```hcl resource "oxide_ip_pool" "example" { - description = "a test ippool" - name = "myippool" + description = "a test ippool" + name = "myippool" ranges = [ { - first_address = "172.20.18.227" - last_address = "172.20.18.239" - } + first_address = "172.20.18.227" + last_address = "172.20.18.239" + } ] } ``` diff --git a/docs/resources/oxide_project.md b/docs/resources/oxide_project.md index 14534a5..02e66b9 100644 --- a/docs/resources/oxide_project.md +++ b/docs/resources/oxide_project.md @@ -10,8 +10,8 @@ This resource manages projects. ```hcl resource "oxide_project" "example" { - description = "a test project" - name = "myproject" + description = "a test project" + name = "myproject" } ``` diff --git a/docs/resources/oxide_vpc.md b/docs/resources/oxide_vpc.md index b16a08b..7f24347 100644 --- a/docs/resources/oxide_vpc.md +++ b/docs/resources/oxide_vpc.md @@ -10,11 +10,11 @@ This resource manages VPCs. ```hcl resource "oxide_vpc" "example" { - project_id = "c1dee930-a8e4-11ed-afa1-0242ac120002" - description = "a test vpc" - name = "myvpc" - dns_name = "my-vpc-dns" - ipv6_prefix = "fd1e:4947:d4a1::/48" + project_id = "c1dee930-a8e4-11ed-afa1-0242ac120002" + description = "a test vpc" + name = "myvpc" + dns_name = "my-vpc-dns" + ipv6_prefix = "fd1e:4947:d4a1::/48" } ``` diff --git a/go.mod b/go.mod index d462f55..0833945 100644 --- a/go.mod +++ b/go.mod @@ -8,11 +8,13 @@ require ( github.com/hashicorp/terraform-plugin-go v0.15.0 github.com/hashicorp/terraform-plugin-testing v1.2.0 github.com/oxidecomputer/oxide.go v0.0.22-0.20230411045251-335c1187c3bd + github.com/stretchr/testify v1.8.2 ) require ( github.com/agext/levenshtein v1.2.2 // indirect github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect github.com/fatih/color v1.13.0 // indirect github.com/golang/protobuf v1.5.2 // indirect github.com/google/go-cmp v0.5.9 // indirect @@ -44,6 +46,7 @@ require ( github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/mitchellh/reflectwalk v1.0.2 // indirect github.com/oklog/run v1.0.0 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect @@ -57,4 +60,5 @@ require ( google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f // indirect google.golang.org/grpc v1.54.0 // indirect google.golang.org/protobuf v1.30.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 304cb38..3038419 100644 --- a/go.sum +++ b/go.sum @@ -163,13 +163,18 @@ github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMB github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= +github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= github.com/vmihailenco/msgpack v4.0.4+incompatible h1:dSLoQfGFAo3F6OoNhwUmLwVgaUXK79GlxNBwueZn0xI= github.com/vmihailenco/msgpack v4.0.4+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= diff --git a/oxide/data_source_images_test.go b/oxide/data_source_images_test.go index 66de275..ad5a434 100644 --- a/oxide/data_source_images_test.go +++ b/oxide/data_source_images_test.go @@ -11,7 +11,7 @@ import ( ) // NB: The project must be populated with at least one image for this test to pass -func TestAccDataSourceImages(t *testing.T) { +func TestAccDataSourceImages_full(t *testing.T) { datasourceName := "data.oxide_images.test" resource.ParallelTest(t, resource.TestCase{ diff --git a/oxide/data_source_projects_test.go b/oxide/data_source_projects_test.go index 980f36e..400658e 100644 --- a/oxide/data_source_projects_test.go +++ b/oxide/data_source_projects_test.go @@ -10,7 +10,7 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" ) -func TestAccDataSourceProjects(t *testing.T) { +func TestAccDataSourceProjects_full(t *testing.T) { datasourceName := "data.oxide_projects.test" resource.ParallelTest(t, resource.TestCase{ diff --git a/oxide/provider.go b/oxide/provider.go index 37552c3..c5e0dfb 100644 --- a/oxide/provider.go +++ b/oxide/provider.go @@ -28,6 +28,7 @@ type oxideProviderModel struct { Token types.String `tfsdk:"token"` } +// New initialises a new provider func New(version string) provider.Provider { return &oxideProvider{ version: version, @@ -79,7 +80,7 @@ func (p *oxideProvider) Configure(ctx context.Context, req provider.ConfigureReq resp.Diagnostics.AddError( "Missing API Token Configuration", "While configuring the provider, the API token was not found in "+ - "the OXIDE_TOKEN environment variable or provider "+ + "the OXIDE_TOKEN environment variable or "+ "configuration block token attribute.", ) } @@ -88,7 +89,7 @@ func (p *oxideProvider) Configure(ctx context.Context, req provider.ConfigureReq resp.Diagnostics.AddError( "Missing Host Configuration", "While configuring the provider, the host was not found in "+ - "the OXIDE_HOST environment variable or provider "+ + "the OXIDE_HOST environment variable or "+ "configuration block host attribute.", ) } diff --git a/oxide/resource_disk.go b/oxide/resource_disk.go index 804aa22..8e89f8b 100644 --- a/oxide/resource_disk.go +++ b/oxide/resource_disk.go @@ -367,15 +367,18 @@ func newDiskSource(p diskResourceModel) (oxideSDK.DiskSource, error) { return ds, nil } -func waitForDetachedDisk(client *oxideSDK.Client, diskId oxideSDK.NameOrId, ch chan error) { +func waitForDetachedDisk(client *oxideSDK.Client, diskID oxideSDK.NameOrId, ch chan error) { for start := time.Now(); time.Since(start) < (5 * time.Second); { - resp, err := client.DiskView(oxideSDK.DiskViewParams{Disk: diskId}) + resp, err := client.DiskView(oxideSDK.DiskViewParams{Disk: diskID}) if err != nil { ch <- err } if resp.State.State == "detached" { break } + + // Ignoring linting error for now as this entire function will be removed + //lintignore:R018 time.Sleep(time.Second) } ch <- nil diff --git a/oxide/resource_disk_test.go b/oxide/resource_disk_test.go index d603e4f..b62b022 100644 --- a/oxide/resource_disk_test.go +++ b/oxide/resource_disk_test.go @@ -13,7 +13,7 @@ import ( oxideSDK "github.com/oxidecomputer/oxide.go/oxide" ) -func TestAccResourceDisk(t *testing.T) { +func TestAccResourceDisk_full(t *testing.T) { resourceName := "oxide_disk.test" resource.ParallelTest(t, resource.TestCase{ diff --git a/oxide/resource_image_test.go b/oxide/resource_image_test.go index 9b5d762..0e4e9a2 100644 --- a/oxide/resource_image_test.go +++ b/oxide/resource_image_test.go @@ -6,7 +6,7 @@ package oxide // TODO: Restore test when it is possible to delete a global image -// func TestAccResourceImage(t *testing.T) { +// func TestAccResourceImage_full(t *testing.T) { // resourceName := "oxide_image.test" // // resource.ParallelTest(t, resource.TestCase{ diff --git a/oxide/resource_instance_test.go b/oxide/resource_instance_test.go index 03dd0fd..d090593 100644 --- a/oxide/resource_instance_test.go +++ b/oxide/resource_instance_test.go @@ -13,7 +13,7 @@ import ( oxideSDK "github.com/oxidecomputer/oxide.go/oxide" ) -func TestAccResourceInstance(t *testing.T) { +func TestAccResourceInstance_full(t *testing.T) { resourceName := "oxide_instance.test" secondResourceName := "oxide_instance.test2" thirdResourceName := "oxide_instance.test3" diff --git a/oxide/resource_ip_pool_test.go b/oxide/resource_ip_pool_test.go index 442b779..ff9ac28 100644 --- a/oxide/resource_ip_pool_test.go +++ b/oxide/resource_ip_pool_test.go @@ -13,39 +13,39 @@ import ( "github.com/oxidecomputer/oxide.go/oxide" ) -func TestAccResourceIpPool(t *testing.T) { +func TestAccResourceIpPool_full(t *testing.T) { resourceName := "oxide_ip_pool.test" resourceName2 := "oxide_ip_pool.test2" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories(), - CheckDestroy: testAccIpPoolDestroy, + CheckDestroy: testAccIPPoolDestroy, Steps: []resource.TestStep{ { - Config: testResourceIpPoolConfig, - Check: checkResourceIpPool(resourceName), + Config: testResourceIPPoolConfig, + Check: checkResourceIPPool(resourceName), }, { - Config: testResourceIpPoolUpdateConfig, - Check: checkResourceIpPoolUpdate(resourceName), + Config: testResourceIPPoolUpdateConfig, + Check: checkResourceIPPoolUpdate(resourceName), }, { - Config: testResourceIpPoolRangesConfig, - Check: checkResourceIpPoolRanges(resourceName2), + Config: testResourceIPPoolRangesConfig, + Check: checkResourceIPPoolRanges(resourceName2), }, }, }) } -var testResourceIpPoolConfig = ` +var testResourceIPPoolConfig = ` resource "oxide_ip_pool" "test" { description = "a test ip_pool" name = "terraform-acc-myippool" } ` -func checkResourceIpPool(resourceName string) resource.TestCheckFunc { +func checkResourceIPPool(resourceName string) resource.TestCheckFunc { return resource.ComposeAggregateTestCheckFunc([]resource.TestCheckFunc{ resource.TestCheckResourceAttrSet(resourceName, "id"), resource.TestCheckResourceAttr(resourceName, "description", "a test ip_pool"), @@ -55,14 +55,14 @@ func checkResourceIpPool(resourceName string) resource.TestCheckFunc { }...) } -var testResourceIpPoolUpdateConfig = ` +var testResourceIPPoolUpdateConfig = ` resource "oxide_ip_pool" "test" { description = "a new description for ip_pool" name = "terraform-acc-myippool-new" } ` -func checkResourceIpPoolUpdate(resourceName string) resource.TestCheckFunc { +func checkResourceIPPoolUpdate(resourceName string) resource.TestCheckFunc { return resource.ComposeAggregateTestCheckFunc([]resource.TestCheckFunc{ resource.TestCheckResourceAttrSet(resourceName, "id"), resource.TestCheckResourceAttr(resourceName, "description", "a new description for ip_pool"), @@ -72,7 +72,7 @@ func checkResourceIpPoolUpdate(resourceName string) resource.TestCheckFunc { }...) } -var testResourceIpPoolRangesConfig = ` +var testResourceIPPoolRangesConfig = ` resource "oxide_ip_pool" "test2" { description = "a test ip_pool" name = "terraform-acc-myippool2" @@ -85,7 +85,7 @@ resource "oxide_ip_pool" "test2" { } ` -func checkResourceIpPoolRanges(resourceName string) resource.TestCheckFunc { +func checkResourceIPPoolRanges(resourceName string) resource.TestCheckFunc { return resource.ComposeAggregateTestCheckFunc([]resource.TestCheckFunc{ resource.TestCheckResourceAttrSet(resourceName, "id"), resource.TestCheckResourceAttr(resourceName, "description", "a test ip_pool"), @@ -99,7 +99,7 @@ func checkResourceIpPoolRanges(resourceName string) resource.TestCheckFunc { }...) } -func testAccIpPoolDestroy(s *terraform.State) error { +func testAccIPPoolDestroy(s *terraform.State) error { client, err := newTestClient() if err != nil { return err diff --git a/oxide/resource_project_test.go b/oxide/resource_project_test.go index 9699b61..de6e780 100644 --- a/oxide/resource_project_test.go +++ b/oxide/resource_project_test.go @@ -13,7 +13,7 @@ import ( oxideSDK "github.com/oxidecomputer/oxide.go/oxide" ) -func TestAccResourceProject(t *testing.T) { +func TestAccResourceProject_full(t *testing.T) { resourceName := "oxide_project.test" resource.ParallelTest(t, resource.TestCase{ diff --git a/oxide/resource_vpc_test.go b/oxide/resource_vpc_test.go index a88a6b4..ba006bf 100644 --- a/oxide/resource_vpc_test.go +++ b/oxide/resource_vpc_test.go @@ -13,7 +13,7 @@ import ( oxideSDK "github.com/oxidecomputer/oxide.go/oxide" ) -func TestAccResourceVPC(t *testing.T) { +func TestAccResourceVPC_full(t *testing.T) { resourceName := "oxide_vpc.test" resourceName2 := "oxide_vpc.test2" diff --git a/oxide/utils_test.go b/oxide/utils_test.go new file mode 100644 index 0000000..4b68b6f --- /dev/null +++ b/oxide/utils_test.go @@ -0,0 +1,77 @@ +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +package oxide + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func Test_isIPv4(t *testing.T) { + type args struct { + str string + } + tests := []struct { + name string + args args + want bool + }{ + { + name: "success", + args: args{"172.20.15.227"}, + want: true, + }, + { + name: "fail with IPv6", + args: args{"2001:0db8:3c4d:0015:0000:0000:1a2f:1a2b"}, + want: false, + }, + { + name: "fail with random input", + args: args{"totally-legit-ipv4"}, + want: false, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := isIPv4(tt.args.str) + assert.Equal(t, tt.want, got) + }) + } +} + +func Test_isIPv6(t *testing.T) { + type args struct { + str string + } + tests := []struct { + name string + args args + want bool + }{ + { + name: "success", + args: args{"2001:0db8:3c4d:0015:0000:0000:1a2f:1a2b"}, + want: true, + }, + { + name: "fail with IPv4", + args: args{"172.20.15.227"}, + want: false, + }, + { + name: "fail with random input", + args: args{"totally-legit-ipv6"}, + want: false, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := isIPv6(tt.args.str) + assert.Equal(t, tt.want, got) + }) + } +}