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 test | resource | agent group assignment #100

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
2 changes: 1 addition & 1 deletion test/live/datasources/agent_group_assignment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestAgentGroupAssignmentDataSource(t *testing.T) {

resource "uxi_agent_group_assignment" "my_agent_group_assignment" {
agent_id = data.uxi_agent.my_agent.id
group_id = uxi_group.my_group.id
group_id = uxi_group.my_group.id
}

// the actual datasource
Expand Down
125 changes: 125 additions & 0 deletions test/live/resources/agent_group_assignment_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
package resource_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"
"github.com/nbio/st"
)

func TestAgentGroupAssignmentResource(t *testing.T) {
const groupName = "tf_provider_acceptance_test_agent_group_assignment_resource"
const group2Name = "tf_provider_acceptance_test_agent_group_assignment_resource_two"

resource.Test(t, resource.TestCase{
ProtoV6ProviderFactories: provider.TestAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
// Creating a agent group assignment
{
Config: provider.ProviderConfig + `
resource "uxi_group" "my_group" {
name = "` + groupName + `"
}

data "uxi_agent" "my_agent" {
filter = {
agent_id = "` + config.AgentPermanentUid + `"
}
}

resource "uxi_agent_group_assignment" "my_agent_group_assignment" {
agent_id = data.uxi_agent.my_agent.id
group_id = uxi_group.my_group.id
}`,
Check: resource.ComposeAggregateTestCheckFunc(
// Check properties are what we configured
resource.TestCheckResourceAttr(
"uxi_agent_group_assignment.my_agent_group_assignment",
"agent_id",
config.AgentPermanentUid,
),
resource.TestCheckResourceAttrWith(
"uxi_agent_group_assignment.my_agent_group_assignment",
"group_id",
func(value string) error {
st.Assert(t, util.GetGroupByName(groupName).Id, value)
return nil
},
),
// Check properties match what is on backend
func(s *terraform.State) error {
resourceName := "uxi_agent_group_assignment.my_agent_group_assignment"
rs := s.RootModule().Resources[resourceName]
return util.CheckStateAgainstAgentGroupAssignment(
t,
"uxi_agent_group_assignment.my_agent_group_assignment",
util.GetAgentGroupAssignment(rs.Primary.ID),
)(s)
},
),
},
// ImportState testing
{
ResourceName: "uxi_agent_group_assignment.my_agent_group_assignment",
ImportState: true,
ImportStateVerify: true,
},
// Update testing
{
Config: provider.ProviderConfig + `
// the original resources
resource "uxi_group" "my_group" {
name = "` + groupName + `"
}

data "uxi_agent" "my_agent" {
filter = {
agent_id = "` + config.AgentPermanentUid + `"
}
}

// the new resources we wanna update the assignment to
resource "uxi_group" "my_group_2" {
name = "` + group2Name + `"
}

// the assignment update, updated from agent/group to agent/group_2
resource "uxi_agent_group_assignment" "my_agent_group_assignment" {
agent_id = data.uxi_agent.my_agent.id
group_id = uxi_group.my_group_2.id
}`,
Check: resource.ComposeAggregateTestCheckFunc(
// Check properties are what we configured
resource.TestCheckResourceAttr(
"uxi_agent_group_assignment.my_agent_group_assignment",
"agent_id",
config.AgentPermanentUid,
),
resource.TestCheckResourceAttrWith(
"uxi_agent_group_assignment.my_agent_group_assignment",
"group_id",
func(value string) error {
st.Assert(t, util.GetGroupByName(group2Name).Id, value)
return nil
},
),
// Check properties match what is on backend
func(s *terraform.State) error {
resourceName := "uxi_agent_group_assignment.my_agent_group_assignment"
rs := s.RootModule().Resources[resourceName]
return util.CheckStateAgainstAgentGroupAssignment(
t,
"uxi_agent_group_assignment.my_agent_group_assignment",
util.GetAgentGroupAssignment(rs.Primary.ID),
)(s)
},
),
},
// Delete testing happens automatically
},
})
}
Loading