Skip to content

Commit

Permalink
Merge branch 'main' into ay/feat/acceptance-tests/sensor-group-assign…
Browse files Browse the repository at this point in the history
…ment
  • Loading branch information
1riatsila1 authored Nov 11, 2024
2 parents b7575bf + a2455c6 commit e6440bd
Showing 1 changed file with 113 additions and 0 deletions.
113 changes: 113 additions & 0 deletions test/live/resources/service_test_group_assignment_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package resource_test

import (
"testing"

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

func TestServiceTestGroupAssignmentResource(t *testing.T) {
const groupName = "tf_acceptance_test_service_test_group_assignment"
const group2Name = "tf_acceptance_test_service_test_group_assignment_two"

resource.Test(t, resource.TestCase{
ProtoV6ProviderFactories: provider.TestAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
// Creating a serviceTest group assignment
{
Config: provider.ProviderConfig + `
resource "uxi_group" "my_group" {
name = "` + groupName + `"
}
resource "uxi_service_test" "my_service_test" {
name = "` + config.ServiceTestName + `"
}
import {
to = uxi_service_test.my_service_test
id = "` + config.ServiceTestUid + `"
}
resource "uxi_service_test_group_assignment" "my_service_test_group_assignment" {
service_test_id = uxi_service_test.my_service_test.id
group_id = uxi_group.my_group.id
}`,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(
"uxi_service_test_group_assignment.my_service_test_group_assignment",
"service_test_id",
config.ServiceTestUid,
),
resource.TestCheckResourceAttrWith(
"uxi_service_test_group_assignment.my_service_test_group_assignment",
"group_id",
func(value string) error {
st.Assert(t, value, util.GetGroupByName(groupName).Id)
return nil
},
),
),
},
// ImportState testing
{
ResourceName: "uxi_service_test_group_assignment.my_service_test_group_assignment",
ImportState: true,
ImportStateVerify: true,
},
// Update and Read testing
{
Config: provider.ProviderConfig + `
// the original resources
resource "uxi_group" "my_group" {
name = "` + groupName + `"
}
resource "uxi_service_test" "my_service_test" {
name = "` + config.ServiceTestName + `"
}
// the new resources we wanna update the assignment to
resource "uxi_group" "my_group_2" {
name = "` + group2Name + `"
}
// the assignment update, updated from service_test/group to service_test/group_2
resource "uxi_service_test_group_assignment" "my_service_test_group_assignment" {
service_test_id = uxi_service_test.my_service_test.id
group_id = uxi_group.my_group_2.id
}`,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(
"uxi_service_test_group_assignment.my_service_test_group_assignment",
"service_test_id",
config.ServiceTestUid,
),
resource.TestCheckResourceAttrWith(
"uxi_service_test_group_assignment.my_service_test_group_assignment",
"group_id",
func(value string) error {
st.Assert(t, value, util.GetGroupByName(group2Name).Id)
return nil
},
),
),
},
// Remove serviceTests from state
{
Config: provider.ProviderConfig + `
removed {
from = uxi_service_test.my_service_test
lifecycle {
destroy = false
}
}`,
},
},
})
}

0 comments on commit e6440bd

Please sign in to comment.