Skip to content

Commit

Permalink
Fix incorrect package type of 'helmoci' repo
Browse files Browse the repository at this point in the history
Add tests to verify 'package_type' attribute.
  • Loading branch information
alexhung committed Apr 5, 2024
1 parent e3f8397 commit 366352d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func ResourceArtifactoryVirtualHelmOciRepository() *schema.Resource {
unpackVirtualRepository := func(data *schema.ResourceData) (interface{}, string, error) {
d := &utilsdk.ResourceData{ResourceData: data}
repo := HelmOciVirtualRepositoryParams{
RepositoryBaseParams: UnpackBaseVirtRepo(data, DockerPackageType),
RepositoryBaseParams: UnpackBaseVirtRepo(data, HelmOciPackageType),
ResolveOCITagsByTimestamp: d.GetBool("resolve_oci_tags_by_timestamp", false),
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -767,8 +767,8 @@ func TestAccAllVirtualGradleLikeRepository(t *testing.T) {
}

// if you wish to override any of the default fields, just pass it as "extraFields" as these will overwrite
func mkNewVirtualTestCase(repoType string, t *testing.T, extraFields map[string]interface{}) (*testing.T, resource.TestCase) {
_, fqrn, name := testutil.MkNames("terraform-virtual-test-repo-full-", fmt.Sprintf("artifactory_virtual_%s_repository", repoType))
func mkNewVirtualTestCase(packageType string, t *testing.T, extraFields map[string]interface{}) (*testing.T, resource.TestCase) {
_, fqrn, name := testutil.MkNames("terraform-virtual-test-repo-full-", fmt.Sprintf("artifactory_virtual_%s_repository", packageType))
remoteRepoName := fmt.Sprintf("%s-remote", name)
defaultFields := map[string]interface{}{
"key": name,
Expand All @@ -791,17 +791,19 @@ func mkNewVirtualTestCase(repoType string, t *testing.T, extraFields map[string]
`
extraChecks := testutil.MapToTestChecks(fqrn, extraFields)
defaultChecks := testutil.MapToTestChecks(fqrn, allFields)
defaultChecks = append(defaultChecks, resource.TestCheckResourceAttr(fqrn, "package_type", packageType))

checks := append(defaultChecks, extraChecks...)
config := fmt.Sprintf(virtualRepoFull, repoType, name, remoteRepoName, allFieldsHcl)
config := fmt.Sprintf(virtualRepoFull, packageType, name, remoteRepoName, allFieldsHcl)

updatedFields := utilsdk.MergeMaps(defaultFields, extraFields, map[string]any{
"description": "",
"notes": "",
})
updatedFieldsHcl := utilsdk.FmtMapToHcl(updatedFields)
updatedConfig := fmt.Sprintf(virtualRepoFull, repoType, name, remoteRepoName, updatedFieldsHcl)
updatedConfig := fmt.Sprintf(virtualRepoFull, packageType, name, remoteRepoName, updatedFieldsHcl)
updatedChecks := testutil.MapToTestChecks(fqrn, updatedFields)
updatedChecks = append(updatedChecks, resource.TestCheckResourceAttr(fqrn, "package_type", packageType))

return t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
Expand Down

0 comments on commit 366352d

Please sign in to comment.