|
1 | 1 | package tencentcloud |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "context" |
| 5 | + "fmt" |
| 6 | + "strings" |
4 | 7 | "testing" |
5 | 8 |
|
6 | 9 | "github.com/hashicorp/terraform-plugin-sdk/helper/resource" |
| 10 | + "github.com/hashicorp/terraform-plugin-sdk/terraform" |
7 | 11 | ) |
8 | 12 |
|
| 13 | +// go test -i; go test -test.run TestAccTencentCloudCiMediaAnimationTemplateResource_basic -v |
9 | 14 | func TestAccTencentCloudCiMediaAnimationTemplateResource_basic(t *testing.T) { |
10 | 15 | t.Parallel() |
| 16 | + |
11 | 17 | 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, |
16 | 21 | Steps: []resource.TestStep{ |
17 | 22 | { |
18 | 23 | 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 | + ), |
25 | 41 | }, |
| 42 | + // { |
| 43 | + // ResourceName: "tencentcloud_ci_media_animation_template.media_animation_template", |
| 44 | + // ImportState: true, |
| 45 | + // ImportStateVerify: true, |
| 46 | + // }, |
26 | 47 | }, |
27 | 48 | }) |
28 | 49 | } |
29 | 50 |
|
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 | + } |
31 | 59 |
|
32 | | -resource "tencentcloud_ci_media_animation_template" "media_animation_template" { |
33 | | - name = <nil> |
34 | | - container { |
35 | | - format = <nil> |
| 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] |
36 | 66 |
|
37 | | - } |
38 | | - video { |
39 | | - codec = <nil> |
40 | | - width = <nil> |
41 | | - height = <nil> |
42 | | - fps = <nil> |
43 | | - animate_only_keep_key_frame = <nil> |
44 | | - animate_time_interval_of_frame = <nil> |
45 | | - animate_frames_per_second = <nil> |
46 | | - quality = <nil> |
| 67 | + res, err := service.DescribeCiMediaTemplateById(ctx, bucket, templateId) |
| 68 | + if err != nil { |
| 69 | + return err |
| 70 | + } |
47 | 71 |
|
48 | | - } |
49 | | - time_interval { |
50 | | - start = <nil> |
51 | | - duration = <nil> |
| 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 | + } |
52 | 92 |
|
| 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 + `" |
53 | 116 | } |
| 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 | + } |
54 | 144 | } |
55 | 145 |
|
56 | 146 | ` |
0 commit comments