Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider replacing usage of built-in TestCheckFunc with state checks #222

Open
bendbennett opened this issue Mar 6, 2024 · 0 comments
Open
Labels
enhancement New feature or request

Comments

@bendbennett
Copy link
Contributor

Many of the tests within terraform-provider-corner make use of TestCheckFunc built-in functions from terraform-plugin-testing for verifying values in state. For instance, TestCheckResourceAttr:

func TestAccResourceUser(t *testing.T) {
	resource.UnitTest(t, resource.TestCase{
		ProtoV5ProviderFactories: map[string]func() (tfprotov5.ProviderServer, error){
			"tf5muxprovider": func() (tfprotov5.ProviderServer, error) {
				provider, err := New()

				return provider(), err
			},
		},
		Steps: []resource.TestStep{
			{
				Config: configResourceUserBasic,
				Check: resource.ComposeTestCheckFunc(
					resource.TestCheckResourceAttr("tf5muxprovider_user1.example", "age", "123"),
					/* ... */
				),
			},
		},
	})
}

Such tests could be updated to use the new style state checks that are now available, for example:

func TestAccResourceUser(t *testing.T) {
	resource.UnitTest(t, resource.TestCase{
		ProtoV5ProviderFactories: map[string]func() (tfprotov5.ProviderServer, error){
			"tf5muxprovider": func() (tfprotov5.ProviderServer, error) {
				provider, err := New()

				return provider(), err
			},
		},
		Steps: []resource.TestStep{
			{
				Config: configResourceUserBasic,
				ConfigStateChecks: []statecheck.StateCheck{
					statecheck.ExpectKnownValue(
						"tf5muxprovider_user1.example",
						tfjsonpath.New("age"),
						knownvalue.Int64Exact(123),
					),
					/* ... */
				},
			},
		},
	})
}
@bendbennett bendbennett added the enhancement New feature or request label Mar 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant