Skip to content

Commit

Permalink
Fix retention_policy.schedule empty state
Browse files Browse the repository at this point in the history
 - Save empty string to the state when no schedule is given

Signed-off-by: Dmitry G <[email protected]>
  • Loading branch information
dmitry-g committed Sep 19, 2023
1 parent dba321d commit 5fb8b58
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
6 changes: 4 additions & 2 deletions provider/resource_retention_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,12 @@ func resolveScope(model models.Retention) interface{} {

func resolveSchedule(model models.Retention) string {
fmt, _ := client.GetSchedule(model.Trigger.Settings.Cron)
if fmt == "Custom" {
switch fmt {
case "Custom", "None":
return model.Trigger.Settings.Cron
default:
return fmt
}
return fmt
}

func resolveRules(model models.Retention) []interface{} {
Expand Down
44 changes: 42 additions & 2 deletions provider/resource_retention_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,22 @@ func TestAccRetentionUpdate(t *testing.T) {
resourceHarborRetentionMain, "rule.0.tag_matching", "latest"),
),
},
{
Config: testAccCheckRetentionScheduleNone(),
Check: resource.ComposeTestCheckFunc(
testAccCheckResourceExists(resourceHarborRetentionMain),
resource.TestCheckResourceAttr(
resourceHarborRetentionMain, "schedule", ""),
resource.TestCheckResourceAttr(
resourceHarborRetentionMain, "rule.0.n_days_since_last_pull", "5"),
resource.TestCheckResourceAttr(
resourceHarborRetentionMain, "rule.0.disabled", "false"),
resource.TestCheckResourceAttr(
resourceHarborRetentionMain, "rule.0.repo_matching", "**"),
resource.TestCheckResourceAttr(
resourceHarborRetentionMain, "rule.0.tag_matching", "latest"),
),
},
// {
// Config: testAccCheckLabelUpdate(),
// Check: resource.ComposeTestCheckFunc(
Expand Down Expand Up @@ -70,7 +86,7 @@ func testAccCheckRetentionBasic() string {
resource "harbor_project" "main" {
name = "acctest_retention_pol"
}
resource "harbor_retention_policy" "main" {
scope = harbor_project.main.id
schedule = "Daily"
Expand All @@ -84,7 +100,31 @@ func testAccCheckRetentionBasic() string {
repo_matching = "**"
tag_matching = "latest"
}
}
`)
}

func testAccCheckRetentionScheduleNone() string {
return fmt.Sprintf(`
resource "harbor_project" "main" {
name = "acctest_retention_pol"
}
resource "harbor_retention_policy" "main" {
scope = harbor_project.main.id
schedule = ""
rule {
n_days_since_last_pull = 5
repo_matching = "**"
tag_matching = "latest"
}
rule {
n_days_since_last_push = 10
repo_matching = "**"
tag_matching = "latest"
}
}
`)
}
Expand Down

0 comments on commit 5fb8b58

Please sign in to comment.