Skip to content

Commit 98f2c25

Browse files
committed
CI/CD configuration
- added Unit tests to workflow - added template unit test - bumped Terraform test version to v1.11 - added necessary mods to mod.go - added testing environment prepare/cleanup/check script - altered workflow file to run check and cleanup script with acceptance tests
1 parent 359bd6b commit 98f2c25

File tree

8 files changed

+401
-9
lines changed

8 files changed

+401
-9
lines changed

.github/workflows/test.yml

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
(echo; echo "Unexpected difference in directories after code generation. Run 'make generate' command and commit."; exit 1)
5454
5555
# Run acceptance tests in a matrix with Terraform CLI versions
56-
test:
56+
acceptance-test:
5757
name: Terraform Provider Acceptance Tests
5858
needs: build
5959
runs-on: self-hosted
@@ -82,7 +82,7 @@ jobs:
8282
# - '1.1.*'
8383
# - '1.2.*'
8484
# - '1.3.*'
85-
- '1.4.*'
85+
- '1.11.*'
8686
steps:
8787
- name: Debug info
8888
run: |
@@ -107,11 +107,40 @@ jobs:
107107
terraform_version: ${{ matrix.terraform }}
108108
terraform_wrapper: false
109109
- run: go mod download
110+
- name: Check Acceptance Test Environment
111+
run: |
112+
set -o allexport; eval "$(echo "$CI_CONFIG_HC_IP205_dos" | tr -s '\r\n' '\n')"; set +o allexport;
113+
set -a
114+
. ./internal/provider/tests/acceptance/setup/env.txt
115+
go run ./internal/provider/tests/acceptance/setup/acceptance_test_env_prepare.go
110116
- env:
111117
TF_ACC: "1"
112118
run: |
113119
set -o allexport; eval "$(echo "$CI_CONFIG_HC_IP205_dos" | tr -s '\r\n' '\n')"; set +o allexport;
114120
echo cur-shell HC_HOST=$HC_HOST
115121
sh -c 'echo sub-shell HC_HOST=$HC_HOST'
116-
go test -v -cover ./internal/provider/
122+
set -a
123+
. ./internal/provider/tests/acceptance/setup/env.txt
124+
go test -v -cover -coverpkg=github.com/hashicorp/terraform-provider-hypercore/internal/provider ./internal/provider/tests/acceptance/
117125
timeout-minutes: 10
126+
- name: Cleanup Acceptance Test Environment
127+
if: always()
128+
run: |
129+
set -o allexport; eval "$(echo "$CI_CONFIG_HC_IP205_dos" | tr -s '\r\n' '\n')"; set +o allexport;
130+
set -a
131+
. ./internal/provider/tests/acceptance/setup/env.txt
132+
go run ./internal/provider/tests/acceptance/setup/acceptance_test_env_prepare.go "cleanup"
133+
134+
unit-test:
135+
name: Go Unit Tests
136+
needs: build
137+
runs-on: ubuntu-latest
138+
timeout-minutes: 10
139+
steps:
140+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
141+
- uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed
142+
with:
143+
go-version-file: 'go.mod'
144+
cache: true
145+
- name: Run Unit Tests
146+
run: go test -v -cover -coverpkg=github.com/hashicorp/terraform-provider-hypercore/internal/provider ./internal/provider/tests/unit/

DEVELOPMENT.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,12 @@ Add needed variables/secrets to github project:
2323
```
2424

2525
TEMP: create VM named `testtf-src`.
26+
27+
Prior to running acceptance tests we need to setup:
28+
1. Virtual machine
29+
a. has one disk
30+
b. has one nic
31+
c. boot order is configured as [disk, nic]
32+
2. Virtual disk (as standalone not attached to the testing VM)
33+
3. Add names and UUIDs to the env.txt file in /tests/acceptance/setup directory
34+
4. Virtual machine needs to be powered off

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ require (
99
github.com/hashicorp/terraform-plugin-go v0.25.0
1010
github.com/hashicorp/terraform-plugin-log v0.9.0
1111
github.com/hashicorp/terraform-plugin-testing v1.11.0
12+
github.com/stretchr/testify v1.9.0
1213
)
1314

1415
require (
@@ -67,4 +68,5 @@ require (
6768
google.golang.org/grpc v1.67.1 // indirect
6869
google.golang.org/protobuf v1.35.1 // indirect
6970
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
71+
gopkg.in/yaml.v3 v3.0.1 // indirect
7072
)

internal/provider/hypercore_vm_resource_test.go renamed to internal/provider/tests/acceptance/hypercore_vm_resource_acc_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) HashiCorp, Inc.
22
// SPDX-License-Identifier: MPL-2.0
33

4-
package provider
4+
package acceptance
55

66
import (
77
"fmt"
Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,33 @@
11
// Copyright (c) HashiCorp, Inc.
22
// SPDX-License-Identifier: MPL-2.0
33

4-
package provider
4+
package acceptance
55

66
import (
77
"testing"
88

99
"github.com/hashicorp/terraform-plugin-framework/providerserver"
1010
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
11+
"github.com/hashicorp/terraform-provider-hypercore/internal/provider"
1112
)
1213

14+
/*
15+
var source_vm_name = os.Getenv("SOURCE_VM_NAME")
16+
var existing_vdisk_uuid = os.Getenv("EXISTING_VDISK_UUID")
17+
var source_nic_uuid = os.Getenv("SOURCE_NIC_UUID")
18+
var source_disk_uuid = os.Getenv("SOURCE_DISK_UUID")
19+
*/
20+
1321
// testAccProtoV6ProviderFactories are used to instantiate a provider during
1422
// acceptance testing. The factory function will be invoked for every Terraform
1523
// CLI command executed to create a provider server to which the CLI can
1624
// reattach.
1725
var testAccProtoV6ProviderFactories = map[string]func() (tfprotov6.ProviderServer, error){
18-
"hypercore": providerserver.NewProtocol6WithError(New("test")()),
26+
"hypercore": providerserver.NewProtocol6WithError(provider.New("test")()),
1927
}
2028

2129
func testAccPreCheck(t *testing.T) {
22-
// You can add code here to run prior to any test case execution, for example assertions
23-
// about the appropriate environment variables being set are common to see in a pre-check
24-
// function.
30+
// Prechecks
31+
// Don't use terraform CRUD operations here, this is ran prior to the test and will not cleanup
32+
2533
}

0 commit comments

Comments
 (0)