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 12, 2022
1 parent 82ecde7 commit 5948cf0
Show file tree
Hide file tree
Showing 5 changed files with 1,428 additions and 1,318 deletions.
2 changes: 1 addition & 1 deletion pkg/registry/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ func (r *Resource) scrapeFieldDocs(doc *html.Node, fieldXPath string) {
conflictedFields[attrName] = true
continue
}
r.ArgumentDocs[attrName] = docStr
r.ArgumentDocs[attrName] = strings.TrimSpace(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
291 changes: 145 additions & 146 deletions pkg/registry/testdata/aws/pm.yaml
Original file line number Diff line number Diff line change
@@ -1,149 +1,148 @@
name: test-provider
resources:
aws_accessanalyzer_analyzer:
subCategory: IAM Access Analyzer
description: Manages an Access Analyzer Analyzer
name: aws_accessanalyzer_analyzer
title: aws_accessanalyzer_analyzer
examples:
- name: example
manifest: |-
{
"analyzer_name": "example"
}
references: {}
dependencies: {}
- name: example
manifest: |-
{
"analyzer_name": "example",
"depends_on": [
"${aws_organizations_organization.example}"
],
"type": "ORGANIZATION"
}
references: {}
dependencies:
aws_organizations_organization.example: |-
{
"aws_service_access_principals": [
"access-analyzer.amazonaws.com"
]
}
argumentDocs:
analyzer_name: ' - (Required) Name of the Analyzer.'
arn: ' - The Amazon Resource Name (ARN) of the Analyzer.'
id: ' - Analyzer name.'
tags: ' - (Optional) 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: ' - (Optional) Type of Analyzer. Valid values are ACCOUNT or ORGANIZATION. Defaults to ACCOUNT.'
aws_ebs_volume:
subCategory: EBS (EC2)
description: Provides an elastic block storage resource.
name: aws_ebs_volume
title: aws_ebs_volume
examples:
- name: example
manifest: |-
{
"availability_zone": "us-west-2a",
"size": 40,
"tags": {
"Name": "HelloWorld"
}
}
references: {}
dependencies: {}
argumentDocs:
arn: ' - The volume ARN (e.g., arn:aws:ec2:us-east-1:0123456789012:volume/vol-59fcb34e).'
availability_zone: ' - (Required) The AZ where the EBS volume will exist.'
create: ' - (Default 5 minutes) Used for creating volumes. This includes the time required for the volume to become available'
delete: ' - (Default 5 minutes) Used for destroying volumes'
encrypted: ' - (Optional) If true, the disk will be encrypted.'
id: ' - The volume ID (e.g., vol-59fcb34e).'
iops: ' - (Optional) The amount of IOPS to provision for the disk. Only valid for type of io1, io2 or gp3.'
kms_key_id: ' - (Optional) 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: ' - (Optional) Specifies whether to enable Amazon EBS Multi-Attach. Multi-Attach is supported on io1 and io2 volumes.'
outpost_arn: ' - (Optional) The Amazon Resource Name (ARN) of the Outpost.'
size: ' - (Optional) The size of the drive in GiBs.'
snapshot_id: ' (Optional) A snapshot to base the EBS volume off of.'
tags: ' - (Optional) 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: ' - (Optional) The throughput that the volume supports, in MiB/s. Only valid for type of gp3.'
type: ' - (Optional) The type of EBS volume. Can be standard, gp2, gp3, io1, io2, sc1 or st1 (Default: gp2).'
update: ' - (Default 5 minutes) Used for size, type, or iops volume changes'
aws_s3_bucket_acl:
subCategory: S3 (Simple Storage)
description: Provides an S3 bucket ACL resource.
name: aws_s3_bucket_acl
title: aws_s3_bucket_acl
examples:
- name: example_bucket_acl
manifest: |-
{
"acl": "private",
"bucket": "${aws_s3_bucket.example.id}"
}
references:
bucket: aws_s3_bucket.example.id
dependencies:
aws_s3_bucket.example: |-
{
"bucket": "my-tf-example-bucket"
}
- name: example
manifest: |-
{
"access_control_policy": [
{
"grant": [
{
"grantee": [
{
"id": "${data.aws_canonical_user_id.current.id}",
"type": "CanonicalUser"
}
],
"permission": "READ"
},
{
"grantee": [
{
"type": "Group",
"uri": "http://acs.amazonaws.com/groups/s3/LogDelivery"
}
],
"permission": "READ_ACP"
aws_accessanalyzer_analyzer:
subCategory: IAM Access Analyzer
description: Manages an Access Analyzer Analyzer
name: aws_accessanalyzer_analyzer
title: aws_accessanalyzer_analyzer
examples:
- name: example
manifest: |-
{
"analyzer_name": "example"
}
- name: example
manifest: |-
{
"analyzer_name": "example",
"depends_on": [
"${aws_organizations_organization.example}"
],
"type": "ORGANIZATION"
}
dependencies:
aws_organizations_organization.example: |-
{
"aws_service_access_principals": [
"access-analyzer.amazonaws.com"
]
}
argumentDocs:
analyzer_name: '- (Required) Name of the Analyzer.'
arn: '- The Amazon Resource Name (ARN) of the Analyzer.'
id: '- Analyzer name.'
tags: '- (Optional) 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: '- (Optional) 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.
name: aws_ebs_volume
title: aws_ebs_volume
examples:
- name: example
manifest: |-
{
"availability_zone": "us-west-2a",
"size": 40,
"tags": {
"Name": "HelloWorld"
}
],
"owner": [
{
"id": "${data.aws_canonical_user_id.current.id}"
}
]
}
],
"bucket": "${aws_s3_bucket.example.id}"
}
references:
access_control_policy.grant.grantee.id: data.aws_canonical_user_id.current.id
access_control_policy.owner.id: data.aws_canonical_user_id.current.id
bucket: aws_s3_bucket.example.id
dependencies:
aws_s3_bucket.example: |-
{
"bucket": "my-tf-example-bucket"
}
argumentDocs:
access_control_policy: ' - (Optional, Conflicts with acl) A configuration block that sets the ACL permissions for an object per grantee documented below.'
acl: ' - (Optional, Conflicts with access_control_policy) The canned ACL to apply to the bucket.'
bucket: ' - (Required, Forces new resource) The name of the bucket.'
display_name: ' - (Optional) The display name of the owner.'
email_address: ' - (Optional) Email address of the grantee. See Regions and Endpoints for supported AWS regions where this argument can be specified.'
expected_bucket_owner: ' - (Optional, Forces new resource) The account ID of the expected bucket owner.'
grant: ' - (Required) Set of grant configuration blocks documented below.'
grantee: ' - (Required) Configuration block for the person being granted permissions documented below.'
owner: ' - (Required) Configuration block of the bucket owner''s display name and ID documented below.'
permission: ' - (Required) Logging permissions assigned to the grantee for the bucket.'
type: ' - (Required) Type of grantee. Valid values: CanonicalUser, AmazonCustomerByEmail, Group.'
uri: ' - (Optional) URI of the grantee group.'
}
argumentDocs:
arn: '- The volume ARN (e.g., arn:aws:ec2:us-east-1:0123456789012:volume/vol-59fcb34e).'
availability_zone: '- (Required) The AZ where the EBS volume will exist.'
create: '- (Default 5 minutes) Used for creating volumes. This includes the time required for the volume to become available'
delete: '- (Default 5 minutes) Used for destroying volumes'
encrypted: '- (Optional) If true, the disk will be encrypted.'
id: '- The volume ID (e.g., vol-59fcb34e).'
iops: '- (Optional) The amount of IOPS to provision for the disk. Only valid for type of io1, io2 or gp3.'
kms_key_id: '- (Optional) 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: '- (Optional) Specifies whether to enable Amazon EBS Multi-Attach. Multi-Attach is supported on io1 and io2 volumes.'
outpost_arn: '- (Optional) The Amazon Resource Name (ARN) of the Outpost.'
size: '- (Optional) The size of the drive in GiBs.'
snapshot_id: (Optional) A snapshot to base the EBS volume off of.
tags: '- (Optional) 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: '- (Optional) The throughput that the volume supports, in MiB/s. Only valid for type of gp3.'
type: '- (Optional) The type of EBS volume. Can be standard, gp2, gp3, io1, io2, sc1 or st1 (Default: gp2).'
update: '- (Default 5 minutes) Used for size, type, or iops volume changes'
importStatements: []
aws_s3_bucket_acl:
subCategory: S3 (Simple Storage)
description: Provides an S3 bucket ACL resource.
name: aws_s3_bucket_acl
title: aws_s3_bucket_acl
examples:
- name: example_bucket_acl
manifest: |-
{
"acl": "private",
"bucket": "${aws_s3_bucket.example.id}"
}
references:
bucket: aws_s3_bucket.example.id
dependencies:
aws_s3_bucket.example: |-
{
"bucket": "my-tf-example-bucket"
}
- name: example
manifest: |-
{
"access_control_policy": [
{
"grant": [
{
"grantee": [
{
"id": "${data.aws_canonical_user_id.current.id}",
"type": "CanonicalUser"
}
],
"permission": "READ"
},
{
"grantee": [
{
"type": "Group",
"uri": "http://acs.amazonaws.com/groups/s3/LogDelivery"
}
],
"permission": "READ_ACP"
}
],
"owner": [
{
"id": "${data.aws_canonical_user_id.current.id}"
}
]
}
],
"bucket": "${aws_s3_bucket.example.id}"
}
references:
access_control_policy.grant.grantee.id: data.aws_canonical_user_id.current.id
access_control_policy.owner.id: data.aws_canonical_user_id.current.id
bucket: aws_s3_bucket.example.id
dependencies:
aws_s3_bucket.example: |-
{
"bucket": "my-tf-example-bucket"
}
argumentDocs:
access_control_policy: '- (Optional, Conflicts with acl) A configuration block that sets the ACL permissions for an object per grantee documented below.'
access_control_policy.grant: '- (Required) Set of grant configuration blocks documented below.'
access_control_policy.grant.grantee: '- (Required) Configuration block for the person being granted permissions documented below.'
access_control_policy.grant.permission: '- (Required) Logging permissions assigned to the grantee for the bucket.'
access_control_policy.owner: '- (Required) Configuration block of the bucket owner''s display name and ID documented below.'
acl: '- (Optional, Conflicts with access_control_policy) The canned ACL to apply to the bucket.'
bucket: '- (Required, Forces new resource) The name of the bucket.'
expected_bucket_owner: '- (Optional, Forces new resource) The account ID of the expected bucket owner.'
grantee.email_address: '- (Optional) Email address of the grantee. See Regions and Endpoints for supported AWS regions where this argument can be specified.'
grantee.type: '- (Required) Type of grantee. Valid values: CanonicalUser, AmazonCustomerByEmail, Group.'
grantee.uri: '- (Optional) URI of the grantee group.'
owner.display_name: '- (Optional) The display name of the owner.'
owner.id: '- (Required) The ID of the owner.'
importStatements: []
Loading

0 comments on commit 5948cf0

Please sign in to comment.