Skip to content

Commit 96d8865

Browse files
authored
add acceptance testing docs (#39)
1 parent 8d7ce1c commit 96d8865

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

README.md

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,39 @@ method. `As` will return an error if the `Value` is not known.
7070

7171
## Testing
7272

73-
TODO: insert information here on how to use `helper/resource` to test
74-
providers written with terraform-plugin-go.
73+
The Terraform Plugin SDK's [`helper/resource`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource) package can be used to test providers written using terraform-plugin-go. While we are working on a testing framework for terraform-plugin-go providers that is independent of the Plugin SDK, this may take some time, so we recommend writing tests in the meantime using the plugin SDK, which will not be a runtime dependency of your provider.
74+
75+
You must supply a factory for your provider server by setting `ProtoV5ProviderFactories` on each [`TestCase`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource#TestCase). For example:
76+
77+
```go
78+
package myprovider
79+
80+
import (
81+
"regexp"
82+
"testing"
83+
84+
"github.com/hashicorp/terraform-plugin-go/tfprotov5"
85+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
86+
)
87+
88+
func TestAccDataSourceFoo(t *testing.T) {
89+
resource.UnitTest(t, resource.TestCase{
90+
ProtoV5ProviderFactories: map[string]func() (tfprotov5.ProviderServer, error){
91+
"myprovider": func() (tfprotov5.ProviderServer, error) {
92+
return Server(), nil
93+
},
94+
},
95+
Steps: []resource.TestStep{
96+
{
97+
Config: `"data" "myprovider_foo" "bar" {}`,
98+
Check: resource.ComposeTestCheckFunc(
99+
resource.TestMatchResourceAttr("data.myprovider_foo.bar", "current", regexp.MustCompile(`[0-9]+`)),
100+
),
101+
},
102+
},
103+
})
104+
}
105+
```
75106

76107
## Documentation
77108

0 commit comments

Comments
 (0)