Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Terraform
Commits
f752f089
Commit
f752f089
authored
3 years ago
by
Brian Flad
Browse files
Options
Download
Email Patches
Plain Diff
backport of commit
0b404f4a
parent
f012c4ac
kmoe/init-checksum-miss-error
backport/4th-alternate-mirror-directory-fix/closely-key-civet
backport/add-format-function-guidance/ultimately-lucky-halibut
backport/add-internals-to-sidebar/willingly-bright-sunbird
backport/add-warnings-backends/physically-many-mantis
backport/backport/cstella84/patch-add-hyperlink-for-referenced-argument/manually-patient-locust
backport/bugfix_typos/hardly-sharp-mosquito
backport/docs-fix-typo/usefully-blessed-monkey
backport/fix-apt-page/abnormally-relative-quagga
backport/fix-backends-link/strangely-emerging-crane
backport/fix-cdktf-link/highly-pumped-snapper
backport/fix-glossary-table-contents/uniquely-pro-garfish
backport/fix-grammar/precisely-polite-tortoise
backport/fix-internals-overview/noticeably-up-rodent
backport/jbardin/static-validate-nested-types/possibly-crack-mouse
backport/main/cleanly-mature-scorpion
backport/mktg-tf-76ef54dc3c574e032725e0341be8e1d2/distinctly-sharp-ferret
backport/module-invocation-warning/fully-fitting-buzzard
backport/nvanthao/update-docs-implicit-provider/locally-neutral-lemur
backport/patch-1/gladly-mature-oarfish
backport/patch-1/manually-fine-mantis
backport/patch-1/rarely-informed-gopher
backport/patch-1/sensibly-saving-swine
backport/patch-1/yearly-rich-skunk
backport/patch-2/badly-game-spider
backport/patch-2/weekly-selected-tiger
backport/remove-future-statement-import/briefly-viable-glowworm
backport/remove-provisioners/widely-singular-hound
backport/system-parameter/infinitely-open-bluebird
backport/update-cloud-block-pages/verbally-key-kangaroo
backport/update-plan-page/lightly-outgoing-halibut
backport/update_docs_for_30072/gradually-trusting-wahoo
jbardin/backport-31576
v1.2.9
v1.2.8
v1.2.7
v1.2.6
v1.2.5
v1.2.4
v1.2.3
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
internal/plugin/grpc_provider.go
+4
-0
internal/plugin/grpc_provider.go
internal/plugin/grpc_provider_test.go
+61
-0
internal/plugin/grpc_provider_test.go
internal/plugin6/grpc_provider.go
+4
-0
internal/plugin6/grpc_provider.go
internal/plugin6/grpc_provider_test.go
+61
-0
internal/plugin6/grpc_provider_test.go
with
130 additions
and
0 deletions
+130
-0
internal/plugin/grpc_provider.go
+
4
-
0
View file @
f752f089
...
...
@@ -137,6 +137,10 @@ func (p *GRPCProvider) GetProviderSchema() (resp providers.GetProviderSchemaResp
resp
.
Diagnostics
=
resp
.
Diagnostics
.
Append
(
convert
.
ProtoToDiagnostics
(
protoResp
.
Diagnostics
))
if
resp
.
Diagnostics
.
HasErrors
()
{
return
resp
}
if
protoResp
.
Provider
==
nil
{
resp
.
Diagnostics
=
resp
.
Diagnostics
.
Append
(
errors
.
New
(
"missing provider schema"
))
return
resp
...
...
This diff is collapsed.
Click to expand it.
internal/plugin/grpc_provider_test.go
+
61
-
0
View file @
f752f089
...
...
@@ -39,6 +39,15 @@ func checkDiags(t *testing.T, d tfdiags.Diagnostics) {
}
}
// checkDiagsHasError ensures error diagnostics are present or fails the test.
func
checkDiagsHasError
(
t
*
testing
.
T
,
d
tfdiags
.
Diagnostics
)
{
t
.
Helper
()
if
!
d
.
HasErrors
()
{
t
.
Fatal
(
"expected error diagnostics"
)
}
}
func
providerProtoSchema
()
*
proto
.
GetProviderSchema_Response
{
return
&
proto
.
GetProviderSchema_Response
{
Provider
:
&
proto
.
Schema
{
...
...
@@ -92,6 +101,58 @@ func TestGRPCProvider_GetSchema(t *testing.T) {
checkDiags
(
t
,
resp
.
Diagnostics
)
}
// Ensure that gRPC errors are returned early.
// Reference: https://github.com/hashicorp/terraform/issues/31047
func
TestGRPCProvider_GetSchema_GRPCError
(
t
*
testing
.
T
)
{
ctrl
:=
gomock
.
NewController
(
t
)
client
:=
mockproto
.
NewMockProviderClient
(
ctrl
)
client
.
EXPECT
()
.
GetSchema
(
gomock
.
Any
(),
gomock
.
Any
(),
gomock
.
Any
(),
)
.
Return
(
&
proto
.
GetProviderSchema_Response
{},
fmt
.
Errorf
(
"test error"
))
p
:=
&
GRPCProvider
{
client
:
client
,
}
resp
:=
p
.
GetProviderSchema
()
checkDiagsHasError
(
t
,
resp
.
Diagnostics
)
}
// Ensure that provider error diagnostics are returned early.
// Reference: https://github.com/hashicorp/terraform/issues/31047
func
TestGRPCProvider_GetSchema_ResponseErrorDiagnostic
(
t
*
testing
.
T
)
{
ctrl
:=
gomock
.
NewController
(
t
)
client
:=
mockproto
.
NewMockProviderClient
(
ctrl
)
client
.
EXPECT
()
.
GetSchema
(
gomock
.
Any
(),
gomock
.
Any
(),
gomock
.
Any
(),
)
.
Return
(
&
proto
.
GetProviderSchema_Response
{
Diagnostics
:
[]
*
proto
.
Diagnostic
{
{
Severity
:
proto
.
Diagnostic_ERROR
,
Summary
:
"error summary"
,
Detail
:
"error detail"
,
},
},
// Trigger potential panics
Provider
:
&
proto
.
Schema
{},
},
nil
)
p
:=
&
GRPCProvider
{
client
:
client
,
}
resp
:=
p
.
GetProviderSchema
()
checkDiagsHasError
(
t
,
resp
.
Diagnostics
)
}
func
TestGRPCProvider_PrepareProviderConfig
(
t
*
testing
.
T
)
{
client
:=
mockProviderClient
(
t
)
p
:=
&
GRPCProvider
{
...
...
This diff is collapsed.
Click to expand it.
internal/plugin6/grpc_provider.go
+
4
-
0
View file @
f752f089
...
...
@@ -144,6 +144,10 @@ func (p *GRPCProvider) GetProviderSchema() (resp providers.GetProviderSchemaResp
resp
.
Diagnostics
=
resp
.
Diagnostics
.
Append
(
convert
.
ProtoToDiagnostics
(
protoResp
.
Diagnostics
))
if
resp
.
Diagnostics
.
HasErrors
()
{
return
resp
}
if
protoResp
.
Provider
==
nil
{
resp
.
Diagnostics
=
resp
.
Diagnostics
.
Append
(
errors
.
New
(
"missing provider schema"
))
return
resp
...
...
This diff is collapsed.
Click to expand it.
internal/plugin6/grpc_provider_test.go
+
61
-
0
View file @
f752f089
...
...
@@ -46,6 +46,15 @@ func checkDiags(t *testing.T, d tfdiags.Diagnostics) {
}
}
// checkDiagsHasError ensures error diagnostics are present or fails the test.
func
checkDiagsHasError
(
t
*
testing
.
T
,
d
tfdiags
.
Diagnostics
)
{
t
.
Helper
()
if
!
d
.
HasErrors
()
{
t
.
Fatal
(
"expected error diagnostics"
)
}
}
func
providerProtoSchema
()
*
proto
.
GetProviderSchema_Response
{
return
&
proto
.
GetProviderSchema_Response
{
Provider
:
&
proto
.
Schema
{
...
...
@@ -99,6 +108,58 @@ func TestGRPCProvider_GetSchema(t *testing.T) {
checkDiags
(
t
,
resp
.
Diagnostics
)
}
// Ensure that gRPC errors are returned early.
// Reference: https://github.com/hashicorp/terraform/issues/31047
func
TestGRPCProvider_GetSchema_GRPCError
(
t
*
testing
.
T
)
{
ctrl
:=
gomock
.
NewController
(
t
)
client
:=
mockproto
.
NewMockProviderClient
(
ctrl
)
client
.
EXPECT
()
.
GetProviderSchema
(
gomock
.
Any
(),
gomock
.
Any
(),
gomock
.
Any
(),
)
.
Return
(
&
proto
.
GetProviderSchema_Response
{},
fmt
.
Errorf
(
"test error"
))
p
:=
&
GRPCProvider
{
client
:
client
,
}
resp
:=
p
.
GetProviderSchema
()
checkDiagsHasError
(
t
,
resp
.
Diagnostics
)
}
// Ensure that provider error diagnostics are returned early.
// Reference: https://github.com/hashicorp/terraform/issues/31047
func
TestGRPCProvider_GetSchema_ResponseErrorDiagnostic
(
t
*
testing
.
T
)
{
ctrl
:=
gomock
.
NewController
(
t
)
client
:=
mockproto
.
NewMockProviderClient
(
ctrl
)
client
.
EXPECT
()
.
GetProviderSchema
(
gomock
.
Any
(),
gomock
.
Any
(),
gomock
.
Any
(),
)
.
Return
(
&
proto
.
GetProviderSchema_Response
{
Diagnostics
:
[]
*
proto
.
Diagnostic
{
{
Severity
:
proto
.
Diagnostic_ERROR
,
Summary
:
"error summary"
,
Detail
:
"error detail"
,
},
},
// Trigger potential panics
Provider
:
&
proto
.
Schema
{},
},
nil
)
p
:=
&
GRPCProvider
{
client
:
client
,
}
resp
:=
p
.
GetProviderSchema
()
checkDiagsHasError
(
t
,
resp
.
Diagnostics
)
}
func
TestGRPCProvider_PrepareProviderConfig
(
t
*
testing
.
T
)
{
client
:=
mockProviderClient
(
t
)
p
:=
&
GRPCProvider
{
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help