Skip to content

Commit

Permalink
Merge pull request GoogleCloudPlatform#2593 from jasonvigil/fix-perio…
Browse files Browse the repository at this point in the history
…dics

fix: Properly handle test edge cases direct resource conversions
  • Loading branch information
google-oss-prow[bot] authored Aug 30, 2024
2 parents 683d6e7 + 5182b4e commit 404c035
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions pkg/test/resourcefixture/contexts/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,20 @@ func GetResourceContext(fixture resourcefixture.ResourceFixture, serviceMetadata
}

func (rc ResourceContext) SupportsLabels(smLoader *servicemappingloader.ServiceMappingLoader) bool {
if rc.IsDCLResource {
if rc.IsTFResource {
// For tf based resources, resolve the label info from ResourceConfig
resourceConfig := rc.getResourceConfig(smLoader)
return resourceConfig.MetadataMapping.Labels != ""
} else if rc.IsDCLResource {
_, _, found, err := dclextension.GetLabelsFieldSchema(rc.DCLSchema)
if err != nil {
panic(fmt.Errorf("error getting the DCL schema for labels field: %w", err))
}
return found
} else {
// Labels are not supported for Direct resources yet.
return false
}
// For tf based resources, resolve the label info from ResourceConfig
resourceConfig := rc.getResourceConfig(smLoader)
return resourceConfig.MetadataMapping.Labels != ""
}

func (rc ResourceContext) getResourceConfig(smLoader *servicemappingloader.ServiceMappingLoader) v1alpha1.ResourceConfig {
Expand All @@ -145,11 +149,12 @@ func (rc ResourceContext) getResourceConfig(smLoader *servicemappingloader.Servi
}

func (rc ResourceContext) IsAutoGenerated(smLoader *servicemappingloader.ServiceMappingLoader) bool {
if rc.IsDCLResource {
if rc.IsTFResource {
resourceConfig := rc.getResourceConfig(smLoader)
return resourceConfig.AutoGenerated
} else {
return false
}
resourceConfig := rc.getResourceConfig(smLoader)
return resourceConfig.AutoGenerated
}

func (rc ResourceContext) Create(ctx context.Context, _ *testing.T, u *unstructured.Unstructured, provider *tfschema.Provider, c client.Client, smLoader *servicemappingloader.ServiceMappingLoader, config *mmdcl.Config, dclConverter *dclconversion.Converter) (*unstructured.Unstructured, error) {
Expand Down

0 comments on commit 404c035

Please sign in to comment.