diff --git a/test/live/config/config.go b/test/live/config/config.go index ddd9a23e..72bf0139 100644 --- a/test/live/config/config.go +++ b/test/live/config/config.go @@ -1,5 +1,6 @@ package config +const GroupUidRoot = "07422d227c0b" const WiredNetworkUid = "ethernet-0ee5b46c2ef0" const WiredNetworkName = "tf-provider-acceptance-tests-ethernet-0" const WirelessNetworkUid = "ssid-bf704ff37dc0" diff --git a/test/live/data-sources/group.go b/test/live/data-sources/group.go new file mode 100644 index 00000000..4b97ca62 --- /dev/null +++ b/test/live/data-sources/group.go @@ -0,0 +1,70 @@ +package data_source_test + +import ( + "regexp" + "testing" + + "github.com/aruba-uxi/terraform-provider-configuration/test/live/config" + "github.com/aruba-uxi/terraform-provider-configuration/test/live/util" + "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/provider" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/nbio/st" +) + +func TestGroupDataSource(t *testing.T) { + groupName := "tf_provider_acceptance_test_group_datasource" + + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: provider.TestAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: provider.ProviderConfig + ` + data "uxi_group" "my_group" { + filter = { + group_id = "` + config.GroupUidRoot + `" + } + } + `, + ExpectError: regexp.MustCompile(`The root group cannot be used as a data source`), + }, + { + Config: provider.ProviderConfig + ` + // create the resource to use subsequently as datasource + resource "uxi_group" "my_group_resource" { + name = "` + groupName + `" + } + + data "uxi_group" "my_group" { + filter = { + group_id = "uxi_group.my_group_resource.id" + } + } + `, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttrWith( + "data.uxi_group.my_group", + "id", + func(value string) error { + st.Assert(t, value, util.GetGroupByName(groupName).Id) + return nil + }, + ), + resource.TestCheckResourceAttr("data.uxi_group.my_group", "name", groupName), + resource.TestCheckResourceAttrWith( + "data.uxi_group.my_group", + "path", + func(value string) error { + st.Assert(t, value, util.GetGroupByName(groupName).Path) + return nil + }, + ), + resource.TestCheckResourceAttr( + "data.uxi_group.my_group", + "path", + config.GroupUidRoot, + ), + ), + }, + }, + }) +} diff --git a/test/live/resources/group_test.go b/test/live/resources/group_test.go index 4fe28540..eed4da5b 100644 --- a/test/live/resources/group_test.go +++ b/test/live/resources/group_test.go @@ -5,6 +5,7 @@ import ( "regexp" "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" @@ -14,8 +15,6 @@ type Fetcher interface { FetchData() ([]byte, error) } -var rootGroup = util.GetRoot() - func TestGroupResource(t *testing.T) { const groupNameParent = "tf_provider_acceptance_test_parent" const groupNameParentUpdated = groupNameParent + "_updated" @@ -186,7 +185,7 @@ func TestRootGroupResource(t *testing.T) { import { to = uxi_group.my_root_group - id = "` + rootGroup.Id + `" + id = "` + config.GroupUidRoot + `" }`, ExpectError: regexp.MustCompile(`The root group cannot be used as a resource`), }, diff --git a/test/live/util/util.go b/test/live/util/util.go index e866b77a..39d7bcfd 100644 --- a/test/live/util/util.go +++ b/test/live/util/util.go @@ -5,7 +5,6 @@ import ( "os" "github.com/aruba-uxi/terraform-provider-configuration-api/pkg/config-api-client" - resources_util "github.com/aruba-uxi/terraform-provider-configuration/internal/provider/util" "golang.org/x/oauth2" "golang.org/x/oauth2/clientcredentials" ) @@ -33,16 +32,6 @@ func NewClient() *config_api_client.APIClient { return config_api_client.NewAPIClient(uxiConfiguration) } -func GetRoot() *config_api_client.GroupsGetItem { - groups, _, _ := Client.ConfigurationAPI.GroupsGet(context.Background()).Execute() - for _, group := range groups.Items { - if resources_util.IsRoot(group) { - return &group - } - } - return nil -} - func GetGroupByName(name string) *config_api_client.GroupsGetItem { groups, _, _ := Client.ConfigurationAPI.GroupsGet(context.Background()).Execute() for _, group := range groups.Items {