Skip to content

Disk acceptance tests #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 32 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
(echo; echo "Unexpected difference in directories after code generation. Run 'make generate' command and commit."; exit 1)

# Run acceptance tests in a matrix with Terraform CLI versions
test:
acceptance-test:
name: Terraform Provider Acceptance Tests
needs: build
runs-on: self-hosted
Expand Down Expand Up @@ -82,7 +82,7 @@ jobs:
# - '1.1.*'
# - '1.2.*'
# - '1.3.*'
- '1.4.*'
- '1.11.*'
steps:
- name: Debug info
run: |
Expand All @@ -107,11 +107,40 @@ jobs:
terraform_version: ${{ matrix.terraform }}
terraform_wrapper: false
- run: go mod download
- name: Check Acceptance Test Environment
run: |
set -o allexport; eval "$(echo "$CI_CONFIG_HC_IP205_dos" | tr -s '\r\n' '\n')"; set +o allexport;
set -a
. ./internal/provider/tests/acceptance/setup/env.txt
go run ./internal/provider/tests/acceptance/setup/acceptance_test_env_prepare.go
- env:
TF_ACC: "1"
run: |
set -o allexport; eval "$(echo "$CI_CONFIG_HC_IP205_dos" | tr -s '\r\n' '\n')"; set +o allexport;
echo cur-shell HC_HOST=$HC_HOST
sh -c 'echo sub-shell HC_HOST=$HC_HOST'
go test -v -cover ./internal/provider/
set -a
. ./internal/provider/tests/acceptance/setup/env.txt
go test -v -cover -coverpkg=github.com/hashicorp/terraform-provider-hypercore/internal/provider ./internal/provider/tests/acceptance/
timeout-minutes: 10
- name: Cleanup Acceptance Test Environment
if: always()
run: |
set -o allexport; eval "$(echo "$CI_CONFIG_HC_IP205_dos" | tr -s '\r\n' '\n')"; set +o allexport;
set -a
. ./internal/provider/tests/acceptance/setup/env.txt
go run ./internal/provider/tests/acceptance/setup/acceptance_test_env_prepare.go "cleanup"

unit-test:
name: Go Unit Tests
needs: build
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed
with:
go-version-file: 'go.mod'
cache: true
- name: Run Unit Tests
run: go test -v -cover -coverpkg=github.com/hashicorp/terraform-provider-hypercore/internal/provider ./internal/provider/tests/unit/
9 changes: 9 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,12 @@ Add needed variables/secrets to github project:
```

TEMP: create VM named `testtf-src`.

Prior to running acceptance tests we need to setup:
1. Virtual machine
a. has one disk
b. has one nic
c. boot order is configured as [disk, nic]
2. Virtual disk (as standalone not attached to the testing VM)
3. Add names and UUIDs to the env.txt file in /tests/acceptance/setup directory
4. Virtual machine needs to be powered off
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require (
github.com/hashicorp/terraform-plugin-go v0.25.0
github.com/hashicorp/terraform-plugin-log v0.9.0
github.com/hashicorp/terraform-plugin-testing v1.11.0
github.com/stretchr/testify v1.9.0
)

require (
Expand Down Expand Up @@ -67,4 +68,5 @@ require (
google.golang.org/grpc v1.67.1 // indirect
google.golang.org/protobuf v1.35.1 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package acceptance

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
)

func TestAccHypercoreDiskResource(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccHypercoreDiskResourceConfig(),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("hypercore_disk.test", "size", "3"),
resource.TestCheckResourceAttr("hypercore_disk.test", "type", "IDE_DISK"),
),
},
},
})
}

func testAccHypercoreDiskResourceConfig() string {
return fmt.Sprintf(`
data "hypercore_vm" "diskvm" {
name = %[1]q
}

resource "hypercore_disk" "test" {
vm_uuid = data.hypercore_vm.diskvm.vms.0.uuid
type = "IDE_DISK"
size = 3
}

output "vm_id" {
value = data.hypercore_vm.diskvm.vms.0.uuid
}
`, source_vm_name)
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package provider
package acceptance

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,35 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package provider
package acceptance

import (
"os"
"testing"

"github.com/hashicorp/terraform-plugin-framework/providerserver"
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
"github.com/hashicorp/terraform-provider-hypercore/internal/provider"
)

var source_vm_name = os.Getenv("SOURCE_VM_NAME")

/*
var existing_vdisk_uuid = os.Getenv("EXISTING_VDISK_UUID")
var source_nic_uuid = os.Getenv("SOURCE_NIC_UUID")
var source_disk_uuid = os.Getenv("SOURCE_DISK_UUID")
*/

// testAccProtoV6ProviderFactories are used to instantiate a provider during
// acceptance testing. The factory function will be invoked for every Terraform
// CLI command executed to create a provider server to which the CLI can
// reattach.
var testAccProtoV6ProviderFactories = map[string]func() (tfprotov6.ProviderServer, error){
"hypercore": providerserver.NewProtocol6WithError(New("test")()),
"hypercore": providerserver.NewProtocol6WithError(provider.New("test")()),
}

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

}
Loading
Loading