-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Get extra nested docs from schema map #1650
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
06b7d4c
Get extra nested docs from schema map
ee2aaa6
add a test that hits the objectType description path
guineveresaenger 36f3782
fix up test: descriptions from nested items can now be read
guineveresaenger e9edcad
re-record tests to reflect that nested fields now have a Description
guineveresaenger b7dd751
fix up Description() docs
guineveresaenger 720d9bb
Clean up nested descriptions and add test to veiry behavior
guineveresaenger 262b0d8
re-gen pf tests
guineveresaenger 244cc22
address code review. Refactor a few other MakeResource functions in t…
guineveresaenger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// Copyright 2016-2022, Pulumi Corporation. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package testprovider | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
// Subset of pulumi-cloudflare provider. | ||
func ProviderNestedDescriptions() *schema.Provider { | ||
resourceRuleset := func() *schema.Resource { | ||
return &schema.Resource{ | ||
Description: "Deploy a ruleset for cloudflare", | ||
Schema: resourceNestedDescriptionsSchema(), | ||
} | ||
} | ||
|
||
return &schema.Provider{ | ||
Schema: map[string]*schema.Schema{}, | ||
ResourcesMap: map[string]*schema.Resource{ | ||
"cloudflare_ruleset": resourceRuleset(), | ||
}, | ||
} | ||
} | ||
|
||
// An aggressively cut down version of cloudflare_ruleset. | ||
func resourceNestedDescriptionsSchema() map[string]*schema.Schema { | ||
return map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
Description: "Name of the ruleset.", | ||
}, | ||
"description": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: "Brief summary of the ruleset and its intended use.", | ||
}, | ||
"rules": { | ||
Type: schema.TypeList, | ||
Optional: true, | ||
Description: "List of rules to apply to the ruleset.", | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "Unique rule identifier.", | ||
}, | ||
"version": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "Version of the ruleset to deploy.", | ||
}, | ||
"action_parameters": { | ||
Type: schema.TypeList, | ||
// MaxItems: 1, | ||
Optional: true, | ||
Description: "List of parameters that configure the behavior of the ruleset rule action.", | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"id": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: "Identifier of the action parameter to modify. " + | ||
"When Terraform is mentioned here, the description should be dropped.", | ||
}, | ||
"translateField": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: "When cloudflare_ruleset is mentioned, it should be translated.", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -42,13 +42,21 @@ func TestObjectAttribute(t *testing.T) { | |||
assert.Equal(t, shim.TypeString, s.Type()) | ||||
} | ||||
|
||||
func TestTypeSchemaDescriptionIsEmpty(t *testing.T) { | ||||
shimmedType := &typeSchema{ | ||||
t: types.StringType, | ||||
nested: nil, | ||||
} | ||||
assert.Equal(t, shimmedType.Description(), "") | ||||
} | ||||
|
||||
func TestSingleNestedBlock(t *testing.T) { | ||||
b := schema.SingleNestedBlock{ | ||||
Attributes: simpleObjectAttributes(), | ||||
} | ||||
shimmed := &blockSchema{"key", pfutils.FromResourceBlock(b)} | ||||
assertIsObjectType(t, shimmed) | ||||
assert.Equal(t, "obj[c=str,co=str,o=str,r=str]", schemaLogicalType(shimmed).String()) | ||||
assert.Equal(t, "obj[c=str,co=str,desc=str,o=str,r=str]", schemaLogicalType(shimmed).String()) | ||||
r, ok := shimmed.Elem().(shim.Resource) | ||||
require.True(t, ok, "Single-nested TF blocks should be represented as Elem() shim.Resource") | ||||
assertHasSimpleObjectAttributes(t, r) | ||||
|
@@ -61,7 +69,7 @@ func TestListNestedBlock(t *testing.T) { | |||
}, | ||||
} | ||||
shimmed := &blockSchema{"key", pfutils.FromResourceBlock(b)} | ||||
assert.Equal(t, "list[obj[c=str,co=str,o=str,r=str]]", schemaLogicalType(shimmed).String()) | ||||
assert.Equal(t, "list[obj[c=str,co=str,desc=str,o=str,r=str]]", schemaLogicalType(shimmed).String()) | ||||
r, ok := shimmed.Elem().(shim.Resource) | ||||
require.True(t, ok, "List-nested TF blocks should be represented as Elem() shim.Resource") | ||||
assertHasSimpleObjectAttributes(t, r) | ||||
|
@@ -74,7 +82,7 @@ func TestSetNestedBlock(t *testing.T) { | |||
}, | ||||
} | ||||
shimmed := &blockSchema{"key", pfutils.FromResourceBlock(b)} | ||||
assert.Equal(t, "set[obj[c=str,co=str,o=str,r=str]]", schemaLogicalType(shimmed).String()) | ||||
assert.Equal(t, "set[obj[c=str,co=str,desc=str,o=str,r=str]]", schemaLogicalType(shimmed).String()) | ||||
r, ok := shimmed.Elem().(shim.Resource) | ||||
require.True(t, ok, "Set-nested TF blocks should be represented as Elem() shim.Resource") | ||||
assertHasSimpleObjectAttributes(t, r) | ||||
|
@@ -135,6 +143,9 @@ func simpleObjectAttributes() map[string]schema.Attribute { | |||
Computed: true, | ||||
Optional: true, | ||||
}, | ||||
"desc": schema.StringAttribute{ | ||||
Description: "I am a description", | ||||
}, | ||||
} | ||||
} | ||||
|
||||
|
@@ -143,6 +154,8 @@ func assertHasSimpleObjectAttributes(t *testing.T, r shim.Resource) { | |||
assert.True(t, r.Schema().Get("c").Computed(), "c is computed") | ||||
assert.True(t, r.Schema().Get("r").Required(), "r is required") | ||||
assert.True(t, r.Schema().Get("co").Computed() && r.Schema().Get("co").Optional(), "co is computed and optional") | ||||
assert.Equal(t, r.Schema().Get("desc").Description(), "I am a description") | ||||
|
||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
} | ||||
|
||||
func assertIsObjectType(t *testing.T, shimmed shim.Schema) { | ||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.