Skip to content

Commit

Permalink
Correcting documentation for revised naming of known value check types (
Browse files Browse the repository at this point in the history
  • Loading branch information
bendbennett committed Jan 15, 2024
1 parent 69f516d commit 66f9b5c
Show file tree
Hide file tree
Showing 17 changed files with 152 additions and 164 deletions.
25 changes: 25 additions & 0 deletions website/data/plugin-testing-nav-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,27 @@
}
]
},
{
"title": "State Checks",
"routes": [
{
"title": "Overview",
"path": "acceptance-tests/state-checks"
},
{
"title": "Resource State Checks",
"path": "acceptance-tests/state-checks/resource"
},
{
"title": "Output Plan Checks",
"path": "acceptance-tests/state-checks/output"
},
{
"title": "Custom Plan Checks",
"path": "acceptance-tests/state-checks/custom"
}
]
},
{
"title": "Known Value Checks",
"routes": [
Expand Down Expand Up @@ -81,6 +102,10 @@
"title": "Map",
"path": "acceptance-tests/known-value-checks/map"
},
{
"title": "Null",
"path": "acceptance-tests/known-value-checks/null"
},
{
"title": "Number",
"path": "acceptance-tests/known-value-checks/number"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ description: >-

The known value checks that are available for bool values are:

* [BoolValueExact](/terraform/plugin/testing/acceptance-tests/known-value-checks/bool#boolvalueexact-check)
* [BoolExact](/terraform/plugin/testing/acceptance-tests/known-value-checks/bool#boolexact-check)

## `BoolValueExact` Check
## `BoolExact` Check

The [BoolValueExact](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-testing/knownvalue#BoolValueExact) check tests that a resource attribute, or output value has an exactly matching bool value.
The [BoolExact](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-testing/knownvalue#BoolExact) check tests that a resource attribute, or output value has an exactly matching bool value.

Example usage of [BoolValueExact](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-testing/knownvalue#BoolValueExact) in an [ExpectKnownValue](/terraform/plugin/testing/acceptance-tests/plan-checks/resource) plan check.
Example usage of [BoolExact](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-testing/knownvalue#BoolExact) in an [ExpectKnownValue](/terraform/plugin/testing/acceptance-tests/plan-checks/resource) plan check.

```go
func TestExpectKnownValue_CheckPlan_Bool(t *testing.T) {
Expand All @@ -33,7 +33,7 @@ func TestExpectKnownValue_CheckPlan_Bool(t *testing.T) {
plancheck.ExpectKnownValue(
"test_resource.one",
tfjsonpath.New("bool_attribute"),
knownvalue.BoolValueExact(true),
knownvalue.BoolExact(true),
),
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ description: >-

The known value checks that are available for float64 values are:

* [Float64ValueExact](/terraform/plugin/testing/acceptance-tests/known-value-checks/float64#float64valueexact-check)
* [Float64Exact](/terraform/plugin/testing/acceptance-tests/known-value-checks/float64#float64exact-check)

## `Float64ValueExact` Check
## `Float64Exact` Check

The [Float64ValueExact](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-testing/knownvalue#Float64ValueExact) check tests that a resource attribute, or output value has an exactly matching float64 value.
The [Float64Exact](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-testing/knownvalue#Float64Exact) check tests that a resource attribute, or output value has an exactly matching float64 value.

Example usage of [Float64ValueExact](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-testing/knownvalue#Float64ValueExact) in an [ExpectKnownValue](/terraform/plugin/testing/acceptance-tests/plan-checks/resource) plan check.
Example usage of [Float64Exact](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-testing/knownvalue#Float64Exact) in an [ExpectKnownValue](/terraform/plugin/testing/acceptance-tests/plan-checks/resource) plan check.

```go
func TestExpectKnownValue_CheckPlan_Float64(t *testing.T) {
Expand All @@ -33,7 +33,7 @@ func TestExpectKnownValue_CheckPlan_Float64(t *testing.T) {
plancheck.ExpectKnownValue(
"test_resource.one",
tfjsonpath.New("float_attribute"),
knownvalue.Float64ValueExact(1.23),
knownvalue.Float64Exact(1.23),
),
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ Example uses in the testing module include:
The known value check types are implemented within the `terraform-plugin-testing` module in the [`knownvalue` package](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-testing/knownvalue). Known value checks are instantiated by calling the relevant constructor function.

```go
knownvalue.BoolValueExact(true)
knownvalue.BoolExact(true)
```

For known value checks that represent collections, or objects, nesting of known value checks can be used to define a "composite" known value check for use in asserting against a resource attribute, or output value that contains other values.

```go
knownvalue.ListValueExact([]knownvalue.Check{
knownvalue.StringValueExact("value1"),
knownvalue.StringValueExact("value2"),
knownvalue.ListExact([]knownvalue.Check{
knownvalue.StringExact("value1"),
knownvalue.StringExact("value2"),
})
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ description: >-

The known value checks that are available for int64 values are:

* [Int64ValueExact](/terraform/plugin/testing/acceptance-tests/known-value-checks/float64#int64valueexact-check)
* [Int64Exact](/terraform/plugin/testing/acceptance-tests/known-value-checks/float64#int64exact-check)

## `Int64ValueExact` Check
## `Int64Exact` Check

The [Int64ValueExact](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-testing/knownvalue#Int64ValueExact) check tests that a resource attribute, or output value has an exactly matching int64 value.
The [Int64Exact](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-testing/knownvalue#Int64Exact) check tests that a resource attribute, or output value has an exactly matching int64 value.

Example usage of [Int64ValueExact](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-testing/knownvalue#Int64ValueExact) in an [ExpectKnownValue](/terraform/plugin/testing/acceptance-tests/plan-checks/resource) plan check.
Example usage of [Int64Exact](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-testing/knownvalue#Int64Exact) in an [ExpectKnownValue](/terraform/plugin/testing/acceptance-tests/plan-checks/resource) plan check.

```go
func TestExpectKnownValue_CheckPlan_Int64(t *testing.T) {
Expand All @@ -33,7 +33,7 @@ func TestExpectKnownValue_CheckPlan_Int64(t *testing.T) {
plancheck.ExpectKnownValue(
"test_resource.one",
tfjsonpath.New("int_attribute"),
knownvalue.Int64ValueExact(123),
knownvalue.Int64Exact(123),
),
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@ description: >-

The known value checks that are available for list values are:

* [ListElementsExact](/terraform/plugin/testing/acceptance-tests/known-value-checks/list#listelementsexact-check)
* [ListValueExact](/terraform/plugin/testing/acceptance-tests/known-value-checks/list#listvalueexact-check)
* [ListValuePartialMatch](/terraform/plugin/testing/acceptance-tests/known-value-checks/list#listvaluepartialmatch-check)
* [ListExact](/terraform/plugin/testing/acceptance-tests/known-value-checks/list#listexact-check)
* [ListPartial](/terraform/plugin/testing/acceptance-tests/known-value-checks/list#listpartial-check)
* [ListSizeExact](/terraform/plugin/testing/acceptance-tests/known-value-checks/list#listsizeexact-check)

## `ListElementsExact` Check
## `ListExact` Check

The [ListElementsExact](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-testing/knownvalue#ListElementsExact) check tests that a resource attribute, or output value contains the specified number of elements.
The [ListExact](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-testing/knownvalue#ListExact) check tests that a resource attribute, or output value has an order-dependent, matching collection of element values.

Example usage of [ListElementsExact](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-testing/knownvalue#ListElementsExact) in an [ExpectKnownValue](/terraform/plugin/testing/acceptance-tests/plan-checks/resource) plan check.
Example usage of [ListExact](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-testing/knownvalue#ListExact) in an [ExpectKnownValue](/terraform/plugin/testing/acceptance-tests/plan-checks/resource) plan check.

```go
func TestExpectKnownValue_CheckPlan_ListElements(t *testing.T) {
func TestExpectKnownValue_CheckPlan_List(t *testing.T) {
t.Parallel()

resource.Test(t, resource.TestCase{
// Provider definition omitted.
// Provider definition omitted.
Steps: []resource.TestStep{
{
Config: `resource "test_resource" "one" {
Expand All @@ -38,7 +38,10 @@ func TestExpectKnownValue_CheckPlan_ListElements(t *testing.T) {
plancheck.ExpectKnownValue(
"test_resource.one",
tfjsonpath.New("list_attribute"),
knownvalue.ListElementsExact(2),
knownvalue.ListExact([]knownvalue.Check{
knownvalue.StringExact("value1"),
knownvalue.StringExact("value2"),
}),
),
},
},
Expand All @@ -48,18 +51,18 @@ func TestExpectKnownValue_CheckPlan_ListElements(t *testing.T) {
}
```

## `ListValueExact` Check
## `ListPartial` Check

The [ListValueExact](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-testing/knownvalue#ListValueExact) check tests that a resource attribute, or output value has an order-dependent, matching collection of element values.
The [ListPartial](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-testing/knownvalue#ListPartial) check tests that a resource attribute, or output value has matching element values for the specified collection indices.

Example usage of [ListValueExact](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-testing/knownvalue#ListValueExact) in an [ExpectKnownValue](/terraform/plugin/testing/acceptance-tests/plan-checks/resource) plan check.
Example usage of [ListPartial](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-testing/knownvalue#ListPartial) in an [ExpectKnownValue](/terraform/plugin/testing/acceptance-tests/plan-checks/resource) plan check. In this example, only the first element within the list, the element defined at index `0`, is checked.

```go
func TestExpectKnownValue_CheckPlan_List(t *testing.T) {
func TestExpectKnownValue_CheckPlan_ListPartial(t *testing.T) {
t.Parallel()

resource.Test(t, resource.TestCase{
// Provider definition omitted.
// Provider definition omitted.
Steps: []resource.TestStep{
{
Config: `resource "test_resource" "one" {
Expand All @@ -74,9 +77,8 @@ func TestExpectKnownValue_CheckPlan_List(t *testing.T) {
plancheck.ExpectKnownValue(
"test_resource.one",
tfjsonpath.New("list_attribute"),
knownvalue.ListValueExact([]knownvalue.Check{
knownvalue.StringValueExact("value1"),
knownvalue.StringValueExact("value2"),
knownvalue.ListPartial(map[int]knownvalue.Check{
0: knownvalue.StringExact("value1"),
}),
),
},
Expand All @@ -87,14 +89,14 @@ func TestExpectKnownValue_CheckPlan_List(t *testing.T) {
}
```

## `ListValuePartialMatch` Check
## `ListSizeExact` Check

The [ListValuePartialMatch](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-testing/knownvalue#ListValuePartialMatch) check tests that a resource attribute, or output value has matching element values for the specified collection indices.
The [ListSizeExact](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-testing/knownvalue#ListSizeExact) check tests that a resource attribute, or output value contains the specified number of elements.

Example usage of [ListValuePartialMatch](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-testing/knownvalue#ListValuePartialMatch) in an [ExpectKnownValue](/terraform/plugin/testing/acceptance-tests/plan-checks/resource) plan check. In this example, only the first element within the list, the element defined at index `0`, is checked.
Example usage of [ListSizeExact](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-testing/knownvalue#ListSizeExact) in an [ExpectKnownValue](/terraform/plugin/testing/acceptance-tests/plan-checks/resource) plan check.

```go
func TestExpectKnownValue_CheckPlan_ListPartial(t *testing.T) {
func TestExpectKnownValue_CheckPlan_ListElements(t *testing.T) {
t.Parallel()

resource.Test(t, resource.TestCase{
Expand All @@ -113,9 +115,7 @@ func TestExpectKnownValue_CheckPlan_ListPartial(t *testing.T) {
plancheck.ExpectKnownValue(
"test_resource.one",
tfjsonpath.New("list_attribute"),
knownvalue.ListValuePartialMatch(map[int]knownvalue.Check{
0: knownvalue.StringValueExact("value1"),
}),
knownvalue.ListSizeExact(2),
),
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ description: >-

The known value checks that are available for map values are:

* [MapElementsExact](/terraform/plugin/testing/acceptance-tests/known-value-checks/map#mapelementsexact-check)
* [MapValueExact](/terraform/plugin/testing/acceptance-tests/known-value-checks/map#mapvalueexact-check)
* [MapValuePartialMatch](/terraform/plugin/testing/acceptance-tests/known-value-checks/map#mapvaluepartialmatch-check)
* [MapExact](/terraform/plugin/testing/acceptance-tests/known-value-checks/map#mapexact-check)
* [MapPartial](/terraform/plugin/testing/acceptance-tests/known-value-checks/map#mappartial-check)
* [MapSizeExact](/terraform/plugin/testing/acceptance-tests/known-value-checks/map#mapsizeexact-check)

## `MapElementsExact` Check
## `MapExact` Check

The [MapElementsExact](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-testing/knownvalue#MapElementsExact) check tests that a resource attribute, or output value contains the specified number of elements.
The [MapExact](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-testing/knownvalue#MapExact) check tests that a resource attribute, or output value has a key-specified, matching collection of element values.

Example usage of [MapElementsExact](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-testing/knownvalue#MapElementsExact) in an [ExpectKnownValue](/terraform/plugin/testing/acceptance-tests/plan-checks/resource) plan check.
Example usage of [MapExact](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-testing/knownvalue#MapExact) in an [ExpectKnownValue](/terraform/plugin/testing/acceptance-tests/plan-checks/resource) plan check.

```go
func TestExpectKnownValue_CheckPlan_MapElements(t *testing.T) {
func TestExpectKnownValue_CheckPlan_Map(t *testing.T) {
t.Parallel()

resource.Test(t, resource.TestCase{
Expand All @@ -38,7 +38,10 @@ func TestExpectKnownValue_CheckPlan_MapElements(t *testing.T) {
plancheck.ExpectKnownValue(
"test_resource.one",
tfjsonpath.New("map_attribute"),
knownvalue.MapElementsExact(2),
knownvalue.MapExact(map[string]knownvalue.Check{
"key1": knownvalue.StringExact("value1"),
"key2": knownvalue.StringExact("value2"),
}),
),
},
},
Expand All @@ -48,14 +51,16 @@ func TestExpectKnownValue_CheckPlan_MapElements(t *testing.T) {
}
```

## `MapValueExact` Check
## `MapPartial` Check

The [MapValueExact](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-testing/knownvalue#MapValueExact) check tests that a resource attribute, or output value has a key-specified, matching collection of element values.
The [MapPartial](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-testing/knownvalue#MapPartial) check tests that a resource attribute, or output value has matching element values for the specified keys.

Example usage of [MapValueExact](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-testing/knownvalue#MapValueExact) in an [ExpectKnownValue](/terraform/plugin/testing/acceptance-tests/plan-checks/resource) plan check.
Example usage of [MapPartial](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-testing/knownvalue#MapPartial) in an [ExpectKnownValue](/terraform/plugin/testing/acceptance-tests/plan-checks/resource) plan check.

In this example, only the element associated with `key1` within the map is checked.

```go
func TestExpectKnownValue_CheckPlan_Map(t *testing.T) {
func TestExpectKnownValue_CheckPlan_MapPartial(t *testing.T) {
t.Parallel()

resource.Test(t, resource.TestCase{
Expand All @@ -74,9 +79,8 @@ func TestExpectKnownValue_CheckPlan_Map(t *testing.T) {
plancheck.ExpectKnownValue(
"test_resource.one",
tfjsonpath.New("map_attribute"),
knownvalue.MapValueExact(map[string]knownvalue.Check{
"key1": knownvalue.StringValueExact("value1"),
"key2": knownvalue.StringValueExact("value2"),
knownvalue.MapPartial(map[string]knownvalue.Check{
"key1": knownvalue.StringExact("value1"),
}),
),
},
Expand All @@ -87,16 +91,14 @@ func TestExpectKnownValue_CheckPlan_Map(t *testing.T) {
}
```

## `MapValuePartialMatch` Check
## `MapSizeExact` Check

The [MapValuePartialMatch](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-testing/knownvalue#MapValuePartialMatch) check tests that a resource attribute, or output value has matching element values for the specified keys.
The [MapSizeExact](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-testing/knownvalue#MapSizeExact) check tests that a resource attribute, or output value contains the specified number of elements.

Example usage of [MapValuePartialMatch](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-testing/knownvalue#MapValuePartialMatch) in an [ExpectKnownValue](/terraform/plugin/testing/acceptance-tests/plan-checks/resource) plan check.

In this example, only the element associated with `key1` within the map is checked.
Example usage of [MapSizeExact](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-testing/knownvalue#MapSizeExact) in an [ExpectKnownValue](/terraform/plugin/testing/acceptance-tests/plan-checks/resource) plan check.

```go
func TestExpectKnownValue_CheckPlan_MapPartial(t *testing.T) {
func TestExpectKnownValue_CheckPlan_MapElements(t *testing.T) {
t.Parallel()

resource.Test(t, resource.TestCase{
Expand All @@ -115,14 +117,12 @@ func TestExpectKnownValue_CheckPlan_MapPartial(t *testing.T) {
plancheck.ExpectKnownValue(
"test_resource.one",
tfjsonpath.New("map_attribute"),
knownvalue.MapValuePartialMatch(map[string]knownvalue.Check{
"key1": knownvalue.StringValueExact("value1"),
}),
knownvalue.MapSizeExact(2),
),
},
},
},
},
})
}
```
```
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ description: >-

The known value checks that are available for null values are:

* [NullValueExact](/terraform/plugin/testing/acceptance-tests/known-value-checks/null#nullvalueexact-check)
* [NullExact](/terraform/plugin/testing/acceptance-tests/known-value-checks/null#nullexact-check)

## `NullValueExact` Check
## `NullExact` Check

The [NullValueExact](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-testing/knownvalue#NullValueExact) check tests that a resource attribute, or output value has an exactly matching null value.
The [NullExact](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-testing/knownvalue#NullExact) check tests that a resource attribute, or output value has an exactly matching null value.

Example usage of [NullValueExact](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-testing/knownvalue#NullValueExact) in an [ExpectKnownValue](/terraform/plugin/testing/acceptance-tests/state-checks/resource) state check.
Example usage of [NullExact](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-testing/knownvalue#NullExact) in an [ExpectKnownValue](/terraform/plugin/testing/acceptance-tests/state-checks/resource) state check.

```go
func TestExpectKnownValue_CheckState_AttributeValueNull(t *testing.T) {
Expand All @@ -29,7 +29,7 @@ func TestExpectKnownValue_CheckState_AttributeValueNull(t *testing.T) {
statecheck.ExpectKnownValue(
"test_resource.one",
tfjsonpath.New("bool_attribute"),
knownvalue.NullValueExact(),
knownvalue.NullExact(),
),
},
},
Expand Down
Loading

0 comments on commit 66f9b5c

Please sign in to comment.