Skip to content

Commit ccc4965

Browse files
committed
Saving my place
1 parent 45b23af commit ccc4965

27 files changed

+6431
-83
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
package querycheck
5+
6+
// AdditionalCLIOptions allows an intentionally limited set of options to be passed
7+
// to the Terraform CLI when executing test steps.
8+
type AdditionalCLIOptions struct {
9+
// Apply represents options to be passed to the `terraform apply` command.
10+
Apply ApplyOptions
11+
12+
// Plan represents options to be passed to the `terraform plan` command.
13+
Plan PlanOptions
14+
}
15+
16+
// ApplyOptions represents options to be passed to the `terraform apply` command.
17+
type ApplyOptions struct {
18+
// AllowDeferral will pass the experimental `-allow-deferral` flag to the apply command.
19+
AllowDeferral bool
20+
}
21+
22+
// PlanOptions represents options to be passed to the `terraform plan` command.
23+
type PlanOptions struct {
24+
// AllowDeferral will pass the experimental `-allow-deferral` flag to the plan command.
25+
AllowDeferral bool
26+
27+
// NoRefresh will pass the `-refresh=false` flag to the plan command.
28+
NoRefresh bool
29+
}

querycheck/contains_name_test.go

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,34 @@
1-
package querycheck_test
1+
package querycheck
22

33
import (
4+
"regexp"
5+
"testing"
6+
47
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
5-
r "github.com/hashicorp/terraform-plugin-testing/helper/resource"
68
"github.com/hashicorp/terraform-plugin-testing/internal/testing/testprovider"
79
"github.com/hashicorp/terraform-plugin-testing/internal/testing/testsdk/providerserver"
8-
"github.com/hashicorp/terraform-plugin-testing/querycheck"
910
"github.com/hashicorp/terraform-plugin-testing/tfversion"
10-
"regexp"
11-
"testing"
1211
)
1312

1413
func TestContainsResourceWithName(t *testing.T) {
1514
t.Parallel()
1615

17-
r.UnitTest(t, r.TestCase{
16+
UnitTest(t, TestCase{
1817
TerraformVersionChecks: []tfversion.TerraformVersionCheck{
1918
tfversion.SkipBelow(tfversion.Version1_14_0),
2019
},
2120
ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){
2221
"examplecloud": providerserver.NewProviderServer(testprovider.Provider{
2322
ListResources: map[string]testprovider.ListResource{
24-
2523
// TODO: define a simpler resource and list resource here or copy the `examplecloud_test.go` and `examplecloud_list_resource.go` files here for use
26-
27-
//"examplecloud_containerette": examplecloudListResource(),
24+
"examplecloud_containerette": examplecloudListResource(),
2825
},
2926
Resources: map[string]testprovider.Resource{
30-
//"examplecloud_containerette": examplecloudResource(),
27+
"examplecloud_containerette": examplecloudResource(),
3128
},
3229
}),
3330
},
34-
Steps: []r.TestStep{
31+
Steps: []TestStep{
3532
// We'll skip the first test step where we simulate creating the resource that will be returned when we query for it for simplicity.
3633
{
3734
Query: true,
@@ -54,13 +51,13 @@ func TestContainsResourceWithName(t *testing.T) {
5451
}
5552
}
5653
`,
57-
QueryResultChecks: []querycheck.QueryResultCheck{
58-
querycheck.ContainsResourceWithName("examplecloud_containerette.test", "banane"),
59-
querycheck.ContainsResourceWithName("examplecloud_containerette.test", "ananas"),
60-
querycheck.ContainsResourceWithName("examplecloud_containerette.test", "kiwi"),
61-
querycheck.ContainsResourceWithName("examplecloud_containerette.test2", "papaya"),
62-
querycheck.ContainsResourceWithName("examplecloud_containerette.test2", "birne"),
63-
querycheck.ContainsResourceWithName("examplecloud_containerette.test2", "kirsche"),
54+
QueryResultChecks: []QueryResultCheck{
55+
ContainsResourceWithName("examplecloud_containerette.test", "banane"),
56+
ContainsResourceWithName("examplecloud_containerette.test", "ananas"),
57+
ContainsResourceWithName("examplecloud_containerette.test", "kiwi"),
58+
ContainsResourceWithName("examplecloud_containerette.test2", "papaya"),
59+
ContainsResourceWithName("examplecloud_containerette.test2", "birne"),
60+
ContainsResourceWithName("examplecloud_containerette.test2", "kirsche"),
6461
},
6562
},
6663
},
@@ -71,24 +68,22 @@ func TestContainsResourceWithName(t *testing.T) {
7168
func TestContainsResourceWithName_NotFound(t *testing.T) {
7269
t.Parallel()
7370

74-
r.UnitTest(t, r.TestCase{
71+
UnitTest(t, TestCase{
7572
TerraformVersionChecks: []tfversion.TerraformVersionCheck{
7673
tfversion.SkipBelow(tfversion.Version1_14_0),
7774
},
7875
ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){
7976
"examplecloud": providerserver.NewProviderServer(testprovider.Provider{
8077
ListResources: map[string]testprovider.ListResource{
81-
82-
// TODO: define a resource and list resource here or copy the `examplecloud_test.go` and `examplecloud_list_resource.go` files here for use
83-
84-
//"examplecloud_containerette": examplecloudListResource(),
78+
// TODO: define a simpler resource and list resource here or copy the `examplecloud_test.go` and `examplecloud_list_resource.go` files here for use
79+
"examplecloud_containerette": examplecloudListResource(),
8580
},
8681
Resources: map[string]testprovider.Resource{
87-
//"examplecloud_containerette": examplecloudResource(),
82+
"examplecloud_containerette": examplecloudResource(),
8883
},
8984
}),
9085
},
91-
Steps: []r.TestStep{
86+
Steps: []TestStep{
9287
{
9388
Query: true,
9489
Config: `
@@ -110,8 +105,8 @@ func TestContainsResourceWithName_NotFound(t *testing.T) {
110105
}
111106
}
112107
`,
113-
QueryResultChecks: []querycheck.QueryResultCheck{
114-
querycheck.ContainsResourceWithName("examplecloud_containerette.test", "pflaume"),
108+
QueryResultChecks: []QueryResultCheck{
109+
ContainsResourceWithName("examplecloud_containerette.test", "pflaume"),
115110
},
116111
// TODO update expected error message to match what we output
117112
ExpectError: regexp.MustCompile("examplecloud_containerette.test - there are no pflaumen here!"),
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
package querycheck
5+
6+
// Environment variables for acceptance testing. Additional environment
7+
// variable constants can be found in the internal/plugintest package.
8+
const (
9+
// Environment variable to enable acceptance tests using this package's
10+
// ParallelTest and Test functions whose TestCase does not enable the
11+
// IsUnitTest field. Defaults to disabled, in which each test will call
12+
// (*testing.T).Skip(). Can be set to any value to enable acceptance tests,
13+
// however "1" is conventional.
14+
EnvTfAcc = "TF_ACC"
15+
16+
// Environment variable with hostname for the provider under acceptance
17+
// test. The hostname is the first portion of the full provider source
18+
// address, such as "example.com" in example.com/myorg/myprovider. Defaults
19+
// to "registry.terraform.io".
20+
//
21+
// Only required if any Terraform configuration set via the TestStep
22+
// type Config field includes a provider source, such as the terraform
23+
// configuration block required_providers attribute.
24+
EnvTfAccProviderHost = "TF_ACC_PROVIDER_HOST"
25+
26+
// Environment variable with namespace for the provider under acceptance
27+
// test. The namespace is the second portion of the full provider source
28+
// address, such as "myorg" in registry.terraform.io/myorg/myprovider.
29+
// Defaults to "-" for Terraform 0.12-0.13 compatibility and "hashicorp".
30+
//
31+
// Only required if any Terraform configuration set via the TestStep
32+
// type Config field includes a provider source, such as the terraform
33+
// configuration block required_providers attribute.
34+
EnvTfAccProviderNamespace = "TF_ACC_PROVIDER_NAMESPACE"
35+
36+
// This is an undocumented compatibility flag. When this is set, a
37+
// `Config`-mode test step will invoke a refresh before successful
38+
// completion.
39+
//
40+
// This is a compatibility measure for test cases that have different --
41+
// but semantically-equal -- state representations in their test steps.
42+
// When comparing two states, the testing framework is not aware of
43+
// semantic equality or set equality.
44+
EnvTfAccRefreshAfterApply = "TF_ACC_REFRESH_AFTER_APPLY"
45+
)

0 commit comments

Comments
 (0)