-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Like other acceptance tests these can be run in 'real' or 'simulation' mode, however only the 'simuation' mode will pass currently due to API limitations.
- Loading branch information
1 parent
6187fc2
commit c25e644
Showing
5 changed files
with
174 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// (C) Copyright 2024 Hewlett Packard Enterprise Development LP | ||
//go:build simulation | ||
|
||
package server | ||
|
||
import ( | ||
"github.com/HewlettPackard/hpegl-pcbe-terraform-resources/internal/simulator" | ||
) | ||
|
||
func init() { | ||
simulator.Server() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{"systemId":"126fd201-9e6e-5e31-9ffb-a766265b1fd3","id":"697e8cbf-df7e-570c-a3c7-912d4ce8375a","generation":13259,"customerId":"bb20052ac81011ed895f7a6e2fba2c57","name":"16.182.105.217","resourceUri":"/private-cloud-business/v1beta1/systems/126fd201-9e6e-5e31-9ffb-a766265b1fd3/servers/697e8cbf-df7e-570c-a3c7-912d4ce8375a","serialNumber":"MXQ1220D7P","hypervisorHost":{"id":"530b1894-9bd0-5627-9362-565aff1e5cbd","name":"16.182.105.217","type":"HYPERVISOR_TYPE_ESXI","ResourceUri":"/api/v1/hypervisor-hosts/530b1894-9bd0-5627-9362-565aff1e5cbd","hypervisorHostIp":"16.182.105.217","hypervisorClusterName":"5305-CL","hypervisorClusterId":"acd4daea-e5e3-5f35-8be3-ce4a4b6d946c"},"health":{"biosOrHardwareHealth":"OK","fanHealth":"OK","memoryHealth":"OK","networkHealth":"OK","overallServerHealth":"WARNING","powerSuppliesHealth":"CRITICAL","processorHealth":"OK","smartStorageBatteryHealth":"","storageHealth":"OK","temperaturesHealth":"OK","fanRedundancy":"REDUNDANT","powerSuppliesRedundancy":"NONREDUNDANT","agentlessManagementService":"READY","hbLastUpdateTimestamp":"Wed Jul 17 11:01:03 2024","powerState":""},"powerState":"ON","iloNetworkInfo":{"iloHostname":"16.182.105.216","iloIp":"16.182.105.216","network":"","subnetMask":"255.255.248.0","gateway":"16.182.104.1"},"iloState":"ENABLED","iloStatus":"OK","indicatorLedStatus":"OFF","iloFirmwareVersion":"iLO 5 v2.72","model":"ProLiant DL325 Gen10 Plus v2","memoryGib":"512","processorCount":"1","processorModel":"AMD EPYC 7413 24-Core Processor ","ncmVersion":"7.0.2-700014","onPremUniqueID":"34383350-3137-584d-5131-323230443750","onPremAgentId":"AF-836032","cloudModuleConfig":null,"consumedBy":null,"operatingSystemInfo":null,"linkLocalInfo":null,"gpus":null} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// (C) Copyright 2024 Hewlett Packard Enterprise Development LP | ||
|
||
package simulator | ||
|
||
import ( | ||
_ "embed" | ||
|
||
"github.com/h2non/gock" | ||
) | ||
|
||
// TODO: (API) Replace fake data with real data when possible | ||
// | ||
//go:embed fixtures/servers/create/get.json | ||
var serverGet string | ||
|
||
func simulateServerCreate() { | ||
systemID := "126fd201-9e6e-5e31-9ffb-a766265b1fd3" | ||
serverID := "697e8cbf-df7e-570c-a3c7-912d4ce8375a" | ||
|
||
gock.New("http://localhost"). | ||
Get("/private-cloud-business/v1beta1/systems/"+ | ||
systemID+"/servers/"+serverID). | ||
Reply(200). | ||
SetHeader("Content-Type", "application/json"). | ||
BodyString(serverGet) | ||
} | ||
|
||
func Server() { | ||
simulateServerCreate() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
// (C) Copyright 2024 Hewlett Packard Enterprise Development LP | ||
|
||
package acceptance | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/HewlettPackard/hpegl-pcbe-terraform-resources/internal/provider" | ||
"github.com/google/uuid" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework/providerserver" | ||
"github.com/hashicorp/terraform-plugin-go/tfprotov6" | ||
"github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-testing/terraform" | ||
) | ||
|
||
const ( | ||
providerConfig = ` | ||
terraform { | ||
required_providers { | ||
hpegl = { | ||
source = "github.com/HewlettPackard/hpegl-pcbe-terraform-resources" | ||
} | ||
} | ||
} | ||
provider "hpegl" { | ||
pc { | ||
host = "http://localhost:8080" | ||
token = "abcdefghijklmnopqrstuvwxyz-0123456789" | ||
http_dump = true | ||
poll_interval = 0.001 | ||
max_polls = 10 | ||
} | ||
} | ||
` | ||
) | ||
|
||
var simulation = false | ||
|
||
var testAccProtoV6ProviderFactories = map[string]func() ( | ||
tfprotov6.ProviderServer, error, | ||
){ | ||
"scaffolding": providerserver.NewProtocol6WithError( | ||
provider.New("test")(), | ||
), | ||
} | ||
|
||
func checkUUIDAttr(resource string, attr string) func(*terraform.State) error { | ||
return func(s *terraform.State) error { | ||
rs, ok := s.RootModule().Resources[resource] | ||
if !ok { | ||
return fmt.Errorf("resource not found: %s", resource) | ||
} | ||
|
||
attrValue := rs.Primary.Attributes[attr] | ||
_, err := uuid.Parse(attrValue) | ||
|
||
return err | ||
} | ||
} | ||
|
||
func TestAccServerResource(t *testing.T) { | ||
config := providerConfig + ` | ||
resource "hpegl_pc_server" "test" { | ||
name = "16.182.105.217" | ||
system_id = "126fd201-9e6e-5e31-9ffb-a766265b1fd3" | ||
} | ||
` | ||
|
||
checks := []resource.TestCheckFunc{ | ||
resource.TestCheckResourceAttr( | ||
"hpegl_pc_server.test", | ||
"name", | ||
"16.182.105.217", | ||
), | ||
checkUUIDAttr("hpegl_pc_server.test", "id"), | ||
checkUUIDAttr("hpegl_pc_server.test", "system_id"), | ||
} | ||
|
||
if simulation { | ||
checks = append(checks, | ||
resource.TestCheckResourceAttr( | ||
"hpegl_pc_server.test", | ||
"id", | ||
"697e8cbf-df7e-570c-a3c7-912d4ce8375a", | ||
), | ||
resource.TestCheckResourceAttr( | ||
"hpegl_pc_server.test", | ||
"system_id", | ||
"126fd201-9e6e-5e31-9ffb-a766265b1fd3", | ||
), | ||
) | ||
} | ||
|
||
checkFn := resource.ComposeAggregateTestCheckFunc(checks...) | ||
|
||
resource.Test(t, resource.TestCase{ | ||
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: config, | ||
Check: checkFn, | ||
PlanOnly: true, | ||
ExpectNonEmptyPlan: true, | ||
}, | ||
{ | ||
Config: config, | ||
Check: checkFn, | ||
}, | ||
{ | ||
Config: config, | ||
Check: checkFn, | ||
PlanOnly: true, | ||
ExpectNonEmptyPlan: false, | ||
}, | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// (C) Copyright 2024 Hewlett Packard Enterprise Development LP | ||
//go:build simulation | ||
// +build simulation | ||
|
||
package acceptance | ||
|
||
func init() { | ||
simulation = true | ||
} |