Skip to content

Commit c3942ef

Browse files
committed
Removing links and making examples generic on migration - testing page (#418)
1 parent ec28812 commit c3942ef

File tree

1 file changed

+21
-38
lines changed

1 file changed

+21
-38
lines changed

website/docs/plugin/framework/migrating/testing.mdx

+21-38
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,13 @@ the Framework.
2828

2929
### Example
3030

31-
The following example is taken from
32-
[v3.0.1](https://github.com/hashicorp/terraform-provider-http/blob/v3.0.1/internal/provider/data_source_http_test.go)
33-
of the http provider.
34-
3531
This example shows how you can use external providers to generate a state file with a previous version of the provider
3632
and then verify that there are no planned changes after migrating to the Framework.
3733

38-
- The first `TestStep` uses `ExternalProviders` to cause `terraform apply` to execute with `v2.2.0` of the http
34+
- The first `TestStep` uses `ExternalProviders` to cause `terraform apply` to execute with a previous version of the
3935
provider, which is built on SDKv2.
40-
- The second `TestStep` uses `ProtoV5ProviderFactories` so that the test uses the provider code contained within your
41-
repository. The second step also uses `PlanOnly` to verify that a no-op plan is generated.
36+
- The second `TestStep` uses `ProtoV5ProviderFactories` so that the test uses the provider code contained within the
37+
http provider repository. The second step also uses `PlanOnly` to verify that a no-op plan is generated.
4238

4339
```go
4440
func TestDataSource_UpgradeFromVersion2_2_0(t *testing.T) {
@@ -47,26 +43,24 @@ func TestDataSource_UpgradeFromVersion2_2_0(t *testing.T) {
4743
Steps: []resource.TestStep{
4844
{
4945
ExternalProviders: map[string]resource.ExternalProvider{
50-
"http": {
51-
VersionConstraint: "2.2.0",
52-
Source: "hashicorp/http",
46+
"<provider>": {
47+
VersionConstraint: "<sdk_version>",
48+
Source: "hashicorp/<provider>",
5349
},
5450
},
55-
Config: fmt.Sprintf(`
56-
data "http" "http_test" {
57-
url = "%s/200"
58-
}`, testHttpMock.server.URL),
51+
Config: `data "provider_datasource" "example" {
52+
/* ... */
53+
}`,
5954
Check: resource.ComposeTestCheckFunc(
60-
resource.TestCheckResourceAttr("data.http.http_test", "response_body", "1.0.0"),
55+
resource.TestCheckResourceAttr("data.provider_datasource.example", "<attribute>", "<value>"),
6156
/* ... */
6257
),
6358
},
6459
{
6560
ProtoV5ProviderFactories: protoV5ProviderFactories(),
66-
Config: fmt.Sprintf(`
67-
data "http" "http_test" {
68-
url = "%s/200"
69-
}`, testHttpMock.server.URL),
61+
Config: `data "provider_datasource" "example" {
62+
/* ... */
63+
}`,
7064
PlanOnly: true,
7165
},
7266
},
@@ -109,21 +103,12 @@ resource.UnitTest(t, resource.TestCase{
109103
110104
### Example
111105
112-
The following examples show how to migrate portions of the [http](https://github.com/hashicorp/terraform-provider-http)
113-
provider.
114-
115-
To review a complete example, clone the
116-
`terraform-provider-http` repository and compare the `data_source_test.go` file in
117-
[v2.2.0](https://github.com/hashicorp/terraform-provider-http/blob/v2.2.0/internal/provider/data_source_test.go) with the `data_source_http_test.go` file in
118-
[v3.0.1](https://github.com/hashicorp/terraform-provider-http/blob/v3.0.1/internal/provider/data_source_http_test.go).
119-
120106
#### SDKv2
121107
122-
The following code sample is from the `data_source_http_test.go` file and shows how to define provider factories within
123-
a test case when using SDKv2.
108+
The following code sample shows how to define provider factories within a test case when using SDKv2.
124109
125110
```go
126-
func TestDataSource_http200(t *testing.T) {
111+
func TestDataSource_Exmple(t *testing.T) {
127112
/* ... */
128113
resource.UnitTest(t, resource.TestCase{
129114
ProviderFactories: testProviders(),
@@ -132,24 +117,22 @@ func TestDataSource_http200(t *testing.T) {
132117
}
133118
```
134119
135-
The following code sample is from the `provider_test.go` file and shows how to generate provider factories when using
136-
SDKv2.
120+
The following shows how to generate provider factories when using SDKv2.
137121
138122
```go
139123
func testProviders() map[string]func() (*schema.Provider, error) {
140124
return map[string]func() (*schema.Provider, error){
141-
"http": func() (*schema.Provider, error) { return New(), nil },
125+
"example": func() (*schema.Provider, error) { return New(), nil },
142126
}
143127
}
144128
```
145129
146130
#### Framework
147131
148-
The following code sample is from the `data_source_http_test.go` file and shows how to define provider factories within
149-
a test case when using the Framework.
132+
The following shows how to define provider factories within a test case when using the Framework.
150133
151134
```go
152-
func TestDataSource_200(t *testing.T) {
135+
func TestDataSource_Example(t *testing.T) {
153136
/* ... */
154137

155138
resource.UnitTest(t, resource.TestCase{
@@ -159,14 +142,14 @@ func TestDataSource_200(t *testing.T) {
159142
}
160143
```
161144
162-
The following code sample is from the `provider_test.go` file and shows how to generate provider factories when using
145+
The following shows how to generate provider factories when using
163146
the Framework. The call to `New` returns an instance of the provider. Refer to
164147
[Provider Definition](/plugin/framework/migrating/providers#provider-definition) in this guide for details.
165148
166149
```go
167150
func protoV5ProviderFactories() map[string]func() (tfprotov5.ProviderServer, error) {
168151
return map[string]func() (tfprotov5.ProviderServer, error){
169-
"http": providerserver.NewProtocol5WithError(New()),
152+
"example": providerserver.NewProtocol5WithError(New()),
170153
}
171154
}
172155
```

0 commit comments

Comments
 (0)