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

feat: acceptance tests | data source | network group assignment #93

Merged
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
58 changes: 58 additions & 0 deletions test/live/datasources/network_group_assignment_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package data_source_test

import (
"testing"

"github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/config"
"github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/provider"
"github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/util"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"
)

func TestNetworkGroupAssignmentDataSource(t *testing.T) {
const groupName = "tf_provider_acceptance_test_network_group_assignment_datasource"

resource.Test(t, resource.TestCase{
ProtoV6ProviderFactories: provider.TestAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
{
Config: provider.ProviderConfig + `
// create the resource to be used as a datasource
resource "uxi_group" "my_group" {
name = "` + groupName + `"
}

data "uxi_wired_network" "my_network" {
filter = {
wired_network_id = "` + config.WiredNetworkUid + `"
}
}

resource "uxi_network_group_assignment" "my_network_group_assignment" {
network_id = data.uxi_wired_network.my_network.id
group_id = uxi_group.my_group.id
}

// the actual datasource
data "uxi_network_group_assignment" "my_network_group_assignment" {
filter = {
network_group_assignment_id = uxi_network_group_assignment.my_network_group_assignment.id
}
}
`,
Check: resource.ComposeTestCheckFunc(
func(s *terraform.State) error {
resourceName := "uxi_network_group_assignment.my_network_group_assignment"
rs := s.RootModule().Resources[resourceName]
return util.CheckStateAgainstNetworkGroupAssignment(
t,
"data.uxi_network_group_assignment.my_network_group_assignment",
util.GetNetworkGroupAssignment(rs.Primary.ID),
)(s)
},
),
},
},
})
}
35 changes: 35 additions & 0 deletions test/live/util/network_group_assignment.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package util

import (
"context"

config_api_client "github.com/aruba-uxi/terraform-provider-hpeuxi/pkg/config-api-client"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/nbio/st"
)

func GetNetworkGroupAssignment(id string) config_api_client.NetworkGroupAssignmentsItem {
result, _, err := Client.ConfigurationAPI.
NetworkGroupAssignmentsGet(context.Background()).
Id(id).
Execute()
if err != nil {
panic(err)
}
if len(result.Items) != 1 {
panic("network_group_assignment with id `" + id + "` could not be found")
}
return result.Items[0]
}

func CheckStateAgainstNetworkGroupAssignment(
t st.Fatalf,
entity string,
networkGroupAssignment config_api_client.NetworkGroupAssignmentsItem,
) resource.TestCheckFunc {
return resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(entity, "id", networkGroupAssignment.Id),
resource.TestCheckResourceAttr(entity, "group_id", networkGroupAssignment.Group.Id),
resource.TestCheckResourceAttr(entity, "network_id", networkGroupAssignment.Network.Id),
)
}
Loading