@@ -11,6 +11,7 @@ import (
1111 "github.com/golang/mock/gomock"
1212 "github.com/google/go-cmp/cmp"
1313 "github.com/google/go-cmp/cmp/cmpopts"
14+ "github.com/hashicorp/terraform/internal/addrs"
1415 "github.com/hashicorp/terraform/internal/configs/hcl2shim"
1516 "github.com/hashicorp/terraform/internal/providers"
1617 "github.com/hashicorp/terraform/internal/tfdiags"
@@ -99,6 +100,9 @@ func providerProtoSchema() *proto.GetProviderSchema_Response {
99100 },
100101 },
101102 },
103+ ServerCapabilities : & proto.ServerCapabilities {
104+ GetProviderSchemaOptional : true ,
105+ },
102106 }
103107}
104108
@@ -111,6 +115,27 @@ func TestGRPCProvider_GetSchema(t *testing.T) {
111115 checkDiags (t , resp .Diagnostics )
112116}
113117
118+ // ensure that the global schema cache is used when the provider supports
119+ // GetProviderSchemaOptional
120+ func TestGRPCProvider_GetSchema_globalCache (t * testing.T ) {
121+ p := & GRPCProvider {
122+ Addr : addrs .ImpliedProviderForUnqualifiedType ("test" ),
123+ client : mockProviderClient (t ),
124+ }
125+
126+ // first call primes the cache
127+ resp := p .GetProviderSchema ()
128+
129+ // create a new provider instance which does not expect a GetProviderSchemaCall
130+ p = & GRPCProvider {
131+ Addr : addrs .ImpliedProviderForUnqualifiedType ("test" ),
132+ client : mockproto .NewMockProviderClient (gomock .NewController (t )),
133+ }
134+
135+ resp = p .GetProviderSchema ()
136+ checkDiags (t , resp .Diagnostics )
137+ }
138+
114139// Ensure that gRPC errors are returned early.
115140// Reference: https://github.com/hashicorp/terraform/issues/31047
116141func TestGRPCProvider_GetSchema_GRPCError (t * testing.T ) {
0 commit comments