Add import tests for google_cloudiot_registry (#2276)

<!-- This change is generated by MagicModules. -->
/cc @rileykarson
This commit is contained in:
The Magician 2018-10-17 15:11:23 -07:00 committed by Nathan McKinley
parent 1eda3c664b
commit d3ab42a60f
2 changed files with 28 additions and 16 deletions

View File

@ -76,6 +76,7 @@ func resourceCloudIoTRegistry() *schema.Resource {
},
"mqtt_config": &schema.Schema{
Type: schema.TypeMap,
Computed: true,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
@ -90,6 +91,7 @@ func resourceCloudIoTRegistry() *schema.Resource {
},
"http_config": &schema.Schema{
Type: schema.TypeMap,
Computed: true,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
@ -233,6 +235,11 @@ func resourceCloudIoTRegistryCreate(d *schema.ResourceData, meta interface{}) er
d.SetId("")
return err
}
// If we infer project and region, they are never actually set so we set them here
d.Set("project", project)
d.Set("region", region)
return resourceCloudIoTRegistryRead(d, meta)
}
@ -317,19 +324,9 @@ func resourceCloudIoTRegistryRead(d *schema.ResourceData, meta interface{}) erro
} else {
d.Set("state_notification_config", nil)
}
// If no config exist for mqtt or http config default values are omitted.
mqttState := res.MqttConfig.MqttEnabledState
_, hasMqttConfig := d.GetOk("mqtt_config")
if mqttState != mqttEnabled || hasMqttConfig {
d.Set("mqtt_config",
map[string]string{"mqtt_enabled_state": mqttState})
}
httpState := res.HttpConfig.HttpEnabledState
_, hasHttpConfig := d.GetOk("http_config")
if httpState != httpEnabled || hasHttpConfig {
d.Set("http_config",
map[string]string{"http_enabled_state": httpState})
}
d.Set("mqtt_config", map[string]string{"mqtt_enabled_state": res.MqttConfig.MqttEnabledState})
d.Set("http_config", map[string]string{"http_enabled_state": res.HttpConfig.HttpEnabledState})
credentials := make([]map[string]interface{}, len(res.Credentials))
for i, item := range res.Credentials {

View File

@ -9,7 +9,7 @@ import (
"github.com/hashicorp/terraform/terraform"
)
func TestAccCloudIoTRegistryCreate_basic(t *testing.T) {
func TestAccCloudIoTRegistry_basic(t *testing.T) {
t.Parallel()
registryName := fmt.Sprintf("psregistry-test-%s", acctest.RandString(10))
@ -26,11 +26,16 @@ func TestAccCloudIoTRegistryCreate_basic(t *testing.T) {
"google_cloudiot_registry.foobar"),
),
},
{
ResourceName: "google_cloudiot_registry.foobar",
ImportState: true,
ImportStateVerify: true,
},
},
})
}
func TestAccCloudIoTRegistryCreate_extended(t *testing.T) {
func TestAccCloudIoTRegistry_extended(t *testing.T) {
t.Parallel()
registryName := fmt.Sprintf("psregistry-test-%s", acctest.RandString(10))
@ -47,11 +52,16 @@ func TestAccCloudIoTRegistryCreate_extended(t *testing.T) {
"google_cloudiot_registry.foobar"),
),
},
{
ResourceName: "google_cloudiot_registry.foobar",
ImportState: true,
ImportStateVerify: true,
},
},
})
}
func TestAccCloudIoTRegistryUpdate(t *testing.T) {
func TestAccCloudIoTRegistry_update(t *testing.T) {
t.Parallel()
registryName := fmt.Sprintf("psregistry-test-%s", acctest.RandString(10))
@ -74,6 +84,11 @@ func TestAccCloudIoTRegistryUpdate(t *testing.T) {
resource.TestStep{
Config: testAccCloudIoTRegistry_basic(registryName),
},
{
ResourceName: "google_cloudiot_registry.foobar",
ImportState: true,
ImportStateVerify: true,
},
},
})
}