Skip to content

Commit 405dc7a

Browse files
gitmknanonymous
andauthored
Feat/ci unit (#1534)
* fix: support ci unit * fix: modify ci service * fix: modify ci unit * fix: update example * feat: support sweeper * fix: perfect use case * fix: fix unit * fix: modify unit * fix: modify snapshot_template * fix: modify unit --------- Co-authored-by: anonymous <anonymous@mail.org>
1 parent 9faf079 commit 405dc7a

File tree

33 files changed

+2045
-512
lines changed

33 files changed

+2045
-512
lines changed

tencentcloud/resource_tc_ci_bucket_attachment_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func testAccCheckCiBucketAttachmentExists(re string) resource.TestCheckFunc {
9595
const testAccCiBucketAttachment = `
9696
9797
resource "tencentcloud_ci_bucket_attachment" "bucket_attachment" {
98-
bucket = "terraform-ci-1308919341"
98+
bucket = "terraform-ci-test-1308919341"
9999
}
100100
101101
`

tencentcloud/resource_tc_ci_media_animation_template.go

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,6 @@ resource "tencentcloud_ci_media_animation_template" "media_animation_template" {
2828
}
2929
}
3030
```
31-
32-
Import
33-
34-
ci media_animation_template can be imported using the bucket#templateId, e.g.
35-
36-
```
37-
terraform import tencentcloud_ci_media_animation_template.media_animation_template terraform-ci-xxxxxx#t18210645f96564eaf80e86b1f58c20152
38-
```
3931
*/
4032
package tencentcloud
4133

@@ -58,9 +50,9 @@ func resourceTencentCloudCiMediaAnimationTemplate() *schema.Resource {
5850
Read: resourceTencentCloudCiMediaAnimationTemplateRead,
5951
Update: resourceTencentCloudCiMediaAnimationTemplateUpdate,
6052
Delete: resourceTencentCloudCiMediaAnimationTemplateDelete,
61-
Importer: &schema.ResourceImporter{
62-
State: schema.ImportStatePassthrough,
63-
},
53+
// Importer: &schema.ResourceImporter{
54+
// State: schema.ImportStatePassthrough,
55+
// },
6456
Schema: map[string]*schema.Schema{
6557
"bucket": {
6658
Required: true,
@@ -244,7 +236,7 @@ func resourceTencentCloudCiMediaAnimationTemplateCreate(d *schema.ResourceData,
244236
if e != nil {
245237
return retryError(e)
246238
} else {
247-
log.Printf("[DEBUG]%s api[%s] success, request body [%v], response body [%v]\n", logId, "CreateMediaAnimationTemplate", request, result)
239+
log.Printf("[DEBUG]%s api[%s] success, request body [%+v], response body [%+v]\n", logId, "CreateMediaAnimationTemplate", request, result)
248240
}
249241
response = result
250242
return nil
@@ -287,11 +279,13 @@ func resourceTencentCloudCiMediaAnimationTemplateRead(d *schema.ResourceData, me
287279
return fmt.Errorf("resource `track` %s does not exist", d.Id())
288280
}
289281

282+
_ = d.Set("bucket", bucket)
283+
290284
if template.Name != "" {
291285
_ = d.Set("name", template.Name)
292286
}
293287

294-
mediaAnimationTemplate := template.Animation
288+
mediaAnimationTemplate := template.TransTpl
295289
if mediaAnimationTemplate != nil {
296290
if mediaAnimationTemplate.Container != nil {
297291
containerMap := map[string]interface{}{}
@@ -322,23 +316,26 @@ func resourceTencentCloudCiMediaAnimationTemplateRead(d *schema.ResourceData, me
322316
videoMap["fps"] = mediaAnimationTemplate.Video.Fps
323317
}
324318

325-
if mediaAnimationTemplate.Video.AnimateOnlyKeepKeyFrame != "" {
326-
videoMap["animate_only_keep_key_frame"] = mediaAnimationTemplate.Video.AnimateOnlyKeepKeyFrame
327-
}
319+
// if mediaAnimationTemplate.Video.AnimateOnlyKeepKeyFrame != "" {
320+
// videoMap["animate_only_keep_key_frame"] = mediaAnimationTemplate.Video.AnimateOnlyKeepKeyFrame
321+
// }
328322

329-
if mediaAnimationTemplate.Video.AnimateTimeIntervalOfFrame != "" {
330-
videoMap["animate_time_interval_of_frame"] = mediaAnimationTemplate.Video.AnimateTimeIntervalOfFrame
331-
}
323+
// if mediaAnimationTemplate.Video.AnimateTimeIntervalOfFrame != "" {
324+
// videoMap["animate_time_interval_of_frame"] = mediaAnimationTemplate.Video.AnimateTimeIntervalOfFrame
325+
// }
332326

333-
if mediaAnimationTemplate.Video.AnimateFramesPerSecond != "" {
334-
videoMap["animate_frames_per_second"] = mediaAnimationTemplate.Video.AnimateFramesPerSecond
335-
}
327+
// if mediaAnimationTemplate.Video.AnimateFramesPerSecond != "" {
328+
// videoMap["animate_frames_per_second"] = mediaAnimationTemplate.Video.AnimateFramesPerSecond
329+
// }
336330

337-
if mediaAnimationTemplate.Video.Quality != "" {
338-
videoMap["quality"] = mediaAnimationTemplate.Video.Quality
339-
}
331+
// if mediaAnimationTemplate.Video.Quality != "" {
332+
// videoMap["quality"] = mediaAnimationTemplate.Video.Quality
333+
// }
340334

341-
_ = d.Set("video", []interface{}{videoMap})
335+
err = d.Set("video", []interface{}{videoMap})
336+
if err != nil {
337+
return err
338+
}
342339
}
343340

344341
if mediaAnimationTemplate.TimeInterval != nil {
@@ -352,7 +349,10 @@ func resourceTencentCloudCiMediaAnimationTemplateRead(d *schema.ResourceData, me
352349
timeIntervalMap["duration"] = mediaAnimationTemplate.TimeInterval.Duration
353350
}
354351

355-
_ = d.Set("time_interval", []interface{}{timeIntervalMap})
352+
err = d.Set("time_interval", []interface{}{timeIntervalMap})
353+
if err != nil {
354+
return err
355+
}
356356
}
357357
}
358358

Lines changed: 119 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,146 @@
11
package tencentcloud
22

33
import (
4+
"context"
5+
"fmt"
6+
"strings"
47
"testing"
58

69
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
10+
"github.com/hashicorp/terraform-plugin-sdk/terraform"
711
)
812

13+
// go test -i; go test -test.run TestAccTencentCloudCiMediaAnimationTemplateResource_basic -v
914
func TestAccTencentCloudCiMediaAnimationTemplateResource_basic(t *testing.T) {
1015
t.Parallel()
16+
1117
resource.Test(t, resource.TestCase{
12-
PreCheck: func() {
13-
testAccPreCheck(t)
14-
},
15-
Providers: testAccProviders,
18+
PreCheck: func() { testAccPreCheck(t) },
19+
Providers: testAccProviders,
20+
CheckDestroy: testAccCheckCiMediaAnimationTemplateDestroy,
1621
Steps: []resource.TestStep{
1722
{
1823
Config: testAccCiMediaAnimationTemplate,
19-
Check: resource.ComposeTestCheckFunc(resource.TestCheckResourceAttrSet("tencentcloud_ci_media_animation_template.media_animation_template", "id")),
20-
},
21-
{
22-
ResourceName: "tencentcloud_ci_media_animation_template.media_animation_template",
23-
ImportState: true,
24-
ImportStateVerify: true,
24+
Check: resource.ComposeTestCheckFunc(
25+
testAccCheckCiMediaAnimationTemplateExists("tencentcloud_ci_media_animation_template.media_animation_template"),
26+
resource.TestCheckResourceAttrSet("tencentcloud_ci_media_animation_template.media_animation_template", "id"),
27+
resource.TestCheckResourceAttr("tencentcloud_ci_media_animation_template.media_animation_template", "bucket", defaultCiBucket),
28+
resource.TestCheckResourceAttr("tencentcloud_ci_media_animation_template.media_animation_template", "name", "animation_template_test"),
29+
resource.TestCheckResourceAttr("tencentcloud_ci_media_animation_template.media_animation_template", "container.#", "1"),
30+
resource.TestCheckResourceAttr("tencentcloud_ci_media_animation_template.media_animation_template", "container.0.format", "gif"),
31+
resource.TestCheckResourceAttr("tencentcloud_ci_media_animation_template.media_animation_template", "video.#", "1"),
32+
resource.TestCheckResourceAttr("tencentcloud_ci_media_animation_template.media_animation_template", "video.0.codec", "gif"),
33+
resource.TestCheckResourceAttr("tencentcloud_ci_media_animation_template.media_animation_template", "video.0.width", "1280"),
34+
resource.TestCheckResourceAttr("tencentcloud_ci_media_animation_template.media_animation_template", "video.0.height", ""),
35+
resource.TestCheckResourceAttr("tencentcloud_ci_media_animation_template.media_animation_template", "video.0.fps", "20"),
36+
// resource.TestCheckResourceAttr("tencentcloud_ci_media_animation_template.media_animation_template", "video.0.animate_only_keep_key_frame", "true"),
37+
resource.TestCheckResourceAttr("tencentcloud_ci_media_animation_template.media_animation_template", "time_interval.#", "1"),
38+
resource.TestCheckResourceAttr("tencentcloud_ci_media_animation_template.media_animation_template", "time_interval.0.start", "0"),
39+
resource.TestCheckResourceAttr("tencentcloud_ci_media_animation_template.media_animation_template", "time_interval.0.duration", "60"),
40+
),
2541
},
42+
// {
43+
// ResourceName: "tencentcloud_ci_media_animation_template.media_animation_template",
44+
// ImportState: true,
45+
// ImportStateVerify: true,
46+
// },
2647
},
2748
})
2849
}
2950

30-
const testAccCiMediaAnimationTemplate = `
51+
func testAccCheckCiMediaAnimationTemplateDestroy(s *terraform.State) error {
52+
logId := getLogId(contextNil)
53+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
54+
service := CiService{client: testAccProvider.Meta().(*TencentCloudClient).apiV3Conn}
55+
for _, rs := range s.RootModule().Resources {
56+
if rs.Type != "tencentcloud_ci_media_animation_template" {
57+
continue
58+
}
3159

32-
resource "tencentcloud_ci_media_animation_template" "media_animation_template" {
33-
name = &lt;nil&gt;
34-
container {
35-
format = &lt;nil&gt;
60+
idSplit := strings.Split(rs.Primary.ID, FILED_SP)
61+
if len(idSplit) != 2 {
62+
return fmt.Errorf("id is broken,%s", rs.Primary.ID)
63+
}
64+
bucket := idSplit[0]
65+
templateId := idSplit[1]
3666

37-
}
38-
video {
39-
codec = &lt;nil&gt;
40-
width = &lt;nil&gt;
41-
height = &lt;nil&gt;
42-
fps = &lt;nil&gt;
43-
animate_only_keep_key_frame = &lt;nil&gt;
44-
animate_time_interval_of_frame = &lt;nil&gt;
45-
animate_frames_per_second = &lt;nil&gt;
46-
quality = &lt;nil&gt;
67+
res, err := service.DescribeCiMediaTemplateById(ctx, bucket, templateId)
68+
if err != nil {
69+
return err
70+
}
4771

48-
}
49-
time_interval {
50-
start = &lt;nil&gt;
51-
duration = &lt;nil&gt;
72+
if res != nil {
73+
return fmt.Errorf("ci media animation template still exist, Id: %v\n", rs.Primary.ID)
74+
}
75+
}
76+
return nil
77+
}
78+
79+
func testAccCheckCiMediaAnimationTemplateExists(re string) resource.TestCheckFunc {
80+
return func(s *terraform.State) error {
81+
logId := getLogId(contextNil)
82+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
83+
service := CiService{client: testAccProvider.Meta().(*TencentCloudClient).apiV3Conn}
84+
85+
rs, ok := s.RootModule().Resources[re]
86+
if !ok {
87+
return fmt.Errorf("ci media animation template %s is not found", re)
88+
}
89+
if rs.Primary.ID == "" {
90+
return fmt.Errorf(" id is not set")
91+
}
5292

93+
idSplit := strings.Split(rs.Primary.ID, FILED_SP)
94+
if len(idSplit) != 2 {
95+
return fmt.Errorf("id is broken,%s", rs.Primary.ID)
96+
}
97+
bucket := idSplit[0]
98+
templateId := idSplit[1]
99+
100+
result, err := service.DescribeCiMediaTemplateById(ctx, bucket, templateId)
101+
if err != nil {
102+
return err
103+
}
104+
105+
if result == nil {
106+
return fmt.Errorf("ci media animation template not found, Id: %v", rs.Primary.ID)
107+
}
108+
109+
return nil
110+
}
111+
}
112+
113+
const testAccCiMediaAnimationTemplateVar = `
114+
variable "bucket" {
115+
default = "` + defaultCiBucket + `"
53116
}
117+
118+
`
119+
120+
const testAccCiMediaAnimationTemplate = testAccCiMediaAnimationTemplateVar + `
121+
122+
resource "tencentcloud_ci_media_animation_template" "media_animation_template" {
123+
bucket = var.bucket
124+
name = "animation_template_test"
125+
container {
126+
format = "gif"
127+
}
128+
video {
129+
codec = "gif"
130+
width = "1280"
131+
height = ""
132+
fps = "20"
133+
animate_only_keep_key_frame = ""
134+
animate_time_interval_of_frame = ""
135+
animate_frames_per_second = ""
136+
quality = ""
137+
138+
}
139+
time_interval {
140+
start = "0"
141+
duration = "60"
142+
143+
}
54144
}
55145
56146
`

tencentcloud/resource_tc_ci_media_concat_template.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ resource "tencentcloud_ci_media_concat_template" "media_concat_template" {
2626
codec = "H.264"
2727
width = "1280"
2828
height = ""
29-
bitrate = "1000"
29+
bitrate = "1000"
3030
fps = "25"
3131
crf = ""
3232
remove = ""
@@ -43,7 +43,7 @@ resource "tencentcloud_ci_media_concat_template" "media_concat_template" {
4343
enable_start_fadein = "true"
4444
start_fadein_time = "3"
4545
enable_end_fadeout = "false"
46-
end_fadeout_time = "0"
46+
end_fadeout_time = "0.1"
4747
enable_bgm_fade = "true"
4848
bgm_fade_time = "1.7"
4949
}
@@ -193,6 +193,7 @@ func resourceTencentCloudCiMediaConcatTemplate() *schema.Resource {
193193
"remove": {
194194
Type: schema.TypeString,
195195
Optional: true,
196+
Computed: true,
196197
Description: "Whether to delete the source audio stream, the value is true, false.",
197198
},
198199
"rotate": {
@@ -264,6 +265,7 @@ func resourceTencentCloudCiMediaConcatTemplate() *schema.Resource {
264265
"end_fadeout_time": {
265266
Type: schema.TypeString,
266267
Optional: true,
268+
Computed: true,
267269
Description: "fade out time, greater than 0, support floating point numbers.",
268270
},
269271
"enable_bgm_fade": {
@@ -469,6 +471,8 @@ func resourceTencentCloudCiMediaConcatTemplateRead(d *schema.ResourceData, meta
469471
return fmt.Errorf("resource `track` %s does not exist", d.Id())
470472
}
471473

474+
_ = d.Set("bucket", bucket)
475+
472476
if mediaConcatTemplate.Name != "" {
473477
_ = d.Set("name", mediaConcatTemplate.Name)
474478
}
@@ -488,7 +492,7 @@ func resourceTencentCloudCiMediaConcatTemplateRead(d *schema.ResourceData, meta
488492
}
489493
concatFragmentList = append(concatFragmentList, concatFragmentMap)
490494
}
491-
concatTemplateMap["concat_fragment"] = []interface{}{concatFragmentList}
495+
concatTemplateMap["concat_fragment"] = concatFragmentList
492496
}
493497

494498
if mediaConcatTemplate.ConcatTemplate.Audio != nil {
@@ -611,7 +615,7 @@ func resourceTencentCloudCiMediaConcatTemplateRead(d *schema.ResourceData, meta
611615
audioMixList = append(audioMixList, audioMixMap)
612616
}
613617

614-
concatTemplateMap["audio_mix"] = []interface{}{audioMixList}
618+
concatTemplateMap["audio_mix"] = audioMixList
615619
}
616620

617621
_ = d.Set("concat_template", []interface{}{concatTemplateMap})

0 commit comments

Comments
 (0)