Skip to content
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

Imprv/issue#438 fc testcases #439

Merged
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
618 changes: 618 additions & 0 deletions client/fc/fc_service_test.go

Large diffs are not rendered by default.

44 changes: 44 additions & 0 deletions client/fc/fc_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package foundationcentral

import (
"testing"

"github.com/terraform-providers/terraform-provider-nutanix/client"
)

func TestNewFoundationCentralClient(t *testing.T) {
// verifies positive client creation
cred := client.Credentials{
URL: "foo.com",
Username: "username",
Password: "password",
Port: "",
Endpoint: "0.0.0.0",
Insecure: true,
FoundationEndpoint: "10.0.0.0",
FoundationPort: "8000",
RequiredFields: nil,
}
_, err := NewFoundationCentralClient(cred)
if err != nil {
t.Errorf(err.Error())
}

// verify missing client scenario
cred2 := client.Credentials{
URL: "foo.com",
Insecure: true,
RequiredFields: map[string][]string{
"prism_central": {"username", "password", "endpoint"},
"foundation_central": {"username", "password", "endpoint"},
},
}
FcClient2, err2 := NewFoundationCentralClient(cred2)
if err2 != nil {
t.Errorf(err2.Error())
}

if FcClient2.client.ErrorMsg == "" {
t.Errorf("NewFoundationCentralClient(%v) expected the base client in v3 client to have some error message", cred2)
}
}
62 changes: 62 additions & 0 deletions nutanix/data_source_nutanix_foundation_central_api_keys_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package nutanix

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccFCAPIKeysDataSource_basic(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccAPIKeysDataSourceConfig(),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("data.nutanix_foundation_central_list_api_keys.test", "api_keys.#"),
),
},
},
})
}

func TestAccFCAPIKeysDataSource_KeyUUID(t *testing.T) {
apiKeyName := acctest.RandomWithPrefix("test-key")
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccAPIKeysDataSourceConfigWithKeyUUID(apiKeyName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("data.nutanix_foundation_central_api_keys.k1", "alias", apiKeyName),
resource.TestCheckResourceAttrSet("data.nutanix_foundation_central_api_keys.k1", "alias"),
resource.TestCheckResourceAttrSet("data.nutanix_foundation_central_api_keys.k1", "created_timestamp"),
resource.TestCheckResourceAttrSet("data.nutanix_foundation_central_api_keys.k1", "current_time"),
),
},
},
})
}

func testAccAPIKeysDataSourceConfig() string {
return `
data "nutanix_foundation_central_list_api_keys" "test"{}
`
}

func testAccAPIKeysDataSourceConfigWithKeyUUID(apiKeyName string) string {
return fmt.Sprintf(`
resource "nutanix_foundation_central_api_keys" "apk"{
alias = "%s"
}

data "nutanix_foundation_central_api_keys" "k1"{
key_uuid = "${nutanix_foundation_central_api_keys.apk.key_uuid}"
}

`, apiKeyName)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package nutanix

import (
"testing"

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

func TestAccFCClusterDetailsDataSource_basic(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccFCClusterDetailsDataSourceConfig(),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("data.nutanix_foundation_central_imaged_clusters_list.cls", "imaged_clusters.#"),
),
},
},
})
}

func TestAccFCClusterDetailsDataSource_ClusterUUID(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccFCClusterDetailsDataSourceConfigWithUUID(),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("data.nutanix_foundation_central_imaged_clusters_list.cls", "imaged_clusters.#"),
resource.TestCheckResourceAttr("data.nutanix_foundation_central_cluster_details.k1", "storage_node_count", "0"),
resource.TestCheckResourceAttrSet("data.nutanix_foundation_central_cluster_details.k1", "imaged_cluster_uuid"),
),
},
},
})
}

func testAccFCClusterDetailsDataSourceConfig() string {
return `
data "nutanix_foundation_central_imaged_clusters_list" "cls" {}
`
}

func testAccFCClusterDetailsDataSourceConfigWithUUID() string {
return `
data "nutanix_foundation_central_imaged_clusters_list" "cls" {}

data "nutanix_foundation_central_cluster_details" "k1"{
imaged_cluster_uuid = "${data.nutanix_foundation_central_imaged_clusters_list.cls.imaged_clusters[0].imaged_cluster_uuid}"
}
`
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package nutanix

import (
"testing"

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

func TestAccFCClusterListDataSource_basic(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccFCClusterListDataSourceConfig(),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("data.nutanix_foundation_central_imaged_clusters_list.cls", "imaged_clusters.#"),
),
},
},
})
}

func testAccFCClusterListDataSourceConfig() string {
return `
data "nutanix_foundation_central_imaged_clusters_list" "cls" {}
`
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package nutanix

import (
"testing"

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

func TestAccFCNodeDetailsDataSource_basic(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccFCNodeDetailsDataSourceConfig(),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("data.nutanix_foundation_central_imaged_nodes_list.cls", "imaged_nodes.#"),
),
},
},
})
}

func TestAccFCNodeDetailsDataSource_NodeUUID(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccFCNodeDetailsDataSourceConfigWithUUID(),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("data.nutanix_foundation_central_imaged_nodes_list.cls", "imaged_nodes.#"),
resource.TestCheckResourceAttr("data.nutanix_foundation_central_imaged_node_details.k1", "cvm_vlan_id", "0"),
resource.TestCheckResourceAttrSet("data.nutanix_foundation_central_imaged_node_details.k1", "imaged_node_uuid"),
),
},
},
})
}

func testAccFCNodeDetailsDataSourceConfig() string {
return `
data "nutanix_foundation_central_imaged_nodes_list" "cls" {}
`
}

func testAccFCNodeDetailsDataSourceConfigWithUUID() string {
return `
data "nutanix_foundation_central_imaged_nodes_list" "cls" {}

data "nutanix_foundation_central_imaged_node_details" "k1"{
imaged_node_uuid = "${data.nutanix_foundation_central_imaged_nodes_list.cls.imaged_nodes[0].imaged_node_uuid}"
}
`
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package nutanix

import (
"testing"

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

func TestAccFCNodesListDataSource_basic(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccFCNodeListDataSourceConfig(),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("data.nutanix_foundation_central_imaged_nodes_list.cls", "imaged_nodes.#"),
),
},
},
})
}

func testAccFCNodeListDataSourceConfig() string {
return `
data "nutanix_foundation_central_imaged_nodes_list" "cls" {}
`
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package nutanix

import (
"testing"

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

func TestAccFCAPIKeysListDataSource_basic(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccAPIKeysListDataSourceConfig(),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("data.nutanix_foundation_central_list_api_keys.test", "api_keys.#"),
),
},
},
})
}

func testAccAPIKeysListDataSourceConfig() string {
return `
data "nutanix_foundation_central_list_api_keys" "test"{}
`
}
24 changes: 18 additions & 6 deletions nutanix/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type IPMIConfig struct {
IpmiIP string `json:"ipmi_ip"`
IpmiMac string `json:"ipmi_mac"`
}

type FoundationVars struct {
IPv6Addresses []string `json:"ipv6_addresses"`
IpmiConfig IPMIConfig `json:"ipmi_config"`
Expand All @@ -56,13 +57,24 @@ type FoundationVars struct {
NodePosition string `json:"node_position"`
IPv6Address string `json:"ipv6_address"`
CurrentNetworkInterface string `json:"current_network_interface"`
ImagedNodeUUID string `json:"imaged_node_uuid"`
HypervisorType string `json:"hypervisor_type"`
} `json:"nodes"`
BlockID string `json:"block_id"`
CvmGateway string `json:"cvm_gateway"`
HypervisorGateway string `json:"hypervisor_gateway"`
CvmNetmask string `json:"cvm_netmask"`
HypervisorNetmask string `json:"hypervisor_netmask"`
IpmiUser string `json:"ipmi_user"`
BlockID string `json:"block_id"`
CvmGateway string `json:"cvm_gateway"`
HypervisorGateway string `json:"hypervisor_gateway"`
CvmNetmask string `json:"cvm_netmask"`
HypervisorNetmask string `json:"hypervisor_netmask"`
IpmiUser string `json:"ipmi_user"`
AosPackageURL string `json:"aos_package_url"`
UseExistingNetworkSettings bool `json:"use_existing_network_settings"`
ImageNow bool `json:"image_now"`
CommonNetworkSettings struct {
CvmDNSServers []string `json:"cvm_dns_servers"`
HypervisorDNSServers []string `json:"hypervisor_dns_servers"`
CvmNtpServers []string `json:"cvm_ntp_servers"`
HypervisorNtpServers []string `json:"hypervisor_ntp_servers"`
} `json:"common_network_settings"`
} `json:"blocks"`
}

Expand Down
34 changes: 34 additions & 0 deletions nutanix/resource_nutanix_foundation_central_api_keys_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package nutanix

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccFCAPIKey_basic(t *testing.T) {
name := acctest.RandomWithPrefix("test-key")
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckNutanixAddressGroupDestroy,
Steps: []resource.TestStep{
{
Config: testAccFCAPIKeyConfig(name),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("nutanix_foundation_central_api_keys.test", "alias", name),
),
},
},
})
}

func testAccFCAPIKeyConfig(name string) string {
return fmt.Sprintf(`
resource "nutanix_foundation_central_api_keys" "test"{
alias = "%s"
}
`, name)
}
Loading