Skip to content

Commit

Permalink
move tests out
Browse files Browse the repository at this point in the history
Signed-off-by: GilTS <[email protected]>
  • Loading branch information
GilTeraSky committed Oct 4, 2023
1 parent 50b013f commit 8b16489
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Copyright © 2023 VMware, Inc. All Rights Reserved.
SPDX-License-Identifier: MPL-2.0
*/

package backupscheduletests
package backupschedule

import (
"testing"
Expand All @@ -16,7 +16,6 @@ import (

"github.com/vmware/terraform-provider-tanzu-mission-control/internal/authctx"
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/cluster"
backupscheduleres "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/cluster/backupschedule"
dataprotectionres "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/cluster/dataprotection"
commonscope "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/common/scope"
targetlocationres "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/targetlocation"
Expand All @@ -33,10 +32,10 @@ func initTestProvider(t *testing.T) *schema.Provider {
cluster.ResourceName: cluster.ResourceTMCCluster(),
targetlocationres.ResourceName: targetlocationres.ResourceTargetLocation(),
dataprotectionres.ResourceName: dataprotectionres.ResourceEnableDataProtection(),
backupscheduleres.ResourceName: backupscheduleres.ResourceBackupSchedule(),
ResourceName: ResourceBackupSchedule(),
},
DataSourcesMap: map[string]*schema.Resource{
backupscheduleres.ResourceName: backupscheduleres.DataSourceBackupSchedule(),
ResourceName: DataSourceBackupSchedule(),
},
ConfigureContextFunc: authctx.ProviderConfigureContext,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Copyright © 2023 VMware, Inc. All Rights Reserved.
SPDX-License-Identifier: MPL-2.0
*/

package backupscheduletests
package backupschedule

import (
"fmt"
Expand All @@ -21,7 +21,6 @@ import (
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/authctx"
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/client/proxy"
backupschedulemodels "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/cluster/backupschedule"
backupscheduleres "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/cluster/backupschedule"
testhelper "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/testing"
)

Expand Down Expand Up @@ -148,7 +147,7 @@ func verifyBackupScheduleDataSource(
return fmt.Errorf("ID not set, data source %s", dataSourceName)
}

firstTargetLocation := fmt.Sprintf("%s.0.%s", backupscheduleres.SchedulesKey, backupscheduleres.NameKey)
firstTargetLocation := fmt.Sprintf("%s.0.%s", SchedulesKey, NameKey)

if rs.Primary.Attributes[firstTargetLocation] != backupScheduleName {
return fmt.Errorf("target location wasn't found at index 0 (%s)", backupScheduleName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ Copyright © 2023 VMware, Inc. All Rights Reserved.
SPDX-License-Identifier: MPL-2.0
*/

package backupscheduletests
package backupschedule

import (
"fmt"

backupscheduleres "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/cluster/backupschedule"
commonscope "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/common/scope"
)

Expand All @@ -24,7 +23,7 @@ const (
)

var (
DataSourceFullName = fmt.Sprintf("data.%s.%s", backupscheduleres.ResourceName, DataSourceName)
DataSourceFullName = fmt.Sprintf("data.%s.%s", ResourceName, DataSourceName)
)

type DataSourceTFConfigBuilder struct {
Expand All @@ -41,7 +40,7 @@ func InitDataSourceTFConfigBuilder(scopeHelper *commonscope.ScopeHelperResources

tfConfigBuilder := &DataSourceTFConfigBuilder{
BackupScheduleRequiredResource: backupScheduleRequiredResource,
ClusterInfo: fmt.Sprintf("%s = \"%s\"", backupscheduleres.ClusterNameKey, scopeHelper.Cluster.Name),
ClusterInfo: fmt.Sprintf("%s = \"%s\"", ClusterNameKey, scopeHelper.Cluster.Name),
}

return tfConfigBuilder
Expand All @@ -61,7 +60,7 @@ func (builder *DataSourceTFConfigBuilder) GetDataSourceConfig() string {
}
`,
builder.BackupScheduleRequiredResource,
backupscheduleres.ResourceName,
ResourceName,
DataSourceName,
builder.ClusterInfo,
LabelsBackupScheduleName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@ Copyright © 2023 VMware, Inc. All Rights Reserved.
SPDX-License-Identifier: MPL-2.0
*/

package backupscheduletests
package backupschedule

import (
"fmt"
"strings"

clusterres "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/cluster"
backupscheduleres "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/cluster/backupschedule"
dataprotectiontests "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/cluster/dataprotection/tests"
dataprotectionres "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/cluster/dataprotection"
commonscope "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/common/scope"
targetlocationres "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/targetlocation"
targetlocationtests "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/targetlocation/tests"
)

type ResourceBuildMode string
Expand All @@ -38,9 +36,9 @@ const (
)

var (
FullClusterBackupScheduleResourceFullName = fmt.Sprintf("%s.%s", backupscheduleres.ResourceName, FullClusterBackupScheduleResourceName)
NamespacesBackupScheduleResourceFullName = fmt.Sprintf("%s.%s", backupscheduleres.ResourceName, NamespacesBackupScheduleResourceName)
LabelsBackupScheduleResourceFullName = fmt.Sprintf("%s.%s", backupscheduleres.ResourceName, LabelsBackupScheduleResourceName)
FullClusterBackupScheduleResourceFullName = fmt.Sprintf("%s.%s", ResourceName, FullClusterBackupScheduleResourceName)
NamespacesBackupScheduleResourceFullName = fmt.Sprintf("%s.%s", ResourceName, NamespacesBackupScheduleResourceName)
LabelsBackupScheduleResourceFullName = fmt.Sprintf("%s.%s", ResourceName, LabelsBackupScheduleResourceName)
)

type ResourceTFConfigBuilder struct {
Expand All @@ -58,17 +56,17 @@ func InitResourceTFConfigBuilder(scopeHelper *commonscope.ScopeHelperResources,

switch bMode {
case RsFullBuild:
dataProtectionConfigBuilder := dataprotectiontests.InitResourceTFConfigBuilder(scopeHelper, dataprotectiontests.RsFullBuild)
targetLocationConfigBuilder := targetlocationtests.InitResourceTFConfigBuilder(scopeHelper, targetlocationtests.RsClusterOnlyNoParentRs)
dataProtectionConfigBuilder := dataprotectionres.InitResourceTFConfigBuilder(scopeHelper, dataprotectionres.RsFullBuild)
targetLocationConfigBuilder := targetlocationres.InitResourceTFConfigBuilder(scopeHelper, targetlocationres.RsClusterOnlyNoParentRs)

dataProtectionRequiredResource = dataProtectionConfigBuilder.GetEnableDataProtectionConfig()
targetLocationRequiredResource = targetLocationConfigBuilder.GetTMCManagedTargetLocationConfig()
case RsDataProtectionParentRsOnly:
dataProtectionConfigBuilder := dataprotectiontests.InitResourceTFConfigBuilder(scopeHelper, dataprotectiontests.RsFullBuild)
dataProtectionConfigBuilder := dataprotectionres.InitResourceTFConfigBuilder(scopeHelper, dataprotectionres.RsFullBuild)

dataProtectionRequiredResource = dataProtectionConfigBuilder.GetEnableDataProtectionConfig()
case RsTargetLocationParentRsOnly:
targetLocationConfigBuilder := targetlocationtests.InitResourceTFConfigBuilder(scopeHelper, targetlocationtests.RsFullBuild)
targetLocationConfigBuilder := targetlocationres.InitResourceTFConfigBuilder(scopeHelper, targetlocationres.RsFullBuild)

targetLocationRequiredResource = targetLocationConfigBuilder.GetTMCManagedTargetLocationConfig()
}
Expand All @@ -81,11 +79,11 @@ func InitResourceTFConfigBuilder(scopeHelper *commonscope.ScopeHelperResources,
%s = %s
%s = %s
`,
backupscheduleres.ClusterNameKey, clusterName,
backupscheduleres.ManagementClusterNameKey, mgmtClusterName,
backupscheduleres.ProvisionerNameKey, provisionerName)
ClusterNameKey, clusterName,
ManagementClusterNameKey, mgmtClusterName,
ProvisionerNameKey, provisionerName)

targetLocationInfo := fmt.Sprintf("storage_location = %s.%s", targetlocationtests.TmcManagedResourceFullName, targetlocationres.NameKey)
targetLocationInfo := fmt.Sprintf("storage_location = %s.%s", targetlocationres.TmcManagedResourceFullName, targetlocationres.NameKey)

tfConfigBuilder := &ResourceTFConfigBuilder{
DataProtectionRequiredResource: strings.Trim(dataProtectionRequiredResource, " "),
Expand Down Expand Up @@ -134,14 +132,14 @@ func (builder *ResourceTFConfigBuilder) GetFullClusterBackupScheduleConfig() str
`,
builder.DataProtectionRequiredResource,
builder.TargetLocationRequiredResource,
backupscheduleres.ResourceName,
ResourceName,
FullClusterBackupScheduleResourceName,
FullClusterBackupScheduleName,
backupscheduleres.FullClusterBackupScope,
FullClusterBackupScope,
builder.ClusterInfo,
builder.TargetLocationInfo,
dataprotectiontests.EnableDataProtectionResourceFullName,
targetlocationtests.TmcManagedResourceFullName)
dataprotectionres.EnableDataProtectionResourceFullName,
targetlocationres.TmcManagedResourceFullName)
}

func (builder *ResourceTFConfigBuilder) GetNamespacesBackupScheduleConfig() string {
Expand Down Expand Up @@ -219,14 +217,14 @@ func (builder *ResourceTFConfigBuilder) GetNamespacesBackupScheduleConfig() stri
`,
builder.DataProtectionRequiredResource,
builder.TargetLocationRequiredResource,
backupscheduleres.ResourceName,
ResourceName,
NamespacesBackupScheduleResourceName,
NamespacesBackupScheduleName,
backupscheduleres.NamespacesBackupScope,
NamespacesBackupScope,
builder.ClusterInfo,
builder.TargetLocationInfo,
dataprotectiontests.EnableDataProtectionResourceFullName,
targetlocationtests.TmcManagedResourceFullName)
dataprotectionres.EnableDataProtectionResourceFullName,
targetlocationres.TmcManagedResourceFullName)
}

func (builder *ResourceTFConfigBuilder) GetLabelsBackupScheduleConfig() string {
Expand Down Expand Up @@ -268,12 +266,12 @@ func (builder *ResourceTFConfigBuilder) GetLabelsBackupScheduleConfig() string {
`,
builder.DataProtectionRequiredResource,
builder.TargetLocationRequiredResource,
backupscheduleres.ResourceName,
ResourceName,
LabelsBackupScheduleResourceName,
LabelsBackupScheduleName,
backupscheduleres.LabelSelectorBackupScope,
LabelSelectorBackupScope,
builder.ClusterInfo,
builder.TargetLocationInfo,
dataprotectiontests.EnableDataProtectionResourceFullName,
targetlocationtests.TmcManagedResourceFullName)
dataprotectionres.EnableDataProtectionResourceFullName,
targetlocationres.TmcManagedResourceFullName)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Copyright © 2023 VMware, Inc. All Rights Reserved.
SPDX-License-Identifier: MPL-2.0
*/

package dataprotectiontests
package dataprotection

import (
"testing"
Expand All @@ -16,7 +16,6 @@ import (

"github.com/vmware/terraform-provider-tanzu-mission-control/internal/authctx"
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/cluster"
dataprotectionres "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/cluster/dataprotection"
commonscope "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/common/scope"
)

Expand All @@ -28,8 +27,8 @@ func initTestProvider(t *testing.T) *schema.Provider {
testAccProvider := &schema.Provider{
Schema: authctx.ProviderAuthSchema(),
ResourcesMap: map[string]*schema.Resource{
dataprotectionres.ResourceName: dataprotectionres.ResourceEnableDataProtection(),
cluster.ResourceName: cluster.ResourceTMCCluster(),
ResourceName: ResourceEnableDataProtection(),
cluster.ResourceName: cluster.ResourceTMCCluster(),
},
ConfigureContextFunc: authctx.ProviderConfigureContext,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Copyright © 2023 VMware, Inc. All Rights Reserved.
SPDX-License-Identifier: MPL-2.0
*/

package dataprotectiontests
package dataprotection

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ Copyright © 2023 VMware, Inc. All Rights Reserved.
SPDX-License-Identifier: MPL-2.0
*/

package dataprotectiontests
package dataprotection

import (
"fmt"
"strings"

clusterres "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/cluster"
dataprotectionres "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/cluster/dataprotection"
commonscope "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/common/scope"
)

Expand All @@ -19,7 +18,7 @@ const (
)

var (
EnableDataProtectionResourceFullName = fmt.Sprintf("%s.%s", dataprotectionres.ResourceName, EnableDataProtectionResourceName)
EnableDataProtectionResourceFullName = fmt.Sprintf("%s.%s", ResourceName, EnableDataProtectionResourceName)
)

type ResourceBuildMode string
Expand Down Expand Up @@ -49,9 +48,9 @@ func InitResourceTFConfigBuilder(scopeHelper *commonscope.ScopeHelperResources,
%s = %s
%s = %s
`,
dataprotectionres.ClusterNameKey, clusterName,
dataprotectionres.ManagementClusterNameKey, mgmtClusterName,
dataprotectionres.ProvisionerNameKey, provisionerName)
ClusterNameKey, clusterName,
ManagementClusterNameKey, mgmtClusterName,
ProvisionerNameKey, provisionerName)

tfConfigBuilder := &ResourceTFConfigBuilder{
ClusterRequiredResource: strings.Trim(clusterRequiredResource, " "),
Expand All @@ -70,7 +69,7 @@ func (builder *ResourceTFConfigBuilder) GetEnableDataProtectionConfig() string {
}
`,
builder.ClusterRequiredResource,
dataprotectionres.ResourceName,
ResourceName,
EnableDataProtectionResourceName,
builder.ClusterInfo)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Copyright © 2023 VMware, Inc. All Rights Reserved.
SPDX-License-Identifier: MPL-2.0
*/

package targetlocationtests
package targetlocation

import (
"testing"
Expand All @@ -19,7 +19,6 @@ import (
dataprotectionres "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/cluster/dataprotection"
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/clustergroup"
commonscope "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/common/scope"
targetlocationres "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/targetlocation"
)

var (
Expand All @@ -30,13 +29,13 @@ func initTestProvider(t *testing.T) *schema.Provider {
testAccProvider := &schema.Provider{
Schema: authctx.ProviderAuthSchema(),
ResourcesMap: map[string]*schema.Resource{
targetlocationres.ResourceName: targetlocationres.ResourceTargetLocation(),
ResourceName: ResourceTargetLocation(),
dataprotectionres.ResourceName: dataprotectionres.ResourceEnableDataProtection(),
cluster.ResourceName: cluster.ResourceTMCCluster(),
clustergroup.ResourceName: clustergroup.ResourceClusterGroup(),
},
DataSourcesMap: map[string]*schema.Resource{
targetlocationres.ResourceName: targetlocationres.DataSourceTargetLocations(),
ResourceName: DataSourceTargetLocations(),
},
ConfigureContextFunc: authctx.ProviderConfigureContext,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Copyright © 2023 VMware, Inc. All Rights Reserved.
SPDX-License-Identifier: MPL-2.0
*/

package targetlocationtests
package targetlocation

import (
"fmt"
Expand All @@ -21,7 +21,6 @@ import (
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/authctx"
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/client/proxy"
targetlocationmodels "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/targetlocation"
targetlocationres "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/targetlocation"
testhelper "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/testing"
)

Expand Down Expand Up @@ -152,7 +151,7 @@ func verifyTargetLocationDataSource(
return fmt.Errorf("ID not set, data source %s", dataSourceName)
}

firstTargetLocation := fmt.Sprintf("%s.0.%s", targetlocationres.TargetLocationsKey, targetlocationres.NameKey)
firstTargetLocation := fmt.Sprintf("%s.0.%s", TargetLocationsKey, NameKey)

if rs.Primary.Attributes[firstTargetLocation] != targetLocationName {
return fmt.Errorf("target location wasn't found at index 0 (%s)", targetLocationName)
Expand Down
Loading

0 comments on commit 8b16489

Please sign in to comment.