add more tests with carious set combinations

This commit is contained in:
James Bardin 2018-11-16 09:54:27 -05:00
parent 21dfa56766
commit 83317975fe
2 changed files with 90 additions and 1 deletions

View File

@ -23,6 +23,11 @@ func testResourceNestedSet() *schema.Resource {
Type: schema.TypeBool,
Optional: true,
},
"force_new": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"single": {
Type: schema.TypeSet,
Optional: true,

View File

@ -127,7 +127,7 @@ resource "test_resource_nested_set" "foo" {
},
})
}
func TestResourceNestedSet_multi(t *testing.T) {
func TestResourceNestedSet_multiAddRemove(t *testing.T) {
checkFunc := func(s *terraform.State) error {
return nil
}
@ -214,6 +214,25 @@ resource "test_resource_nested_set" "foo" {
optional_int = 3
}
}
}
`),
Check: checkFunc,
},
resource.TestStep{
Config: strings.TrimSpace(`
resource "test_resource_nested_set" "foo" {
optional = true
single {
value = "bar"
optional = "baz"
}
multi {
set {
required = "new"
optional_int = 3
}
}
}
`),
Check: checkFunc,
@ -221,3 +240,68 @@ resource "test_resource_nested_set" "foo" {
},
})
}
func TestResourceNestedSet_forceNewEmptyString(t *testing.T) {
var id string
step := 0
checkFunc := func(s *terraform.State) error {
root := s.ModuleByPath(addrs.RootModuleInstance)
res := root.Resources["test_resource_nested_set.foo"]
defer func() {
step++
id = res.Primary.ID
}()
if step == 2 && res.Primary.ID == id {
// setting an empty string currently does not trigger ForceNew, but
// it should in the future.
return nil
}
if res.Primary.ID == id {
return errors.New("expected new resource")
}
return nil
}
resource.UnitTest(t, resource.TestCase{
Providers: testAccProviders,
CheckDestroy: testAccCheckResourceDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: strings.TrimSpace(`
resource "test_resource_nested_set" "foo" {
multi {
set {
required = "val"
}
}
}
`),
Check: checkFunc,
},
resource.TestStep{
Config: strings.TrimSpace(`
resource "test_resource_nested_set" "foo" {
multi {
set {
required = ""
}
}
}
`),
Check: checkFunc,
},
resource.TestStep{
Config: strings.TrimSpace(`
resource "test_resource_nested_set" "foo" {
force_new = ""
}
`),
Check: checkFunc,
},
},
})
}