-
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.
- Loading branch information
1 parent
439e10a
commit 002a307
Showing
16 changed files
with
2,189 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,90 @@ | ||
package data_source | ||
|
||
import ( | ||
"regexp" | ||
"testing" | ||
|
||
"github.com/aruba-uxi/configuration-api-terraform-provider/pkg/terraform-provider-configuration/test/provider" | ||
"github.com/aruba-uxi/configuration-api-terraform-provider/pkg/terraform-provider-configuration/test/util" | ||
"github.com/h2non/gock" | ||
"github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
) | ||
|
||
func TestGroupDataSource(t *testing.T) { | ||
defer gock.Off() | ||
mockOAuth := util.MockOAuth() | ||
|
||
resource.Test(t, resource.TestCase{ | ||
ProtoV6ProviderFactories: provider.TestAccProtoV6ProviderFactories, | ||
Steps: []resource.TestStep{ | ||
// Test no filters set | ||
{ | ||
Config: provider.ProviderConfig + ` | ||
data "uxi_group" "my_group" { | ||
filter = {} | ||
} | ||
`, | ||
ExpectError: regexp.MustCompile(`either filter.group_id must be set or 'filter.is_root = true' is required`), | ||
}, | ||
// Test too many filters set | ||
{ | ||
Config: provider.ProviderConfig + ` | ||
data "uxi_group" "my_group" { | ||
filter = { | ||
is_root = true | ||
group_id = "uid" | ||
} | ||
} | ||
`, | ||
ExpectError: regexp.MustCompile(`group_id and 'is_root = true' cannot both be set`), | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
resource.TestCheckResourceAttr("data.uxi_root_group.my_root_group", "id", "mock_uid"), | ||
), | ||
}, | ||
// Test Read, is_root not set | ||
{ | ||
PreConfig: func() { | ||
util.MockGetGroup( | ||
"uid", | ||
util.GenerateGroupPaginatedResponse([]map[string]interface{}{util.StructToMap(util.GenerateGroupResponseModel("uid", "", ""))}), | ||
3, | ||
) | ||
}, | ||
Config: provider.ProviderConfig + ` | ||
data "uxi_group" "my_group" { | ||
filter = { | ||
group_id = "uid" | ||
} | ||
} | ||
`, | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
resource.TestCheckResourceAttr("data.uxi_group.my_group", "id", "uid"), | ||
), | ||
}, | ||
// Test Read, is_root is false | ||
{ | ||
PreConfig: func() { | ||
util.MockGetGroup( | ||
"uid", | ||
util.GenerateGroupPaginatedResponse([]map[string]interface{}{util.StructToMap(util.GenerateGroupResponseModel("uid", "", ""))}), | ||
3, | ||
) | ||
}, | ||
Config: provider.ProviderConfig + ` | ||
data "uxi_group" "my_group" { | ||
filter = { | ||
is_root = false | ||
group_id = "uid" | ||
} | ||
} | ||
`, | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
resource.TestCheckResourceAttr("data.uxi_group.my_group", "id", "uid"), | ||
), | ||
}, | ||
// TODO: Test retrieving the root group | ||
}, | ||
}) | ||
|
||
mockOAuth.Mock.Disable() | ||
} |
46 changes: 46 additions & 0 deletions
46
pkg/config-api-provider/test/data-sources/sensor_group_assignment_test.go
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,46 @@ | ||
package data_source_test | ||
|
||
import ( | ||
"github.com/aruba-uxi/configuration-api-terraform-provider/pkg/terraform-provider-configuration/test/provider" | ||
"github.com/aruba-uxi/configuration-api-terraform-provider/pkg/terraform-provider-configuration/test/util" | ||
"github.com/h2non/gock" | ||
"github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
"testing" | ||
) | ||
|
||
func TestSensorGroupAssignmentDataSource(t *testing.T) { | ||
defer gock.Off() | ||
mockOAuth := util.MockOAuth() | ||
|
||
resource.Test(t, resource.TestCase{ | ||
ProtoV6ProviderFactories: provider.TestAccProtoV6ProviderFactories, | ||
Steps: []resource.TestStep{ | ||
// Read testing | ||
{ | ||
PreConfig: func() { | ||
util.MockGetSensorGroupAssignment( | ||
"uid", | ||
util.GenerateSensorGroupAssignmentPaginatedResponse([]map[string]interface{}{ | ||
util.StructToMap(util.GenerateSensorGroupAssignmentResponse("uid", "")), | ||
}), | ||
3, | ||
) | ||
}, | ||
Config: provider.ProviderConfig + ` | ||
data "uxi_sensor_group_assignment" "my_sensor_group_assignment" { | ||
filter = { | ||
sensor_group_assignment_id = "uid" | ||
} | ||
} | ||
`, | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
resource.TestCheckResourceAttr("data.uxi_sensor_group_assignment.my_sensor_group_assignment", "id", "uid"), | ||
resource.TestCheckResourceAttr("data.uxi_sensor_group_assignment.my_sensor_group_assignment", "group_id", "group_uid"), | ||
resource.TestCheckResourceAttr("data.uxi_sensor_group_assignment.my_sensor_group_assignment", "sensor_id", "sensor_uid"), | ||
), | ||
}, | ||
}, | ||
}) | ||
|
||
mockOAuth.Mock.Disable() | ||
} |
52 changes: 52 additions & 0 deletions
52
pkg/config-api-provider/test/data-sources/wired_group_test.go
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,52 @@ | ||
package data_source_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/aruba-uxi/configuration-api-terraform-provider/pkg/terraform-provider-configuration/test/provider" | ||
"github.com/aruba-uxi/configuration-api-terraform-provider/pkg/terraform-provider-configuration/test/util" | ||
|
||
"github.com/h2non/gock" | ||
"github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
) | ||
|
||
func TestWiredNetworkDataSource(t *testing.T) { | ||
defer gock.Off() | ||
mockOAuth := util.MockOAuth() | ||
|
||
resource.Test(t, resource.TestCase{ | ||
ProtoV6ProviderFactories: provider.TestAccProtoV6ProviderFactories, | ||
Steps: []resource.TestStep{ | ||
// Read testing | ||
{ | ||
PreConfig: func() { | ||
util.MockGetWiredNetwork( | ||
"uid", | ||
util.GenerateWiredNetworkPaginatedResponse([]map[string]interface{}{util.GenerateWiredNetworkResponse("uid", "")}), | ||
3, | ||
) | ||
}, | ||
Config: provider.ProviderConfig + ` | ||
data "uxi_wired_network" "my_wired_network" { | ||
filter = { | ||
wired_network_id = "uid" | ||
} | ||
} | ||
`, | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
resource.TestCheckResourceAttr("data.uxi_wired_network.my_wired_network", "id", "uid"), | ||
resource.TestCheckResourceAttr("data.uxi_wired_network.my_wired_network", "alias", "alias"), | ||
resource.TestCheckResourceAttr("data.uxi_wired_network.my_wired_network", "ip_version", "ip_version"), | ||
resource.TestCheckResourceAttr("data.uxi_wired_network.my_wired_network", "security", "security"), | ||
resource.TestCheckResourceAttr("data.uxi_wired_network.my_wired_network", "dns_lookup_domain", "dns_lookup_domain"), | ||
resource.TestCheckResourceAttr("data.uxi_wired_network.my_wired_network", "disable_edns", "false"), | ||
resource.TestCheckResourceAttr("data.uxi_wired_network.my_wired_network", "use_dns64", "false"), | ||
resource.TestCheckResourceAttr("data.uxi_wired_network.my_wired_network", "external_connectivity", "false"), | ||
resource.TestCheckResourceAttr("data.uxi_wired_network.my_wired_network", "vlan_id", "123"), | ||
), | ||
}, | ||
}, | ||
}) | ||
|
||
mockOAuth.Mock.Disable() | ||
} |
53 changes: 53 additions & 0 deletions
53
pkg/config-api-provider/test/data-sources/wireless_group_test.go
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,53 @@ | ||
package data_source_test | ||
|
||
import ( | ||
"github.com/aruba-uxi/configuration-api-terraform-provider/pkg/terraform-provider-configuration/test/provider" | ||
"github.com/aruba-uxi/configuration-api-terraform-provider/pkg/terraform-provider-configuration/test/util" | ||
"testing" | ||
|
||
"github.com/h2non/gock" | ||
"github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
) | ||
|
||
func TestWirelessNetworkDataSource(t *testing.T) { | ||
defer gock.Off() | ||
mockOAuth := util.MockOAuth() | ||
|
||
resource.Test(t, resource.TestCase{ | ||
ProtoV6ProviderFactories: provider.TestAccProtoV6ProviderFactories, | ||
Steps: []resource.TestStep{ | ||
// Read testing | ||
{ | ||
PreConfig: func() { | ||
util.MockGetWirelessNetwork( | ||
"uid", | ||
util.GenerateWirelessNetworkPaginatedResponse([]map[string]interface{}{util.GenerateWirelessNetworkResponse("uid", "")}), | ||
3, | ||
) | ||
}, | ||
Config: provider.ProviderConfig + ` | ||
data "uxi_wireless_network" "my_wireless_network" { | ||
filter = { | ||
wireless_network_id = "uid" | ||
} | ||
} | ||
`, | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
resource.TestCheckResourceAttr("data.uxi_wireless_network.my_wireless_network", "id", "uid"), | ||
resource.TestCheckResourceAttr("data.uxi_wireless_network.my_wireless_network", "ssid", "ssid"), | ||
resource.TestCheckResourceAttr("data.uxi_wireless_network.my_wireless_network", "alias", "alias"), | ||
resource.TestCheckResourceAttr("data.uxi_wireless_network.my_wireless_network", "ip_version", "ip_version"), | ||
resource.TestCheckResourceAttr("data.uxi_wireless_network.my_wireless_network", "security", "security"), | ||
resource.TestCheckResourceAttr("data.uxi_wireless_network.my_wireless_network", "hidden", "false"), | ||
resource.TestCheckResourceAttr("data.uxi_wireless_network.my_wireless_network", "band_locking", "band_locking"), | ||
resource.TestCheckResourceAttr("data.uxi_wireless_network.my_wireless_network", "dns_lookup_domain", "dns_lookup_domain"), | ||
resource.TestCheckResourceAttr("data.uxi_wireless_network.my_wireless_network", "disable_edns", "false"), | ||
resource.TestCheckResourceAttr("data.uxi_wireless_network.my_wireless_network", "use_dns64", "false"), | ||
resource.TestCheckResourceAttr("data.uxi_wireless_network.my_wireless_network", "external_connectivity", "false"), | ||
), | ||
}, | ||
}, | ||
}) | ||
|
||
mockOAuth.Mock.Disable() | ||
} |
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,26 @@ | ||
package provider | ||
|
||
import ( | ||
"github.com/aruba-uxi/configuration-api-terraform-provider/pkg/terraform-provider-configuration/provider" | ||
"github.com/hashicorp/terraform-plugin-framework/providerserver" | ||
"github.com/hashicorp/terraform-plugin-go/tfprotov6" | ||
) | ||
|
||
const ( | ||
ProviderConfig = `provider "uxi" { | ||
host = "test.api.capenetworks.com" | ||
client_id = "client_id" | ||
client_secret = "client_secret" | ||
token_url = "https://test.sso.common.cloud.hpe.com/as/token.oauth2" | ||
}` | ||
) | ||
|
||
var ( | ||
// 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. | ||
TestAccProtoV6ProviderFactories = map[string]func() (tfprotov6.ProviderServer, error){ | ||
"uxi": providerserver.NewProtocol6WithError(provider.New("test")()), | ||
} | ||
) |
Oops, something went wrong.