-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add protocol bindings to external interface
- Loading branch information
1 parent
da509ac
commit b7bed63
Showing
26 changed files
with
554 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package tfprotov5 | ||
|
||
const ( | ||
// TODO: doc | ||
DeferredReasonUnknown DeferredReason = 0 | ||
|
||
// TODO: doc | ||
DeferredReasonResourceConfigUnknown DeferredReason = 1 | ||
|
||
// TODO: doc | ||
DeferredReasonProviderConfigUnknown DeferredReason = 2 | ||
|
||
// TODO: doc | ||
DeferredReasonAbsentPrereq DeferredReason = 3 | ||
) | ||
|
||
// TODO: doc | ||
type Deferred struct { | ||
// TODO: doc | ||
Reason DeferredReason | ||
} | ||
|
||
// TODO: doc | ||
type DeferredReason int32 | ||
|
||
func (d DeferredReason) String() string { | ||
switch d { | ||
case 0: | ||
return "UNKNOWN" | ||
case 1: | ||
return "RESOURCE_CONFIG_UNKNOWN" | ||
case 2: | ||
return "PROVIDER_CONFIG_UNKNOWN" | ||
case 3: | ||
return "ABSENT_PREREQ" | ||
} | ||
return "UNKNOWN" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package toproto | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-go/tfprotov5" | ||
"github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5" | ||
) | ||
|
||
func Deferred(in *tfprotov5.Deferred) *tfplugin5.Deferred { | ||
if in == nil { | ||
return nil | ||
} | ||
|
||
resp := &tfplugin5.Deferred{ | ||
Reason: tfplugin5.Deferred_Reason(in.Reason), | ||
} | ||
|
||
return resp | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package toproto_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
"github.com/google/go-cmp/cmp/cmpopts" | ||
|
||
"github.com/hashicorp/terraform-plugin-go/tfprotov5" | ||
"github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5" | ||
"github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/toproto" | ||
) | ||
|
||
func TestDeferred(t *testing.T) { | ||
t.Parallel() | ||
|
||
testCases := map[string]struct { | ||
in *tfprotov5.Deferred | ||
expected *tfplugin5.Deferred | ||
}{ | ||
"nil": { | ||
in: nil, | ||
expected: nil, | ||
}, | ||
"zero": { | ||
in: &tfprotov5.Deferred{}, | ||
expected: &tfplugin5.Deferred{ | ||
Reason: tfplugin5.Deferred_UNKNOWN, | ||
}, | ||
}, | ||
"Reason-ResourceConfigUnknown": { | ||
in: &tfprotov5.Deferred{ | ||
Reason: tfprotov5.DeferredReasonResourceConfigUnknown, | ||
}, | ||
|
||
expected: &tfplugin5.Deferred{ | ||
Reason: tfplugin5.Deferred_RESOURCE_CONFIG_UNKNOWN, | ||
}, | ||
}, | ||
"Reason-ProviderConfigUnknown": { | ||
in: &tfprotov5.Deferred{ | ||
Reason: tfprotov5.DeferredReasonProviderConfigUnknown, | ||
}, | ||
|
||
expected: &tfplugin5.Deferred{ | ||
Reason: tfplugin5.Deferred_PROVIDER_CONFIG_UNKNOWN, | ||
}, | ||
}, | ||
"Reason-AbsentPrereq": { | ||
in: &tfprotov5.Deferred{ | ||
Reason: tfprotov5.DeferredReasonAbsentPrereq, | ||
}, | ||
|
||
expected: &tfplugin5.Deferred{ | ||
Reason: tfplugin5.Deferred_ABSENT_PREREQ, | ||
}, | ||
}, | ||
} | ||
|
||
for name, testCase := range testCases { | ||
name, testCase := name, testCase | ||
|
||
t.Run(name, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
got := toproto.Deferred(testCase.in) | ||
|
||
// Protocol Buffers generated types must have unexported fields | ||
// ignored or cmp.Diff() will raise an error. This is easier than | ||
// writing a custom Comparer for each type, which would have no | ||
// benefits. | ||
diffOpts := cmpopts.IgnoreUnexported( | ||
tfplugin5.Deferred{}, | ||
) | ||
|
||
if diff := cmp.Diff(got, testCase.expected, diffOpts); diff != "" { | ||
t.Errorf("unexpected difference: %s", diff) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.