github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/aws/resource_aws_elastic_transcoder_preset_test.go (about) 1 package aws 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/aws/aws-sdk-go/aws" 8 "github.com/aws/aws-sdk-go/aws/awserr" 9 "github.com/aws/aws-sdk-go/service/elastictranscoder" 10 "github.com/hashicorp/terraform/helper/resource" 11 "github.com/hashicorp/terraform/terraform" 12 ) 13 14 func TestAccAWSElasticTranscoderPreset_basic(t *testing.T) { 15 preset := &elastictranscoder.Preset{} 16 name := "aws_elastictranscoder_preset.bar" 17 18 // make sure the old preset was destroyed on each intermediate step 19 // these are very easy to leak 20 checkExists := func(replaced bool) resource.TestCheckFunc { 21 return func(s *terraform.State) error { 22 conn := testAccProvider.Meta().(*AWSClient).elastictranscoderconn 23 24 if replaced { 25 _, err := conn.ReadPreset(&elastictranscoder.ReadPresetInput{Id: preset.Id}) 26 if err != nil { 27 return nil 28 } 29 30 return fmt.Errorf("Preset Id %v should not exist", *preset.Id) 31 } 32 33 rs, ok := s.RootModule().Resources[name] 34 if !ok { 35 return fmt.Errorf("Not found: %s", name) 36 } 37 if rs.Primary.ID == "" { 38 return fmt.Errorf("No Preset ID is set") 39 } 40 41 out, err := conn.ReadPreset(&elastictranscoder.ReadPresetInput{ 42 Id: aws.String(rs.Primary.ID), 43 }) 44 45 if err != nil { 46 return err 47 } 48 49 preset = out.Preset 50 51 return nil 52 53 } 54 } 55 56 resource.Test(t, resource.TestCase{ 57 PreCheck: func() { testAccPreCheck(t) }, 58 Providers: testAccProviders, 59 CheckDestroy: testAccCheckElasticTranscoderPresetDestroy, 60 Steps: []resource.TestStep{ 61 resource.TestStep{ 62 Config: awsElasticTranscoderPresetConfig, 63 Check: resource.ComposeTestCheckFunc( 64 checkExists(false), 65 ), 66 }, 67 resource.TestStep{ 68 Config: awsElasticTranscoderPresetConfig2, 69 Check: resource.ComposeTestCheckFunc( 70 checkExists(true), 71 ), 72 }, 73 resource.TestStep{ 74 Config: awsElasticTranscoderPresetConfig3, 75 Check: resource.ComposeTestCheckFunc( 76 checkExists(true), 77 ), 78 }, 79 }, 80 }) 81 } 82 83 func testAccCheckElasticTranscoderPresetDestroy(s *terraform.State) error { 84 conn := testAccProvider.Meta().(*AWSClient).elastictranscoderconn 85 86 for _, rs := range s.RootModule().Resources { 87 if rs.Type != "aws_elastictranscoder_preset" { 88 continue 89 } 90 91 out, err := conn.ReadPreset(&elastictranscoder.ReadPresetInput{ 92 Id: aws.String(rs.Primary.ID), 93 }) 94 95 if err == nil { 96 if out.Preset != nil && *out.Preset.Id == rs.Primary.ID { 97 return fmt.Errorf("Elastic Transcoder Preset still exists") 98 } 99 } 100 101 awsErr, ok := err.(awserr.Error) 102 if !ok { 103 return err 104 } 105 106 if awsErr.Code() != "ResourceNotFoundException" { 107 return fmt.Errorf("unexpected error: %s", awsErr) 108 } 109 110 } 111 return nil 112 } 113 114 const awsElasticTranscoderPresetConfig = ` 115 resource "aws_elastictranscoder_preset" "bar" { 116 container = "mp4" 117 description = "elastic transcoder preset test 1" 118 name = "aws_elastictranscoder_preset_tf_test_" 119 120 audio { 121 audio_packing_mode = "SingleTrack" 122 bit_rate = 320 123 channels = 2 124 codec = "mp3" 125 sample_rate = 44100 126 } 127 } 128 ` 129 130 const awsElasticTranscoderPresetConfig2 = ` 131 resource "aws_elastictranscoder_preset" "bar" { 132 container = "mp4" 133 description = "elastic transcoder preset test 2" 134 name = "aws_elastictranscoder_preset_tf_test_" 135 136 audio { 137 audio_packing_mode = "SingleTrack" 138 bit_rate = 128 139 channels = 2 140 codec = "AAC" 141 sample_rate = 48000 142 } 143 144 audio_codec_options { 145 profile = "auto" 146 } 147 148 video { 149 bit_rate = "auto" 150 codec = "H.264" 151 display_aspect_ratio = "16:9" 152 fixed_gop = "true" 153 frame_rate = "auto" 154 keyframes_max_dist = 90 155 max_height = 1080 156 max_width = 1920 157 padding_policy = "Pad" 158 sizing_policy = "Fit" 159 } 160 161 video_codec_options { 162 Profile = "main" 163 Level = "4.1" 164 MaxReferenceFrames = 4 165 } 166 167 thumbnails { 168 format = "jpg" 169 interval = 5 170 max_width = 960 171 max_height = 540 172 padding_policy = "Pad" 173 sizing_policy = "Fit" 174 } 175 } 176 ` 177 178 const awsElasticTranscoderPresetConfig3 = ` 179 resource "aws_elastictranscoder_preset" "bar" { 180 container = "mp4" 181 description = "elastic transcoder preset test 3" 182 name = "aws_elastictranscoder_preset_tf_test_" 183 184 audio { 185 audio_packing_mode = "SingleTrack" 186 bit_rate = 96 187 channels = 2 188 codec = "AAC" 189 sample_rate = 44100 190 } 191 192 audio_codec_options { 193 profile = "AAC-LC" 194 } 195 196 video { 197 bit_rate = "1600" 198 codec = "H.264" 199 display_aspect_ratio = "16:9" 200 fixed_gop = "false" 201 frame_rate = "auto" 202 max_frame_rate = "60" 203 keyframes_max_dist = 240 204 max_height = "auto" 205 max_width = "auto" 206 padding_policy = "Pad" 207 sizing_policy = "Fit" 208 } 209 210 video_codec_options { 211 Profile = "main" 212 Level = "2.2" 213 MaxReferenceFrames = 3 214 InterlaceMode = "Progressive" 215 ColorSpaceConversionMode = "None" 216 } 217 218 video_watermarks { 219 id = "Terraform Test" 220 max_width = "20%" 221 max_height = "20%" 222 sizing_policy = "ShrinkToFit" 223 horizontal_align = "Right" 224 horizontal_offset = "10px" 225 vertical_align = "Bottom" 226 vertical_offset = "10px" 227 opacity = "55.5" 228 target = "Content" 229 } 230 231 thumbnails { 232 format = "png" 233 interval = 120 234 max_width = "auto" 235 max_height = "auto" 236 padding_policy = "Pad" 237 sizing_policy = "Fit" 238 } 239 } 240 `