Skip to content

Commit

Permalink
Merge pull request #234 from jfrog/gh-225-fix-missed-cache-period-sec…
Browse files Browse the repository at this point in the history
…onds-got-lost

GH-225 Fix missed_cache_period_seconds not being retained
  • Loading branch information
alexhung authored Dec 10, 2021
2 parents 3c3dabd + 01f52f9 commit 469b52c
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pkg/artifactory/repositories.go
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ func unpackBaseRemoteRepo(s *schema.ResourceData, packageType string) RemoteRepo
RetrievalCachePeriodSecs: d.getInt("retrieval_cache_period_seconds", true),
// Not returned in the GET
//FailedRetrievalCachePeriodSecs: d.getInt("failed_retrieval_cache_period_secs", true),
MissedRetrievalCachePeriodSecs: d.getInt("missed_cache_period_seconds", true),
MissedRetrievalCachePeriodSecs: d.getInt("missed_cache_period_seconds", false),
UnusedArtifactsCleanupEnabled: d.getBoolRef("unused_artifacts_cleanup_period_enabled", true),
UnusedArtifactsCleanupPeriodHours: d.getInt("unused_artifacts_cleanup_period_hours", true),
AssumedOfflinePeriodSecs: d.getInt("assumed_offline_period_secs", true),
Expand Down
2 changes: 1 addition & 1 deletion pkg/artifactory/resource_artifactory_remote_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ func unpackLegacyRemoteRepo(s *schema.ResourceData) (interface{}, string, error)
repo.IncludesPattern = d.getString("includes_pattern", true)
repo.LocalAddress = d.getString("local_address", true)
repo.MaxUniqueSnapshots = d.getInt("max_unique_snapshots", true)
repo.MissedRetrievalCachePeriodSecs = d.getInt("missed_cache_period_seconds", true)
repo.MissedRetrievalCachePeriodSecs = d.getInt("missed_cache_period_seconds", false)
repo.Notes = d.getString("notes", true)
repo.Offline = d.getBoolRef("offline", true)
repo.PackageType = d.getString("package_type", true)
Expand Down
66 changes: 63 additions & 3 deletions pkg/artifactory/resource_artifactory_remote_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,28 +70,32 @@ func TestAccRemoteDockerRepository(t *testing.T) {
"enable_token_authentication": true,
"block_pushing_schema1": true,
"external_dependencies_patterns": []interface{}{"**/hub.docker.io/**", "**/bintray.jfrog.io/**"},
"missed_cache_period_seconds": 1800, // https://github.com/jfrog/terraform-provider-artifactory/issues/225
})
resource.Test(t, testCase)
}

func TestAccRemoteCargoRepository(t *testing.T) {
_, testCase := mkNewRemoteTestCase("cargo", t, map[string]interface{}{
"git_registry_url": "https://github.com/rust-lang/foo.index",
"anonymous_access": true,
"git_registry_url": "https://github.com/rust-lang/foo.index",
"anonymous_access": true,
"missed_cache_period_seconds": 1800, // https://github.com/jfrog/terraform-provider-artifactory/issues/225
})
resource.Test(t, testCase)
}

func TestAccRemoteHelmRepository(t *testing.T) {
resource.Test(mkNewRemoteTestCase("helm", t, map[string]interface{}{
"helm_charts_base_url": "https://github.com/rust-lang/foo.index",
"helm_charts_base_url": "https://github.com/rust-lang/foo.index",
"missed_cache_period_seconds": 1800, // https://github.com/jfrog/terraform-provider-artifactory/issues/225
}))
}

func TestAccRemoteNpmRepository(t *testing.T) {
resource.Test(mkNewRemoteTestCase("npm", t, map[string]interface{}{
"list_remote_folder_items": true,
"mismatching_mime_types_override_list": "application/json,application/xml",
"missed_cache_period_seconds": 1800, // https://github.com/jfrog/terraform-provider-artifactory/issues/225
}))
}

Expand Down Expand Up @@ -458,3 +462,59 @@ func TestAccRemoteRepository_generic_with_propagate(t *testing.T) {
},
})
}

// https://github.com/jfrog/terraform-provider-artifactory/issues/225
func TestAccRemoteLegacyRepository_MissedRetrievalCachePeriodSecs_retained_between_updates_GH225(t *testing.T) {
_, fqrn, name := mkNames("terraform-remote-test-repo-basic", "artifactory_remote_repository")

key := fmt.Sprintf("cran-remote-%d", randomInt())
remoteRepositoryInit := fmt.Sprintf(`
resource "artifactory_remote_repository" "%s" {
key = "%s"
package_type = "cran"
repo_layout_ref = "bower-default"
url = "https://cran.r-project.org/"
notes = "managed by terraform"
property_sets = ["artifactory"]
unused_artifacts_cleanup_period_hours = 10100
retrieval_cache_period_seconds = 600
missed_cache_period_seconds = 1800
}
`, name, key)

remoteRepositoryUpdate := fmt.Sprintf(`
resource "artifactory_remote_repository" "%s" {
key = "%s"
package_type = "cran"
repo_layout_ref = "simple-default"
url = "https://cran.r-project.org/"
notes = "managed by terraform"
property_sets = ["artifactory"]
unused_artifacts_cleanup_period_hours = 10100
retrieval_cache_period_seconds = 600
missed_cache_period_seconds = 1800
}
`, name, key)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
CheckDestroy: verifyDeleted(fqrn, testCheckRepo),
ProviderFactories: testAccProviders,
Steps: []resource.TestStep{
{
Config: remoteRepositoryInit,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(fqrn, "key", key),
resource.TestCheckResourceAttr(fqrn, "missed_cache_period_seconds", "1800"),
),
},
{
Config: remoteRepositoryUpdate,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(fqrn, "key", key),
resource.TestCheckResourceAttr(fqrn, "missed_cache_period_seconds", "1800"),
),
},
},
})
}

0 comments on commit 469b52c

Please sign in to comment.