Skip to content

Commit

Permalink
fix cms diff bug and improve its testcases
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaozhu36 committed Apr 23, 2019
1 parent 6eb7e22 commit 1d66077
Show file tree
Hide file tree
Showing 14 changed files with 131 additions and 107 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ export ALICLOUD_ACCOUNT_SITE=International
```
The setting of acount site type can skip some unsupported cases automatically.

-> **Note:** At present, there is missing CMS contact group resource and please create manually a contact group by web console and set it by environment variable `ALICLOUD_CMS_CONTACT_GROUP`, like:
```
export ALICLOUD_CMS_CONTACT_GROUP=tf-testAccCms
```
Otherwise, all of resource `alicloud_cms_alarm's` test cases will be skipped.

## Refer

Alibaba Cloud Provider [Official Docs](https://www.terraform.io/docs/providers/alicloud/index.html)
Expand Down
3 changes: 2 additions & 1 deletion alicloud/data_source_alicloud_network_interfaces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package alicloud

import (
"fmt"
"github.com/hashicorp/terraform/helper/acctest"
"strings"
"testing"

"github.com/hashicorp/terraform/helper/acctest"
)

func TestAccAlicloudNetworkInterfacesDataSourceBasic(t *testing.T) {
Expand Down
14 changes: 0 additions & 14 deletions alicloud/diff_suppress_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ import (

"strings"

"reflect"
"sort"

"github.com/denverdino/aliyungo/common"
"github.com/denverdino/aliyungo/dns"
"github.com/denverdino/aliyungo/ecs"
Expand Down Expand Up @@ -270,17 +267,6 @@ func vpcTypeResourceDiffSuppressFunc(k, old, new string, d *schema.ResourceData)
return true
}

func cmsDimensionsDiffSuppressFunc(k, old, new string, d *schema.ResourceData) bool {
if d.IsNewResource() {
return false
}
olds := strings.Split(old, COMMA_SEPARATED)
sort.Strings(olds)
news := strings.Split(new, COMMA_SEPARATED)
sort.Strings(news)
return reflect.DeepEqual(olds, news)
}

func routerInterfaceAcceptsideDiffSuppressFunc(k, old, new string, d *schema.ResourceData) bool {
return d.Get("role").(string) == string(AcceptingSide)
}
Expand Down
13 changes: 8 additions & 5 deletions alicloud/import_alicloud_cms_alarm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,21 @@ import (
"github.com/hashicorp/terraform/helper/resource"
)

// At present, the provider does not support creating contact group resource, so you should add a contact group called "tf-acc-test-group"
// by web console manually before running the following test case.
func SkipTestAccAlicloudCmsAlarm_import(t *testing.T) {
// At present, the provider does not support creating contact group resource, so you should create manually a contact group
// by web console and set it by environment variable ALICLOUD_CMS_CONTACT_GROUP before running the following test case.
func TestAccAlicloudCmsAlarm_import(t *testing.T) {
resourceName := "alicloud_cms_alarm.basic"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() {
testAccPreCheck(t)
testAccPreCheckWithCmsContactGroupSetting(t)
},
Providers: testAccProviders,
CheckDestroy: testAccCheckCmsAlarmDestroy,
Steps: []resource.TestStep{
{
Config: testAccCmsAlarm_basic,
Config: testAccCmsAlarm_basic(cmsContactGroup),
},

{
Expand Down
3 changes: 2 additions & 1 deletion alicloud/import_alicloud_key_pair_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package alicloud

import (
"github.com/hashicorp/terraform/helper/acctest"
"testing"

"github.com/hashicorp/terraform/helper/acctest"

"github.com/hashicorp/terraform/helper/resource"
)

Expand Down
3 changes: 2 additions & 1 deletion alicloud/import_alicloud_network_interface_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package alicloud

import (
"github.com/hashicorp/terraform/helper/acctest"
"testing"

"github.com/hashicorp/terraform/helper/acctest"

"github.com/hashicorp/terraform/helper/resource"
)

Expand Down
7 changes: 7 additions & 0 deletions alicloud/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,10 @@ func testAccPreCheckWithMultipleAccount(t *testing.T) {
t.Skipped()
}
}

func testAccPreCheckWithCmsContactGroupSetting(t *testing.T) {
if v := strings.TrimSpace(os.Getenv("ALICLOUD_CMS_CONTACT_GROUP")); v == "" {
t.Skipf("Skipping the test case with no cms contact group setting")
t.Skipped()
}
}
9 changes: 4 additions & 5 deletions alicloud/resource_alicloud_cms_alarm.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,10 @@ func resourceAlicloudCmsAlarm() *schema.Resource {
ForceNew: true,
},
"dimensions": {
Type: schema.TypeMap,
Required: true,
ForceNew: true,
Elem: schema.TypeString,
DiffSuppressFunc: cmsDimensionsDiffSuppressFunc,
Type: schema.TypeMap,
Required: true,
ForceNew: true,
Elem: schema.TypeString,
},
"period": {
Type: schema.TypeInt,
Expand Down
Loading

0 comments on commit 1d66077

Please sign in to comment.