helper/schema: tests that all pass as I was trying to track down a bug

This commit is contained in:
Mitchell Hashimoto 2015-02-18 14:10:12 -08:00
parent 17680bb7ff
commit dd00001c9a
2 changed files with 127 additions and 0 deletions

View File

@ -2593,6 +2593,108 @@ func TestResourceDataState(t *testing.T) {
},
},
},
// #25
{
Schema: map[string]*Schema{
"ports": &Schema{
Type: TypeSet,
Optional: true,
Computed: true,
Elem: &Schema{Type: TypeInt},
Set: func(a interface{}) int {
return a.(int)
},
},
},
State: nil,
Diff: nil,
Set: map[string]interface{}{
"ports": []interface{}{},
},
Result: &terraform.InstanceState{
Attributes: map[string]string{
"ports.#": "0",
},
},
},
// #26
{
Schema: map[string]*Schema{
"ports": &Schema{
Type: TypeList,
Optional: true,
Computed: true,
Elem: &Schema{Type: TypeInt},
},
},
State: nil,
Diff: nil,
Set: map[string]interface{}{
"ports": []interface{}{},
},
Result: &terraform.InstanceState{
Attributes: map[string]string{
"ports.#": "0",
},
},
},
// #27 Set lists
{
Schema: map[string]*Schema{
"ports": &Schema{
Type: TypeList,
Optional: true,
Computed: true,
Elem: &Resource{
Schema: map[string]*Schema{
"index": &Schema{Type: TypeInt},
"uuids": &Schema{Type: TypeMap},
},
},
},
},
State: nil,
Diff: &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"ports.#": &terraform.ResourceAttrDiff{
NewComputed: true,
},
},
},
Set: map[string]interface{}{
"ports": []interface{}{
map[string]interface{}{
"index": 10,
"uuids": map[string]interface{}{
"80": "value",
},
},
},
},
Result: &terraform.InstanceState{
Attributes: map[string]string{
"ports.#": "1",
"ports.0.index": "10",
"ports.0.uuids.#": "1",
"ports.0.uuids.80": "value",
},
},
},
}
for i, tc := range cases {

View File

@ -2140,6 +2140,31 @@ func TestSchemaMap_Diff(t *testing.T) {
Err: false,
},
// #55 - Unset list in state, should not show up computed
{
Schema: map[string]*Schema{
"metadata_keys": &Schema{
Type: TypeList,
Optional: true,
Computed: true,
ForceNew: true,
Elem: &Schema{Type: TypeInt},
},
},
State: &terraform.InstanceState{
Attributes: map[string]string{
"metadata_keys.#": "0",
},
},
Config: map[string]interface{}{},
Diff: nil,
Err: false,
},
}
for i, tc := range cases {