@@ -3,65 +3,123 @@ package cvm_test
3
3
import (
4
4
"testing"
5
5
6
- tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest"
6
+ acctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest"
7
7
8
8
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
9
9
)
10
10
11
- // go test -i; go test -test.run TestAccTencentCloudEipsDataSource_basic -v
12
- func TestAccTencentCloudEipsDataSource_basic (t * testing.T ) {
11
+ func TestAccTencentCloudCvmEipsDataSource_Basic (t * testing.T ) {
13
12
t .Parallel ()
14
13
resource .Test (t , resource.TestCase {
15
- PreCheck : func () { tcacctest .AccPreCheck (t ) },
16
- Providers : tcacctest .AccProviders ,
17
- CheckDestroy : testAccCheckEipDestroy ,
14
+ PreCheck : func () {
15
+ acctest .AccPreCheck (t )
16
+ },
17
+ Providers : acctest .AccProviders ,
18
18
Steps : []resource.TestStep {
19
19
{
20
- Config : testAccEipsDataSource ,
21
- Check : resource .ComposeTestCheckFunc (
22
- tcacctest .AccCheckTencentCloudDataSourceID ("data.tencentcloud_eips.example" ),
23
- resource .TestCheckResourceAttr ("data.tencentcloud_eips.example" , "eip_list.#" , "0" ),
24
-
25
- tcacctest .AccCheckTencentCloudDataSourceID ("data.tencentcloud_eips.example_by_id" ),
26
- resource .TestCheckResourceAttr ("data.tencentcloud_eips.example_by_id" , "eip_list.#" , "1" ),
27
- resource .TestCheckResourceAttrSet ("data.tencentcloud_eips.example_by_id" , "eip_list.0.eip_id" ),
28
- resource .TestCheckResourceAttr ("data.tencentcloud_eips.example_by_id" , "eip_list.0.eip_name" , "tf-example" ),
29
- resource .TestCheckResourceAttrSet ("data.tencentcloud_eips.example_by_id" , "eip_list.0.eip_type" ),
30
- resource .TestCheckResourceAttrSet ("data.tencentcloud_eips.example_by_id" , "eip_list.0.status" ),
31
- resource .TestCheckResourceAttrSet ("data.tencentcloud_eips.example_by_id" , "eip_list.0.public_ip" ),
32
- resource .TestCheckResourceAttrSet ("data.tencentcloud_eips.example_by_id" , "eip_list.0.create_time" ),
33
-
34
- tcacctest .AccCheckTencentCloudDataSourceID ("data.tencentcloud_eips.example_by_name" ),
35
- resource .TestCheckResourceAttr ("data.tencentcloud_eips.example_by_name" , "eip_list.0.eip_name" , "tf-example" ),
36
-
37
- tcacctest .AccCheckTencentCloudDataSourceID ("data.tencentcloud_eips.example_by_tags" ),
38
- resource .TestCheckResourceAttr ("data.tencentcloud_eips.example_by_tags" , "eip_list.0.tags.test" , "test" ),
39
- ),
20
+ Config : testAccCvmEipsDataSource_BasicCreate ,
21
+ Check : resource .ComposeTestCheckFunc (acctest .AccCheckTencentCloudDataSourceID ("data.tencentcloud_eips.example" )),
40
22
},
41
23
},
42
24
})
43
25
}
44
26
45
- const testAccEipsDataSource = `
46
- resource "tencentcloud_eip" "example" {
47
- name = "tf-example"
27
+ const testAccCvmEipsDataSource_BasicCreate = `
28
+
29
+ data "tencentcloud_eips" "example" {
30
+ }
31
+
32
+ `
48
33
49
- tags = {
50
- "test" = "test"
51
- }
34
+ func TestAccTencentCloudCvmEipsDataSource_ById (t * testing.T ) {
35
+ t .Parallel ()
36
+ resource .Test (t , resource.TestCase {
37
+ PreCheck : func () {
38
+ acctest .AccPreCheck (t )
39
+ },
40
+ Providers : acctest .AccProviders ,
41
+ Steps : []resource.TestStep {
42
+ {
43
+ Config : testAccCvmEipsDataSource_ByIdCreate ,
44
+ Check : resource .ComposeTestCheckFunc (acctest .AccCheckTencentCloudDataSourceID ("data.tencentcloud_eips.example_by_id" ), resource .TestCheckResourceAttrSet ("data.tencentcloud_eips.example_by_id" , "eip_list.0.public_ip" ), resource .TestCheckResourceAttrSet ("data.tencentcloud_eips.example_by_id" , "eip_list.0.create_time" ), resource .TestCheckResourceAttr ("data.tencentcloud_eips.example_by_id" , "eip_list.#" , "1" ), resource .TestCheckResourceAttrSet ("data.tencentcloud_eips.example_by_id" , "eip_list.0.eip_id" ), resource .TestCheckResourceAttr ("data.tencentcloud_eips.example_by_id" , "eip_list.0.eip_name" , "tf-example" ), resource .TestCheckResourceAttrSet ("data.tencentcloud_eips.example_by_id" , "eip_list.0.eip_type" ), resource .TestCheckResourceAttrSet ("data.tencentcloud_eips.example_by_id" , "eip_list.0.status" )),
45
+ },
46
+ },
47
+ })
52
48
}
53
49
54
- data "tencentcloud_eips" "example" {}
50
+ const testAccCvmEipsDataSource_ByIdCreate = `
55
51
56
52
data "tencentcloud_eips" "example_by_id" {
57
- eip_id = tencentcloud_eip.example.id
53
+ eip_id = tencentcloud_eip.example.id
54
+ }
55
+ resource "tencentcloud_eip" "example" {
56
+
57
+ tags = {
58
+ test = "test"
59
+ }
60
+ name = "tf-example"
58
61
}
59
62
63
+ `
64
+
65
+ func TestAccTencentCloudCvmEipsDataSource_ByName (t * testing.T ) {
66
+ t .Parallel ()
67
+ resource .Test (t , resource.TestCase {
68
+ PreCheck : func () {
69
+ acctest .AccPreCheck (t )
70
+ },
71
+ Providers : acctest .AccProviders ,
72
+ Steps : []resource.TestStep {
73
+ {
74
+ Config : testAccCvmEipsDataSource_ByNameCreate ,
75
+ Check : resource .ComposeTestCheckFunc (acctest .AccCheckTencentCloudDataSourceID ("data.tencentcloud_eips.example_by_name" ), resource .TestCheckResourceAttr ("data.tencentcloud_eips.example_by_name" , "eip_list.0.eip_name" , "tf-example" )),
76
+ },
77
+ },
78
+ })
79
+ }
80
+
81
+ const testAccCvmEipsDataSource_ByNameCreate = `
82
+
60
83
data "tencentcloud_eips" "example_by_name" {
61
- eip_name = tencentcloud_eip.example.name
84
+ eip_name = tencentcloud_eip.example.name
85
+ }
86
+ resource "tencentcloud_eip" "example" {
87
+ name = "tf-example"
88
+
89
+ tags = {
90
+ test = "test"
91
+ }
62
92
}
63
93
94
+ `
95
+
96
+ func TestAccTencentCloudCvmEipsDataSource_ByTags (t * testing.T ) {
97
+ t .Parallel ()
98
+ resource .Test (t , resource.TestCase {
99
+ PreCheck : func () {
100
+ acctest .AccPreCheck (t )
101
+ },
102
+ Providers : acctest .AccProviders ,
103
+ Steps : []resource.TestStep {
104
+ {
105
+ Config : testAccCvmEipsDataSource_ByTagsCreate ,
106
+ Check : resource .ComposeTestCheckFunc (acctest .AccCheckTencentCloudDataSourceID ("data.tencentcloud_eips.example_by_tags" ), resource .TestCheckResourceAttr ("data.tencentcloud_eips.example_by_tags" , "eip_list.0.tags.test" , "test" )),
107
+ },
108
+ },
109
+ })
110
+ }
111
+
112
+ const testAccCvmEipsDataSource_ByTagsCreate = `
113
+
64
114
data "tencentcloud_eips" "example_by_tags" {
65
- tags = tencentcloud_eip.example.tags
115
+ tags = tencentcloud_eip.example.tags
66
116
}
117
+ resource "tencentcloud_eip" "example" {
118
+ name = "tf-example"
119
+
120
+ tags = {
121
+ test = "test"
122
+ }
123
+ }
124
+
67
125
`
0 commit comments