Skip to content

Commit a7f8748

Browse files
authored
list: tidy the doc comments and tests (#1162)
1 parent 9adb46b commit a7f8748

File tree

4 files changed

+67
-276
lines changed

4 files changed

+67
-276
lines changed

list/list_resource.go

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -85,35 +85,39 @@ type ListResourceWithValidateConfig interface {
8585
ValidateListResourceConfig(context.Context, ValidateConfigRequest, *ValidateConfigResponse)
8686
}
8787

88-
// ListRequest represents a request for the provider to list instances
89-
// of a managed resource type that satisfy a user-defined request. An instance
90-
// of this reqeuest struct is passed as an argument to the provider's
91-
// ListResource function implementation.
88+
// ListRequest represents a request for the provider to list instances of a
89+
// managed resource type that satisfy a user-defined request. An instance of
90+
// this reqeuest struct is passed as an argument to the provider's List
91+
// function implementation.
9292
type ListRequest struct {
9393
// Config is the configuration the user supplied for listing resource
9494
// instances.
9595
Config tfsdk.Config
9696

9797
// IncludeResource indicates whether the provider should populate the
98-
// Resource field in the ListResult struct.
98+
// [ListResult.Resource] field.
9999
IncludeResource bool
100100
}
101101

102-
// ListResultsStream represents a streaming response to a ListRequest.
103-
// An instance of this struct is supplied as an argument to the provider's
104-
// ListResource function implementation function. The provider should set a Results
105-
// iterator function that yields zero or more results of type ListResult.
102+
// ListResultsStream represents a streaming response to a [ListRequest]. An
103+
// instance of this struct is supplied as an argument to the provider's
104+
// [ListResource.List] function. The provider should set a Results iterator
105+
// function that pushes zero or more results of type [ListResult].
106106
//
107107
// For convenience, a provider implementation may choose to convert a slice of
108108
// results into an iterator using [slices.Values].
109-
//
110-
// [slices.Values]: https://pkg.go.dev/slices#Values
111109
type ListResultsStream struct {
112-
// Results is a function that emits ListResult values via its yield
110+
// Results is a function that emits [ListResult] values via its push
113111
// function argument.
112+
//
113+
// To indicate a fatal processing error, push a [ListResult] that contains
114+
// a [diag.ErrorDiagnostic].
114115
Results iter.Seq[ListResult]
115116
}
116117

118+
// NoListResults is an iterator that pushes zero results.
119+
var NoListResults = func(func(ListResult) bool) {}
120+
117121
// ListResult represents a listed managed resource instance.
118122
type ListResult struct {
119123
// Identity is the identity of the managed resource instance.
@@ -124,7 +128,7 @@ type ListResult struct {
124128
// Resource is the provider's representation of the attributes of the
125129
// listed managed resource instance.
126130
//
127-
// If ListRequest.IncludeResource is true, a nil value will raise
131+
// If [ListRequest.IncludeResource] is true, a nil value will raise
128132
// a warning diagnostic.
129133
Resource *tfsdk.Resource
130134

@@ -140,8 +144,8 @@ type ListResult struct {
140144

141145
// ValidateConfigRequest represents a request to validate the configuration of
142146
// a list resource. An instance of this request struct is supplied as an
143-
// argument to the ValidateListResourceConfig receiver method or automatically
144-
// passed through to each ListResourceConfigValidator.
147+
// argument to the [ListResourceWithValidateConfig.ValidateListResourceConfig]
148+
// receiver method or automatically passed through to each [ConfigValidator].
145149
type ValidateConfigRequest struct {
146150
// Config is the configuration the user supplied for the resource.
147151
//
@@ -151,10 +155,10 @@ type ValidateConfigRequest struct {
151155
Config tfsdk.Config
152156
}
153157

154-
// ValidateConfigResponse represents a response to a ValidateConfigRequest. An
155-
// instance of this response struct is supplied as an argument to the
156-
// list.ValidateListResourceConfig receiver method or automatically passed
157-
// through to each ConfigValidator.
158+
// ValidateConfigResponse represents a response to a [ValidateConfigRequest].
159+
// An instance of this response struct is supplied as an argument to the
160+
// [list.ValidateListResourceConfig] receiver method or automatically passed
161+
// through to each [ConfigValidator].
158162
type ValidateConfigResponse struct {
159163
// Diagnostics report errors or warnings related to validating the list
160164
// configuration. An empty slice indicates success, with no warnings

list/schema/schema.go

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@ import (
1717
// Schema must satify the fwschema.Schema interface.
1818
var _ fwschema.Schema = Schema{}
1919

20-
// Schema defines the structure and value types of resource data. This type
21-
// is used as the resource.SchemaResponse type Schema field, which is
22-
// implemented by the resource.DataSource type Schema method.
20+
// Schema defines the structure and value types of a list block. This is
21+
// returned as a ListResourceSchemas map value by the GetProviderSchemas RPC.
2322
type Schema struct {
2423
// Attributes is the mapping of underlying attribute names to attribute
2524
// definitions.
@@ -106,7 +105,7 @@ func (s Schema) GetMarkdownDescription() string {
106105
return s.MarkdownDescription
107106
}
108107

109-
// GetVersion returns zero because list resource schemas do not have a version.
108+
// GetVersion always returns 0 because list resource schemas cannot be versioned.
110109
func (s Schema) GetVersion() int64 {
111110
return 0
112111
}
@@ -126,13 +125,6 @@ func (s Schema) TypeAtTerraformPath(ctx context.Context, p *tftypes.AttributePat
126125
return fwschema.SchemaTypeAtTerraformPath(ctx, s, p)
127126
}
128127

129-
// Validate verifies that the schema is not using a reserved field name for a top-level attribute.
130-
//
131-
// Deprecated: Use the ValidateImplementation method instead.
132-
func (s Schema) Validate() diag.Diagnostics {
133-
return s.ValidateImplementation(context.Background())
134-
}
135-
136128
// ValidateImplementation contains logic for validating the provider-defined
137129
// implementation of the schema and underlying attributes and blocks to prevent
138130
// unexpected errors or panics. This logic runs during the

list/schema/schema_test.go

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -797,47 +797,6 @@ func TestSchemaTypeAtTerraformPath(t *testing.T) {
797797
}
798798
}
799799

800-
func TestSchemaValidate(t *testing.T) {
801-
t.Parallel()
802-
803-
testCases := map[string]struct {
804-
schema schema.Schema
805-
expectedDiags diag.Diagnostics
806-
}{
807-
"empty-schema": {
808-
schema: schema.Schema{},
809-
},
810-
"validate-implementation-error": {
811-
schema: schema.Schema{
812-
Attributes: map[string]schema.Attribute{
813-
"depends_on": schema.StringAttribute{},
814-
},
815-
},
816-
expectedDiags: diag.Diagnostics{
817-
diag.NewErrorDiagnostic(
818-
"Reserved Root Attribute/Block Name",
819-
"When validating the resource or data source schema, an implementation issue was found. "+
820-
"This is always an issue with the provider and should be reported to the provider developers.\n\n"+
821-
"\"depends_on\" is a reserved root attribute/block name. "+
822-
"This is to prevent practitioners from needing special Terraform configuration syntax.",
823-
),
824-
},
825-
},
826-
}
827-
828-
for name, testCase := range testCases {
829-
t.Run(name, func(t *testing.T) {
830-
t.Parallel()
831-
832-
diags := testCase.schema.Validate()
833-
834-
if diff := cmp.Diff(diags, testCase.expectedDiags); diff != "" {
835-
t.Errorf("Unexpected diagnostics (+wanted, -got): %s", diff)
836-
}
837-
})
838-
}
839-
}
840-
841800
func TestSchemaValidateImplementation(t *testing.T) {
842801
t.Parallel()
843802

0 commit comments

Comments
 (0)