mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-28 01:41:48 -06:00
add tests for deprecated/removed attrs
This commit is contained in:
parent
1b9a392c01
commit
9b89f6ecc6
@ -26,6 +26,7 @@ func Provider() terraform.ResourceProvider {
|
||||
"test_resource_nested": testResourceNested(),
|
||||
"test_resource_nested_set": testResourceNestedSet(),
|
||||
"test_resource_state_func": testResourceStateFunc(),
|
||||
"test_resource_deprecated": testResourceDeprecated(),
|
||||
},
|
||||
DataSourcesMap: map[string]*schema.Resource{
|
||||
"test_data_source": testDataSource(),
|
||||
|
119
builtin/providers/test/resource_deprecated.go
Normal file
119
builtin/providers/test/resource_deprecated.go
Normal file
@ -0,0 +1,119 @@
|
||||
package test
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
)
|
||||
|
||||
func testResourceDeprecated() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
Create: testResourceDeprecatedCreate,
|
||||
Read: testResourceDeprecatedRead,
|
||||
Update: testResourceDeprecatedUpdate,
|
||||
Delete: testResourceDeprecatedDelete,
|
||||
|
||||
Schema: map[string]*schema.Schema{
|
||||
"map_deprecated": {
|
||||
Type: schema.TypeMap,
|
||||
Optional: true,
|
||||
Deprecated: "deprecated",
|
||||
},
|
||||
"map_removed": {
|
||||
Type: schema.TypeMap,
|
||||
Optional: true,
|
||||
Removed: "removed",
|
||||
},
|
||||
"set_block_deprecated": {
|
||||
Type: schema.TypeSet,
|
||||
Optional: true,
|
||||
MaxItems: 1,
|
||||
Deprecated: "deprecated",
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"value": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
Deprecated: "deprecated",
|
||||
},
|
||||
"optional": {
|
||||
Type: schema.TypeString,
|
||||
ForceNew: true,
|
||||
Optional: true,
|
||||
Deprecated: "deprecated",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"set_block_removed": {
|
||||
Type: schema.TypeSet,
|
||||
Optional: true,
|
||||
MaxItems: 1,
|
||||
Removed: "Removed",
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"optional": {
|
||||
Type: schema.TypeString,
|
||||
ForceNew: true,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Removed: "removed",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"list_block_deprecated": {
|
||||
Type: schema.TypeList,
|
||||
Optional: true,
|
||||
Deprecated: "deprecated",
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"value": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
Deprecated: "deprecated",
|
||||
},
|
||||
"optional": {
|
||||
Type: schema.TypeString,
|
||||
ForceNew: true,
|
||||
Optional: true,
|
||||
Deprecated: "deprecated",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"list_block_removed": {
|
||||
Type: schema.TypeList,
|
||||
Optional: true,
|
||||
Removed: "removed",
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"optional": {
|
||||
Type: schema.TypeString,
|
||||
ForceNew: true,
|
||||
Optional: true,
|
||||
Removed: "removed",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func testResourceDeprecatedCreate(d *schema.ResourceData, meta interface{}) error {
|
||||
d.SetId("testId")
|
||||
return nil
|
||||
}
|
||||
|
||||
func testResourceDeprecatedRead(d *schema.ResourceData, meta interface{}) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func testResourceDeprecatedUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func testResourceDeprecatedDelete(d *schema.ResourceData, meta interface{}) error {
|
||||
d.SetId("")
|
||||
return nil
|
||||
}
|
71
builtin/providers/test/resource_deprecated_test.go
Normal file
71
builtin/providers/test/resource_deprecated_test.go
Normal file
@ -0,0 +1,71 @@
|
||||
package test
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/terraform/helper/resource"
|
||||
)
|
||||
|
||||
// an empty config should be ok, because no deprecated/removed fields are set.
|
||||
func TestResourceDeprecated_empty(t *testing.T) {
|
||||
resource.UnitTest(t, resource.TestCase{
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckResourceDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: strings.TrimSpace(`
|
||||
resource "test_resource_deprecated" "foo" {
|
||||
}
|
||||
`),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// Deprecated fields should still work
|
||||
func TestResourceDeprecated_deprecatedOK(t *testing.T) {
|
||||
resource.UnitTest(t, resource.TestCase{
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckResourceDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: strings.TrimSpace(`
|
||||
resource "test_resource_deprecated" "foo" {
|
||||
map_deprecated = {
|
||||
"a" = "b",
|
||||
}
|
||||
set_block_deprecated {
|
||||
value = "1"
|
||||
}
|
||||
list_block_deprecated {
|
||||
value = "2"
|
||||
}
|
||||
}
|
||||
`),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// Declaring an empty block should trigger the error
|
||||
func TestResourceDeprecated_removedBlocks(t *testing.T) {
|
||||
resource.UnitTest(t, resource.TestCase{
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckResourceDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: strings.TrimSpace(`
|
||||
resource "test_resource_deprecated" "foo" {
|
||||
set_block_removed {
|
||||
}
|
||||
list_block_removed {
|
||||
}
|
||||
}
|
||||
`),
|
||||
ExpectError: regexp.MustCompile("REMOVED"),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
Loading…
Reference in New Issue
Block a user