-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding function tests for protocol v5 and protocol v6 providers (#202)
- Loading branch information
1 parent
6653ce6
commit 9ddc360
Showing
8 changed files
with
234 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package protocol | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hashicorp/terraform-plugin-go/tfprotov5" | ||
"github.com/hashicorp/terraform-plugin-go/tftypes" | ||
) | ||
|
||
type functionBool struct{} | ||
|
||
func (f functionBool) CallFunction(context.Context, *tfprotov5.CallFunctionRequest) (*tfprotov5.CallFunctionResponse, error) { | ||
value, err := tfprotov5.NewDynamicValue(tftypes.Bool, tftypes.NewValue(tftypes.Bool, true)) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &tfprotov5.CallFunctionResponse{ | ||
Result: &value, | ||
}, nil | ||
} | ||
|
||
func (f functionBool) GetFunctions(context.Context, *tfprotov5.GetFunctionsRequest) (*tfprotov5.GetFunctionsResponse, error) { | ||
panic("implement me") | ||
} |
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,36 @@ | ||
package protocol | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-go/tfprotov5" | ||
"github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-testing/knownvalue" | ||
"github.com/hashicorp/terraform-plugin-testing/statecheck" | ||
"github.com/hashicorp/terraform-plugin-testing/tfversion" | ||
) | ||
|
||
func TestAccV5FunctionBool(t *testing.T) { | ||
resource.UnitTest(t, resource.TestCase{ | ||
TerraformVersionChecks: []tfversion.TerraformVersionCheck{ | ||
tfversion.SkipBelow(tfversion.Version1_8_0), | ||
}, | ||
ProtoV5ProviderFactories: map[string]func() (tfprotov5.ProviderServer, error){ | ||
//nolint:unparam // False positive in unparam related to map: https://github.com/mvdan/unparam/issues/40 | ||
"corner": func() (tfprotov5.ProviderServer, error) { | ||
return Server(), nil | ||
}, | ||
}, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: ` | ||
output "test" { | ||
value = provider::corner::bool(true) | ||
}`, | ||
ConfigStateChecks: []statecheck.StateCheck{ | ||
statecheck.ExpectKnownOutputValue("test", knownvalue.Bool(true)), | ||
}, | ||
}, | ||
}, | ||
}) | ||
} |
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,32 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package protocol | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hashicorp/terraform-plugin-go/tfprotov5" | ||
) | ||
|
||
type errUnsupportedFunction string | ||
|
||
func (e errUnsupportedFunction) Error() string { | ||
return "unsupported function: " + string(e) | ||
} | ||
|
||
type functionRouter map[string]tfprotov5.FunctionServer | ||
|
||
func (f functionRouter) CallFunction(ctx context.Context, req *tfprotov5.CallFunctionRequest) (*tfprotov5.CallFunctionResponse, error) { | ||
fu, ok := f[req.Name] | ||
|
||
if !ok { | ||
return nil, errUnsupportedFunction(req.Name) | ||
} | ||
|
||
return fu.CallFunction(ctx, req) | ||
} | ||
|
||
func (f functionRouter) GetFunctions(ctx context.Context, req *tfprotov5.GetFunctionsRequest) (*tfprotov5.GetFunctionsResponse, error) { | ||
panic("not implemented") | ||
} |
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,29 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package protocolv6 | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hashicorp/terraform-plugin-go/tfprotov6" | ||
"github.com/hashicorp/terraform-plugin-go/tftypes" | ||
) | ||
|
||
type functionBool struct{} | ||
|
||
func (f functionBool) CallFunction(context.Context, *tfprotov6.CallFunctionRequest) (*tfprotov6.CallFunctionResponse, error) { | ||
value, err := tfprotov6.NewDynamicValue(tftypes.Bool, tftypes.NewValue(tftypes.Bool, true)) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &tfprotov6.CallFunctionResponse{ | ||
Result: &value, | ||
}, nil | ||
} | ||
|
||
func (f functionBool) GetFunctions(context.Context, *tfprotov6.GetFunctionsRequest) (*tfprotov6.GetFunctionsResponse, error) { | ||
panic("implement me") | ||
} |
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,36 @@ | ||
package protocolv6 | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-go/tfprotov6" | ||
"github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-testing/knownvalue" | ||
"github.com/hashicorp/terraform-plugin-testing/statecheck" | ||
"github.com/hashicorp/terraform-plugin-testing/tfversion" | ||
) | ||
|
||
func TestAccV6FunctionBool(t *testing.T) { | ||
resource.UnitTest(t, resource.TestCase{ | ||
TerraformVersionChecks: []tfversion.TerraformVersionCheck{ | ||
tfversion.SkipBelow(tfversion.Version1_8_0), | ||
}, | ||
ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ | ||
//nolint:unparam // False positive in unparam related to map: https://github.com/mvdan/unparam/issues/40 | ||
"corner": func() (tfprotov6.ProviderServer, error) { | ||
return Server(), nil | ||
}, | ||
}, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: ` | ||
output "test" { | ||
value = provider::corner::bool(true) | ||
}`, | ||
ConfigStateChecks: []statecheck.StateCheck{ | ||
statecheck.ExpectKnownOutputValue("test", knownvalue.Bool(true)), | ||
}, | ||
}, | ||
}, | ||
}) | ||
} |
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,32 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package protocolv6 | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hashicorp/terraform-plugin-go/tfprotov6" | ||
) | ||
|
||
type errUnsupportedFunction string | ||
|
||
func (e errUnsupportedFunction) Error() string { | ||
return "unsupported function: " + string(e) | ||
} | ||
|
||
type functionRouter map[string]tfprotov6.FunctionServer | ||
|
||
func (f functionRouter) CallFunction(ctx context.Context, req *tfprotov6.CallFunctionRequest) (*tfprotov6.CallFunctionResponse, error) { | ||
fu, ok := f[req.Name] | ||
|
||
if !ok { | ||
return nil, errUnsupportedFunction(req.Name) | ||
} | ||
|
||
return fu.CallFunction(ctx, req) | ||
} | ||
|
||
func (f functionRouter) GetFunctions(ctx context.Context, req *tfprotov6.GetFunctionsRequest) (*tfprotov6.GetFunctionsResponse, error) { | ||
panic("not implemented") | ||
} |
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