Skip to content

Commit

Permalink
test: added more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hjoshi123 committed Jan 12, 2025
1 parent 57b4735 commit 1488798
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 23 deletions.
35 changes: 25 additions & 10 deletions internal/service/eks/cluster_versions_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (d *dataSourceClusterVersions) Schema(ctx context.Context, req datasource.S
},
names.AttrStatus: schema.StringAttribute{
Optional: true,
CustomType: fwtypes.StringEnumType[awstypes.ClusterVersionStatus](),
CustomType: fwtypes.StringEnumType[clusterVersionAWSStatus](),
},
"cluster_versions": framework.DataSourceComputedListOfObjectAttribute[customDataSourceClusterVersion](ctx),
},
Expand Down Expand Up @@ -124,21 +124,36 @@ func findClusterVersions(ctx context.Context, conn *eks.Client, input *eks.Descr
return output, nil
}

type clusterVersionAWSStatus string

// Values returns all known values for ClusterVersionStatus. Note that this can be
// expanded in the future, and so it is only as up to date as the client.
//
// The ordering of this slice is not guaranteed to be stable across updates.
func (clusterVersionAWSStatus) Values() []clusterVersionAWSStatus {
return []clusterVersionAWSStatus{
"UNSUPPORTED",
"STANDARD_SUPPORT",
"EXTENDED_SUPPORT",
}
}

type dataSourceClusterVersionsModel struct {
ClusterType types.String `tfsdk:"cluster_type"`
DefaultOnly types.Bool `tfsdk:"default_only"`
ClusterVersionsOnly fwtypes.ListValueOf[types.String] `tfsdk:"cluster_versions_only"`
Status fwtypes.StringEnum[awstypes.ClusterVersionStatus] `tfsdk:"status"`
Status fwtypes.StringEnum[clusterVersionAWSStatus] `tfsdk:"status"`
ClusterVersions fwtypes.ListNestedObjectValueOf[customDataSourceClusterVersion] `tfsdk:"cluster_versions"`
}

type customDataSourceClusterVersion struct {
ClusterType types.String `tfsdk:"cluster_type"`
ClusterVersion types.String `tfsdk:"cluster_version"`
DefaultPlatformVersion types.String `tfsdk:"default_platform_version"`
EndOfExtendedSupportDate timetypes.RFC3339 `tfsdk:"end_of_extended_support_date"`
EndOfStandardSupportDate timetypes.RFC3339 `tfsdk:"end_of_standard_support_date"`
KubernetesPatchVersion types.String `tfsdk:"kubernetes_patch_version"`
ReleaseDate timetypes.RFC3339 `tfsdk:"release_date"`
Status fwtypes.StringEnum[awstypes.ClusterVersionStatus] `tfsdk:"status"`
ClusterType types.String `tfsdk:"cluster_type"`
ClusterVersion types.String `tfsdk:"cluster_version"`
DefaultPlatformVersion types.String `tfsdk:"default_platform_version"`
EndOfExtendedSupportDate timetypes.RFC3339 `tfsdk:"end_of_extended_support_date"`
EndOfStandardSupportDate timetypes.RFC3339 `tfsdk:"end_of_standard_support_date"`
KubernetesPatchVersion types.String `tfsdk:"kubernetes_patch_version"`
ReleaseDate timetypes.RFC3339 `tfsdk:"release_date"`
DefaultVersion types.Bool `tfsdk:"default_version"`
Status fwtypes.StringEnum[clusterVersionAWSStatus] `tfsdk:"status"`
}
48 changes: 35 additions & 13 deletions internal/service/eks/cluster_versions_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package eks_test
import (
"testing"

sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-provider-aws/internal/acctest"
"github.com/hashicorp/terraform-provider-aws/names"
Expand All @@ -15,19 +14,18 @@ import (
func TestAccEKSClusterVersionsDataSource_basic(t *testing.T) {
ctx := acctest.Context(t)

rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
dataSourceName := "data.aws_eks_cluster_versions.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, names.EKSServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckClusterDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccClusterVersionsDataSourceConfig_basic(rName),
Config: testAccClusterVersionsDataSourceConfig_basic(),
Check: resource.ComposeAggregateTestCheckFunc(
acctest.CheckResourceAttrGreaterThanValue(dataSourceName, "cluster_versions.#", 0),
acctest.CheckResourceAttrContains(dataSourceName, "cluster_versions.0.default_version", "true"),
),
},
},
Expand All @@ -37,17 +35,15 @@ func TestAccEKSClusterVersionsDataSource_basic(t *testing.T) {
func TestAccEKSClusterVersionsDataSource_clusterType(t *testing.T) {
ctx := acctest.Context(t)

rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
dataSourceName := "data.aws_eks_cluster_versions.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, names.EKSServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckClusterDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccClusterVersionsDataSourceConfig_clusterType(rName),
Config: testAccClusterVersionsDataSourceConfig_clusterType(),
Check: resource.ComposeTestCheckFunc(
acctest.CheckResourceAttrGreaterThanValue(dataSourceName, "cluster_versions.#", 0),
),
Expand All @@ -56,19 +52,45 @@ func TestAccEKSClusterVersionsDataSource_clusterType(t *testing.T) {
})
}

func testAccClusterVersionsDataSourceConfig_basic(rName string) string {
return acctest.ConfigCompose(testAccClusterConfig_basic(rName), `
func TestAccEKSClusterVersionsDataSource_defaultOnly(t *testing.T) {
ctx := acctest.Context(t)

dataSourceName := "data.aws_eks_cluster_versions.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, names.EKSServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccClusterVersionsDataSourceConfig_defaultOnly(),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(dataSourceName, "cluster_versions.#", "1"),
),
},
},
})
}

func testAccClusterVersionsDataSourceConfig_basic() string {
return acctest.ConfigCompose(`
data "aws_eks_cluster_versions" "test" {
depends_on = [aws_eks_cluster.test]
}
`)
}

func testAccClusterVersionsDataSourceConfig_clusterType(rName string) string {
return acctest.ConfigCompose(testAccClusterConfig_basic(rName), `
func testAccClusterVersionsDataSourceConfig_clusterType() string {
return acctest.ConfigCompose(`
data "aws_eks_cluster_versions" "test" {
cluster_type = "eks"
depends_on = [aws_eks_cluster.test]
}
`)
}

func testAccClusterVersionsDataSourceConfig_defaultOnly() string {
return acctest.ConfigCompose(`
data "aws_eks_cluster_versions" "test" {
default_only = true
}
`)
}

0 comments on commit 1488798

Please sign in to comment.