Skip to content

Commit 177467d

Browse files
committed
Added ResourcesMethod to tests in server_validatelistresourceconfig_test.go
1 parent 99229ad commit 177467d

File tree

3 files changed

+78
-24
lines changed

3 files changed

+78
-24
lines changed

internal/fwserver/server_listresource.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ func (s *Server) ListResource(ctx context.Context, fwReq *ListRequest, fwStream
8888

8989
if fwReq.Config == nil {
9090
fwStream.Results = NoListResults
91+
return
9192
}
9293

9394
req := list.ListRequest{

internal/proto5server/server_validatelistresourceconfig_test.go

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,7 @@ func TestServerValidateListResourceConfig(t *testing.T) {
2222

2323
testSchema := schema.Schema{
2424
Attributes: map[string]schema.Attribute{
25-
"test_optional": schema.StringAttribute{
26-
Optional: false,
27-
},
28-
"test_required": schema.StringAttribute{
25+
"test": schema.StringAttribute{
2926
Required: true,
3027
},
3128
},
@@ -64,16 +61,17 @@ func TestServerValidateListResourceConfig(t *testing.T) {
6461
MetadataMethod: func(_ context.Context, _ resource.MetadataRequest, resp *resource.MetadataResponse) {
6562
resp.TypeName = "test_resource"
6663
},
67-
ListResourceConfigSchemaMethod: func(_ context.Context, _ list.ListResourceSchemaRequest, resp *list.ListResourceSchemaResponse) {
68-
resp.Schema = schema.Schema{
69-
Attributes: map[string]schema.Attribute{
70-
"example_attribute": schema.StringAttribute{
71-
Required: true,
72-
},
73-
},
74-
}
75-
},
76-
ListMethod: func(_ context.Context, _ list.ListRequest, resp *list.ListResultsStream) {
64+
ListResourceConfigSchemaMethod: func(_ context.Context, _ list.ListResourceSchemaRequest, resp *list.ListResourceSchemaResponse) {},
65+
}
66+
},
67+
}
68+
},
69+
ResourcesMethod: func(_ context.Context) []func() resource.Resource {
70+
return []func() resource.Resource{
71+
func() resource.Resource {
72+
return &testprovider.Resource{
73+
MetadataMethod: func(_ context.Context, _ resource.MetadataRequest, response *resource.MetadataResponse) {
74+
response.TypeName = "test_resource"
7775
},
7876
}
7977
},
@@ -105,6 +103,17 @@ func TestServerValidateListResourceConfig(t *testing.T) {
105103
},
106104
}
107105
},
106+
ResourcesMethod: func(ctx context.Context) []func() resource.Resource {
107+
return []func() resource.Resource{
108+
func() resource.Resource {
109+
return &testprovider.Resource{
110+
MetadataMethod: func(ctx context.Context, request resource.MetadataRequest, response *resource.MetadataResponse) {
111+
response.TypeName = "test_resource"
112+
},
113+
}
114+
},
115+
}
116+
},
108117
},
109118
},
110119
},
@@ -138,6 +147,17 @@ func TestServerValidateListResourceConfig(t *testing.T) {
138147
},
139148
}
140149
},
150+
ResourcesMethod: func(ctx context.Context) []func() resource.Resource {
151+
return []func() resource.Resource{
152+
func() resource.Resource {
153+
return &testprovider.Resource{
154+
MetadataMethod: func(ctx context.Context, request resource.MetadataRequest, response *resource.MetadataResponse) {
155+
response.TypeName = "test_resource"
156+
},
157+
}
158+
},
159+
}
160+
},
141161
},
142162
},
143163
},

internal/proto6server/server_validatelistresourceconfig_test.go

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package proto6server
66
import (
77
"context"
88
"github.com/hashicorp/terraform-plugin-framework/resource"
9+
"github.com/hashicorp/terraform-plugin-go/tftypes"
910
"testing"
1011

1112
"github.com/google/go-cmp/cmp"
@@ -14,12 +15,19 @@ import (
1415
"github.com/hashicorp/terraform-plugin-framework/list"
1516
"github.com/hashicorp/terraform-plugin-framework/list/schema"
1617
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
17-
"github.com/hashicorp/terraform-plugin-go/tftypes"
1818
)
1919

2020
func TestServerValidateListResourceConfig(t *testing.T) {
2121
t.Parallel()
2222

23+
testSchema := schema.Schema{
24+
Attributes: map[string]schema.Attribute{
25+
"test": schema.StringAttribute{
26+
Required: true,
27+
},
28+
},
29+
}
30+
2331
testType := tftypes.Object{
2432
AttributeTypes: map[string]tftypes.Type{
2533
"test": tftypes.String,
@@ -36,14 +44,6 @@ func TestServerValidateListResourceConfig(t *testing.T) {
3644
t.Fatalf("unexpected error calling tfprotov6.NewDynamicValue(): %s", err)
3745
}
3846

39-
testSchema := schema.Schema{
40-
Attributes: map[string]schema.Attribute{
41-
"test": schema.StringAttribute{
42-
Required: true,
43-
},
44-
},
45-
}
46-
4747
testCases := map[string]struct {
4848
server *Server
4949
request *tfprotov6.ValidateListResourceConfigRequest
@@ -58,10 +58,21 @@ func TestServerValidateListResourceConfig(t *testing.T) {
5858
return []func() list.ListResource{
5959
func() list.ListResource {
6060
return &testprovider.ListResource{
61-
ListResourceConfigSchemaMethod: func(_ context.Context, _ list.ListResourceSchemaRequest, resp *list.ListResourceSchemaResponse) {},
6261
MetadataMethod: func(_ context.Context, _ resource.MetadataRequest, resp *resource.MetadataResponse) {
6362
resp.TypeName = "test_resource"
6463
},
64+
ListResourceConfigSchemaMethod: func(_ context.Context, _ list.ListResourceSchemaRequest, resp *list.ListResourceSchemaResponse) {},
65+
}
66+
},
67+
}
68+
},
69+
ResourcesMethod: func(_ context.Context) []func() resource.Resource {
70+
return []func() resource.Resource{
71+
func() resource.Resource {
72+
return &testprovider.Resource{
73+
MetadataMethod: func(_ context.Context, _ resource.MetadataRequest, response *resource.MetadataResponse) {
74+
response.TypeName = "test_resource"
75+
},
6576
}
6677
},
6778
}
@@ -92,6 +103,17 @@ func TestServerValidateListResourceConfig(t *testing.T) {
92103
},
93104
}
94105
},
106+
ResourcesMethod: func(ctx context.Context) []func() resource.Resource {
107+
return []func() resource.Resource{
108+
func() resource.Resource {
109+
return &testprovider.Resource{
110+
MetadataMethod: func(ctx context.Context, request resource.MetadataRequest, response *resource.MetadataResponse) {
111+
response.TypeName = "test_resource"
112+
},
113+
}
114+
},
115+
}
116+
},
95117
},
96118
},
97119
},
@@ -125,6 +147,17 @@ func TestServerValidateListResourceConfig(t *testing.T) {
125147
},
126148
}
127149
},
150+
ResourcesMethod: func(ctx context.Context) []func() resource.Resource {
151+
return []func() resource.Resource{
152+
func() resource.Resource {
153+
return &testprovider.Resource{
154+
MetadataMethod: func(ctx context.Context, request resource.MetadataRequest, response *resource.MetadataResponse) {
155+
response.TypeName = "test_resource"
156+
},
157+
}
158+
},
159+
}
160+
},
128161
},
129162
},
130163
},

0 commit comments

Comments
 (0)