Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: Alper Rifat Ulucinar <[email protected]>
  • Loading branch information
ulucinar committed Sep 8, 2022
1 parent d0af53c commit 7561401
Show file tree
Hide file tree
Showing 5 changed files with 814 additions and 763 deletions.
2 changes: 1 addition & 1 deletion pkg/registry/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ func (r *Resource) scrapeFieldDocs(doc *html.Node, fieldXPath string) {
conflictedFields[attrName] = true
continue
}
r.ArgumentDocs[attrName] = getDescription(docStr)
r.ArgumentDocs[attrName] = strings.TrimSpace(getDescription(docStr))
}

// Remove descriptions for repeating fields in the registry.
Expand Down
22 changes: 22 additions & 0 deletions pkg/registry/meta_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,28 @@ func TestScrapeRepo(t *testing.T) {
if err := yaml.Unmarshal(buff, &pmExpected); err != nil {
t.Errorf("Failed to unmarshal expected ProviderMetadata from file: %s", tc.want.pmPath)
}
// upcoming cmp.Diff fails if
// resources[*].examples[*].dependencies or
// resources[*].examples[*].references is not present in the expected
// metadata document (and is thus nil when decoded). One way to handle
// this would be not to initialize them to empty maps/slices while
// populating the `ProviderMetadata` struct but this is good to eliminate
// nil checks elsewhere. Thus, for the test cases, instead of having to manually
// initialize them in the testcase YAML documents, we do so programmatically below
for _, r := range pmExpected.Resources {
for eKey, e := range r.Examples {
if e.Dependencies == nil {
e.Dependencies = make(Dependencies)
}
if e.References == nil {
e.References = make(map[string]string)
}
r.Examples[eKey] = e
}
if len(r.ImportStatements) == 0 {
r.ImportStatements = nil
}
}
if diff := cmp.Diff(&pmExpected, pm, cmpopts.IgnoreUnexported(fieldpath.Paved{})); diff != "" {
t.Errorf("\n%s\nScrapeRepo(ProviderConfig): -want, +got:\n%s", tc.reason, diff)
}
Expand Down
67 changes: 33 additions & 34 deletions pkg/registry/testdata/aws/pm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ resources:
{
"analyzer_name": "example"
}
references: {}
dependencies: {}
- name: example
manifest: |-
{
Expand All @@ -22,7 +20,6 @@ resources:
],
"type": "ORGANIZATION"
}
references: {}
dependencies:
aws_organizations_organization.example: |-
{
Expand All @@ -31,12 +28,13 @@ resources:
]
}
argumentDocs:
analyzer_name: ' Name of the Analyzer.'
analyzer_name: Name of the Analyzer.
arn: The Amazon Resource Name of the Analyzer.
id: Analyzer name.
tags: ' Key-value map of resource tags. If configured with a provider default_tags configuration block present, tags with matching keys will overwrite those defined at the provider-level.'
tags: Key-value map of resource tags. If configured with a provider default_tags configuration block present, tags with matching keys will overwrite those defined at the provider-level.
tags_all: A map of tags assigned to the resource, including those inherited from the provider default_tags configuration block.
type: ' Type of Analyzer. Valid values are ACCOUNT or ORGANIZATION. Defaults to ACCOUNT.'
type: Type of Analyzer. Valid values are ACCOUNT or ORGANIZATION. Defaults to ACCOUNT.
importStatements: []
aws_ebs_volume:
subCategory: EBS (EC2)
description: Provides an elastic block storage resource.
Expand All @@ -52,26 +50,25 @@ resources:
"Name": "HelloWorld"
}
}
references: {}
dependencies: {}
argumentDocs:
arn: The volume ARN .
availability_zone: ' The AZ where the EBS volume will exist.'
create: ' Used for creating volumes. This includes the time required for the volume to become available'
delete: ' Used for destroying volumes'
encrypted: ' If true, the disk will be encrypted.'
availability_zone: The AZ where the EBS volume will exist.
create: Used for creating volumes. This includes the time required for the volume to become available
delete: Used for destroying volumes
encrypted: If true, the disk will be encrypted.
id: The volume ID .
iops: ' The amount of IOPS to provision for the disk. Only valid for type of io1, io2 or gp3.'
kms_key_id: ' The ARN for the KMS encryption key. When specifying kms_key_id, encrypted needs to be set to true. Note: Terraform must be running with credentials which have the GenerateDataKeyWithoutPlaintext permission on the specified KMS key as required by the EBS KMS CMK volume provisioning process to prevent a volume from being created and almost immediately deleted.'
multi_attach_enabled: ' Specifies whether to enable Amazon EBS Multi-Attach. Multi-Attach is supported on io1 and io2 volumes.'
outpost_arn: ' The Amazon Resource Name of the Outpost.'
size: ' The size of the drive in GiBs.'
snapshot_id: ' A snapshot to base the EBS volume off of.'
tags: ' A map of tags to assign to the resource. If configured with a provider default_tags configuration block present, tags with matching keys will overwrite those defined at the provider-level.'
iops: The amount of IOPS to provision for the disk. Only valid for type of io1, io2 or gp3.
kms_key_id: 'The ARN for the KMS encryption key. When specifying kms_key_id, encrypted needs to be set to true. Note: Terraform must be running with credentials which have the GenerateDataKeyWithoutPlaintext permission on the specified KMS key as required by the EBS KMS CMK volume provisioning process to prevent a volume from being created and almost immediately deleted.'
multi_attach_enabled: Specifies whether to enable Amazon EBS Multi-Attach. Multi-Attach is supported on io1 and io2 volumes.
outpost_arn: The Amazon Resource Name of the Outpost.
size: The size of the drive in GiBs.
snapshot_id: A snapshot to base the EBS volume off of.
tags: A map of tags to assign to the resource. If configured with a provider default_tags configuration block present, tags with matching keys will overwrite those defined at the provider-level.
tags_all: A map of tags assigned to the resource, including those inherited from the provider default_tags configuration block.
throughput: ' The throughput that the volume supports, in MiB/s. Only valid for type of gp3.'
type: ' The type of EBS volume. Can be standard, gp2, gp3, io1, io2, sc1 or st1 .'
update: ' Used for size, type, or iops volume changes'
throughput: The throughput that the volume supports, in MiB/s. Only valid for type of gp3.
type: The type of EBS volume. Can be standard, gp2, gp3, io1, io2, sc1 or st1 .
update: Used for size, type, or iops volume changes
importStatements: []
aws_s3_bucket_acl:
subCategory: S3 (Simple Storage)
description: Provides an S3 bucket ACL resource.
Expand Down Expand Up @@ -135,15 +132,17 @@ resources:
"bucket": "my-tf-example-bucket"
}
argumentDocs:
access_control_policy: ' A configuration block that sets the ACL permissions for an object per grantee documented below.'
acl: ' The canned ACL to apply to the bucket.'
bucket: ' The name of the bucket.'
display_name: ' The display name of the owner.'
email_address: ' Email address of the grantee. See Regions and Endpoints for supported AWS regions where this argument can be specified.'
expected_bucket_owner: ' The account ID of the expected bucket owner.'
grant: ' Set of grant configuration blocks documented below.'
grantee: ' Configuration block for the person being granted permissions documented below.'
owner: ' Configuration block of the bucket owner''s display name and ID documented below.'
permission: ' Logging permissions assigned to the grantee for the bucket.'
type: ' Type of grantee. Valid values: CanonicalUser, AmazonCustomerByEmail, Group.'
uri: ' URI of the grantee group.'
access_control_policy: A configuration block that sets the ACL permissions for an object per grantee documented below.
access_control_policy.grant: Set of grant configuration blocks documented below.
access_control_policy.grant.grantee: Configuration block for the person being granted permissions documented below.
access_control_policy.grant.permission: Logging permissions assigned to the grantee for the bucket.
access_control_policy.owner: Configuration block of the bucket owner's display name and ID documented below.
acl: The canned ACL to apply to the bucket.
bucket: The name of the bucket.
expected_bucket_owner: The account ID of the expected bucket owner.
grantee.email_address: Email address of the grantee. See Regions and Endpoints for supported AWS regions where this argument can be specified.
grantee.type: 'Type of grantee. Valid values: CanonicalUser, AmazonCustomerByEmail, Group.'
grantee.uri: URI of the grantee group.
owner.display_name: The display name of the owner.
owner.id: The ID of the owner.
importStatements: []
Loading

0 comments on commit 7561401

Please sign in to comment.