Skip to content

Commit

Permalink
fixed flattten and unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
SivaanandM committed Dec 25, 2024
1 parent ed31044 commit 2743265
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 20 deletions.
9 changes: 8 additions & 1 deletion spectrocloud/cluster_common_policies.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,19 @@ func flattenBackupPolicy(policy *models.V1ClusterBackupConfig) []interface{} {
data["namespaces"] = policy.Namespaces
data["expiry_in_hour"] = policy.DurationInHours
data["include_disks"] = policy.IncludeAllDisks
data["include_cluster_resources"] = policy.IncludeClusterResources
data["include_cluster_resources"] = flattenIncludeResourceMode(policy.IncludeClusterResourceMode)
data["include_cluster_resources_mode"] = policy.IncludeClusterResourceMode
result = append(result, data)
return result
}

func flattenIncludeResourceMode(m models.V1IncludeClusterResourceMode) bool {
if m == models.V1IncludeClusterResourceMode("Always") {

Check failure on line 90 in spectrocloud/cluster_common_policies.go

View workflow job for this annotation

GitHub Actions / build-with-coverage

S1008: should use 'return m == models.V1IncludeClusterResourceMode("Always")' instead of 'if m == models.V1IncludeClusterResourceMode("Always") { return true }; return false' (gosimple)
return true
}
return false
}

func updateBackupPolicy(c *client.V1Client, d *schema.ResourceData) error {
if policy := toBackupPolicy(d); policy != nil {
//clusterContext := d.Get("context").(string)
Expand Down
41 changes: 22 additions & 19 deletions spectrocloud/cluster_policies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,14 @@ func TestFlattenBackupPolicy(t *testing.T) {

expected := []interface{}{
map[string]interface{}{
"schedule": "daily",
"backup_location_id": "location-123",
"prefix": "backup-prefix",
"namespaces": []string{"namespace1", "namespace2"},
"expiry_in_hour": int64(24),
"include_disks": true,
"include_cluster_resources": true,
"schedule": "daily",
"backup_location_id": "location-123",
"prefix": "backup-prefix",
"namespaces": []string{"namespace1", "namespace2"},
"expiry_in_hour": int64(24),
"include_disks": true,
"include_cluster_resources": false,
"include_cluster_resources_mode": models.V1IncludeClusterResourceMode(""),
},
}

Expand Down Expand Up @@ -112,12 +113,13 @@ func TestToBackupPolicy(t *testing.T) {
result := toBackupPolicy(resourceData)

expected := &models.V1ClusterBackupConfig{
BackupLocationUID: "location-123",
BackupPrefix: "backup-prefix",
DurationInHours: 24,
IncludeAllDisks: true,
IncludeClusterResources: true,
Namespaces: []string{"namespace1"},
BackupLocationUID: "location-123",
BackupPrefix: "backup-prefix",
DurationInHours: 24,
IncludeAllDisks: true,
IncludeClusterResources: false,
IncludeClusterResourceMode: models.V1IncludeClusterResourceMode("Always"),
Namespaces: []string{"namespace1"},
Schedule: &models.V1ClusterFeatureSchedule{
ScheduledRunTime: "daily",
},
Expand Down Expand Up @@ -192,12 +194,13 @@ func TestToPolicies(t *testing.T) {

expected := &models.V1SpectroClusterPolicies{
BackupPolicy: &models.V1ClusterBackupConfig{
BackupLocationUID: "location-123",
BackupPrefix: "backup-prefix",
DurationInHours: 24,
IncludeAllDisks: true,
IncludeClusterResources: true,
Namespaces: []string{"namespace1"},
BackupLocationUID: "location-123",
BackupPrefix: "backup-prefix",
DurationInHours: 24,
IncludeAllDisks: true,
IncludeClusterResources: false,
IncludeClusterResourceMode: models.V1IncludeClusterResourceMode("Always"),
Namespaces: []string{"namespace1"},
Schedule: &models.V1ClusterFeatureSchedule{
ScheduledRunTime: "daily",
},
Expand Down

0 comments on commit 2743265

Please sign in to comment.