Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions internal/fwserver/server_configureprovider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,20 @@ func TestServerConfigureProvider(t *testing.T) {
ActionData: "test-provider-configure-value",
},
},
"response-listresourcedata": {
server: &fwserver.Server{
Provider: &testprovider.Provider{
SchemaMethod: func(_ context.Context, _ provider.SchemaRequest, resp *provider.SchemaResponse) {},
ConfigureMethod: func(ctx context.Context, req provider.ConfigureRequest, resp *provider.ConfigureResponse) {
resp.ListResourceData = "test-provider-configure-value"
},
},
},
request: &provider.ConfigureRequest{},
expectedResponse: &provider.ConfigureResponse{
ListResourceData: "test-provider-configure-value",
},
},
"response-invalid-deferral-diagnostic": {
server: &fwserver.Server{
Provider: &testprovider.Provider{
Expand Down
40 changes: 40 additions & 0 deletions internal/fwserver/server_listresource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package fwserver_test

import (
"context"
"fmt"
"slices"
"testing"

Expand All @@ -13,6 +14,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/internal/fwserver"
"github.com/hashicorp/terraform-plugin-framework/internal/testing/testprovider"
"github.com/hashicorp/terraform-plugin-framework/list"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/identityschema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
Expand Down Expand Up @@ -182,6 +184,44 @@ func TestServerListResource(t *testing.T) {
expectedStreamEvents: []fwserver.ListResult{},
expectedError: "config cannot be nil",
},
"listresource-configure-data": {
server: &fwserver.Server{
ListResourceConfigureData: "test-provider-configure-value",
Provider: &testprovider.Provider{},
},
request: &fwserver.ListRequest{
Config: &tfsdk.Config{},
ListResource: &testprovider.ListResourceWithConfigure{
ConfigureMethod: func(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
providerData, ok := req.ProviderData.(string)

if !ok {
resp.Diagnostics.AddError(
"Unexpected ConfigureRequest.ProviderData",
fmt.Sprintf("Expected string, got: %T", req.ProviderData),
)
return
}

if providerData != "test-provider-configure-value" {
resp.Diagnostics.AddError(
"Unexpected ConfigureRequest.ProviderData",
fmt.Sprintf("Expected test-provider-configure-value, got: %q", providerData),
)
}
},
ListResource: &testprovider.ListResource{
ListMethod: func(ctx context.Context, req list.ListRequest, resp *list.ListResultsStream) {
// In practice, the Configure method would save the
// provider data to the ListResource implementation and
// use it here. The fact that Configure is able to
// read the data proves this can work.
},
},
},
},
expectedStreamEvents: []fwserver.ListResult{},
},
}

for name, testCase := range testCases {
Expand Down
Loading