github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/alicloud/data_source_alicloud_regions_test.go (about)

     1  package alicloud
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/hashicorp/terraform/helper/resource"
     7  )
     8  
     9  func TestAccAlicloudRegionsDataSource_regions(t *testing.T) {
    10  	resource.Test(t, resource.TestCase{
    11  		PreCheck:  func() { testAccPreCheck(t) },
    12  		Providers: testAccProviders,
    13  		Steps: []resource.TestStep{
    14  			{
    15  				Config: testAccCheckAlicloudRegionsDataSourceRegionsConfig,
    16  				Check: resource.ComposeTestCheckFunc(
    17  					testAccCheckAlicloudDataSourceID("data.alicloud_regions.region"),
    18  
    19  					resource.TestCheckResourceAttr("data.alicloud_regions.region", "name", "cn-beijing"),
    20  					resource.TestCheckResourceAttr("data.alicloud_regions.region", "current", "true"),
    21  
    22  					resource.TestCheckResourceAttr("data.alicloud_regions.region", "regions.#", "1"),
    23  
    24  					resource.TestCheckResourceAttr("data.alicloud_regions.region", "regions.0.id", "cn-beijing"),
    25  					resource.TestCheckResourceAttr("data.alicloud_regions.region", "regions.0.region_id", "cn-beijing"),
    26  					resource.TestCheckResourceAttr("data.alicloud_regions.region", "regions.0.local_name", "华北 2"),
    27  				),
    28  			},
    29  		},
    30  	})
    31  }
    32  
    33  func TestAccAlicloudRegionsDataSource_name(t *testing.T) {
    34  	resource.Test(t, resource.TestCase{
    35  		PreCheck:  func() { testAccPreCheck(t) },
    36  		Providers: testAccProviders,
    37  		Steps: []resource.TestStep{
    38  			{
    39  				Config: testAccCheckAlicloudRegionsDataSourceNameConfig,
    40  				Check: resource.ComposeTestCheckFunc(
    41  					testAccCheckAlicloudDataSourceID("data.alicloud_regions.name_filtered_region"),
    42  					resource.TestCheckResourceAttr("data.alicloud_regions.name_filtered_region", "name", "cn-hangzhou")),
    43  			},
    44  		},
    45  	})
    46  }
    47  
    48  func TestAccAlicloudRegionsDataSource_current(t *testing.T) {
    49  	resource.Test(t, resource.TestCase{
    50  		PreCheck:  func() { testAccPreCheck(t) },
    51  		Providers: testAccProviders,
    52  		Steps: []resource.TestStep{
    53  			{
    54  				Config: testAccCheckAlicloudRegionsDataSourceCurrentConfig,
    55  				Check: resource.ComposeTestCheckFunc(
    56  					testAccCheckAlicloudDataSourceID("data.alicloud_regions.current_filtered_region"),
    57  					resource.TestCheckResourceAttr("data.alicloud_regions.current_filtered_region", "current", "true"),
    58  				),
    59  			},
    60  		},
    61  	})
    62  }
    63  
    64  func TestAccAlicloudRegionsDataSource_empty(t *testing.T) {
    65  	resource.Test(t, resource.TestCase{
    66  		PreCheck:  func() { testAccPreCheck(t) },
    67  		Providers: testAccProviders,
    68  		Steps: []resource.TestStep{
    69  			{
    70  				Config: testAccCheckAlicloudRegionsDataSourceEmptyConfig,
    71  				Check: resource.ComposeTestCheckFunc(
    72  					testAccCheckAlicloudDataSourceID("data.alicloud_regions.empty_params_region"),
    73  
    74  					resource.TestCheckResourceAttr("data.alicloud_regions.empty_params_region", "regions.0.id", "cn-shenzhen"),
    75  					resource.TestCheckResourceAttr("data.alicloud_regions.empty_params_region", "regions.0.region_id", "cn-shenzhen"),
    76  					resource.TestCheckResourceAttr("data.alicloud_regions.empty_params_region", "regions.0.local_name", "华南 1"),
    77  				),
    78  			},
    79  		},
    80  	})
    81  }
    82  
    83  // Instance store test - using centos regions
    84  const testAccCheckAlicloudRegionsDataSourceRegionsConfig = `
    85  data "alicloud_regions" "region" {
    86  	name = "cn-beijing"
    87  	current = true
    88  }
    89  `
    90  
    91  // Testing name parameter
    92  const testAccCheckAlicloudRegionsDataSourceNameConfig = `
    93  data "alicloud_regions" "name_filtered_region" {
    94  	name = "cn-hangzhou"
    95  }
    96  `
    97  
    98  // Testing current parameter
    99  const testAccCheckAlicloudRegionsDataSourceCurrentConfig = `
   100  data "alicloud_regions" "current_filtered_region" {
   101  	current = true
   102  }
   103  `
   104  
   105  // Testing empty parmas
   106  const testAccCheckAlicloudRegionsDataSourceEmptyConfig = `
   107  data "alicloud_regions" "empty_params_region" {
   108  }
   109  `