Skip to content

Commit

Permalink
feat: acceptance tests | groups data source
Browse files Browse the repository at this point in the history
  • Loading branch information
1riatsila1 committed Nov 11, 2024
1 parent ba7067a commit 8d5b969
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 14 deletions.
1 change: 1 addition & 0 deletions test/live/config/config.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
70 changes: 70 additions & 0 deletions test/live/data-sources/group.go
Original file line number Diff line number Diff line change
@@ -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,
),
),
},
},
})
}
5 changes: 2 additions & 3 deletions test/live/resources/group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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`),
},
Expand Down
11 changes: 0 additions & 11 deletions test/live/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 8d5b969

Please sign in to comment.