@@ -2,6 +2,7 @@ package codefresh
2
2
3
3
import (
4
4
"fmt"
5
+ "reflect"
5
6
"regexp"
6
7
"testing"
7
8
@@ -165,7 +166,56 @@ func TestAccCodefreshPipeline_RuntimeEnvironment(t *testing.T) {
165
166
func TestAccCodefreshPipeline_OriginalYamlString (t * testing.T ) {
166
167
name := pipelineNamePrefix + acctest .RandString (10 )
167
168
resourceName := "codefresh_pipeline.test"
168
- originalYamlString := "version: \" 1.0\" \n fail_fast: false\n mode: parallel\n steps:\n test:\n image: alpine:latest\n commands:\n - echo \" ACC tests\" "
169
+ originalYamlString := `version: 1.0
170
+ fail_fast: false
171
+ stages:
172
+ - test
173
+ mode: parallel
174
+ hooks:
175
+ on_finish:
176
+ steps:
177
+ secondmycleanup:
178
+ commands:
179
+ - echo echo cleanup step
180
+ image: alpine:3.9
181
+ firstmynotification:
182
+ commands:
183
+ - echo Notify slack
184
+ image: cloudposse/slack-notifier
185
+ on_elected:
186
+ exec:
187
+ commands:
188
+ - echo 'Creating an adhoc test environment'
189
+ image: alpine:3.9
190
+ annotations:
191
+ set:
192
+ - annotations:
193
+ - my_annotation_example1: 10.45
194
+ - my_string_annotation: Hello World
195
+ entity_type: build
196
+ steps:
197
+ zz_firstStep:
198
+ stage: test
199
+ image: alpine
200
+ commands:
201
+ - echo Hello World First Step
202
+ aa_secondStep:
203
+ stage: test
204
+ image: alpine
205
+ commands:
206
+ - echo Hello World Second Step`
207
+
208
+ expectedSpecAttributes := & cfClient.Spec {
209
+ Steps : & cfClient.Steps {
210
+ Steps : `{"zz_firstStep":{"commands":["echo Hello World First Step"],"image":"alpine","stage":"test"},"aa_secondStep":{"commands":["echo Hello World Second Step"],"image":"alpine","stage":"test"}}` ,
211
+ },
212
+ Stages : & cfClient.Stages {
213
+ Stages : `["test"]` ,
214
+ },
215
+ Hooks : & cfClient.Hooks {
216
+ Hooks : `{"on_finish":{"steps":{"secondmycleanup":{"commands":["echo echo cleanup step"],"image":"alpine:3.9"},"firstmynotification":{"commands":["echo Notify slack"],"image":"cloudposse/slack-notifier"}}},"on_elected":{"exec":{"commands":["echo 'Creating an adhoc test environment'"],"image":"alpine:3.9"},"annotations":{"set":[{"annotations":[{"my_annotation_example1":10.45},{"my_string_annotation":"Hello World"}],"entity_type":"build"}]}}}` ,
217
+ },
218
+ }
169
219
170
220
resource .ParallelTest (t , resource.TestCase {
171
221
PreCheck : func () { testAccPreCheck (t ) },
@@ -178,6 +228,7 @@ func TestAccCodefreshPipeline_OriginalYamlString(t *testing.T) {
178
228
179
229
testAccCheckCodefreshPipelineExists (resourceName ),
180
230
resource .TestCheckResourceAttr (resourceName , "original_yaml_string" , originalYamlString ),
231
+ testAccCheckCodefreshPipelineOriginalYamlStringAttributePropagation (resourceName , expectedSpecAttributes ),
181
232
),
182
233
},
183
234
{
@@ -426,6 +477,38 @@ func testAccCheckCodefreshPipelineDestroy(s *terraform.State) error {
426
477
return nil
427
478
}
428
479
480
+ func testAccCheckCodefreshPipelineOriginalYamlStringAttributePropagation (resource string , spec * cfClient.Spec ) resource.TestCheckFunc {
481
+ return func (state * terraform.State ) error {
482
+
483
+ rs , ok := state .RootModule ().Resources [resource ]
484
+ if ! ok {
485
+ return fmt .Errorf ("Not found: %s" , resource )
486
+ }
487
+ if rs .Primary .ID == "" {
488
+ return fmt .Errorf ("No Record ID is set" )
489
+ }
490
+
491
+ pipelineID := rs .Primary .ID
492
+
493
+ apiClient := testAccProvider .Meta ().(* cfClient.Client )
494
+ pipeline , err := apiClient .GetPipeline (pipelineID )
495
+
496
+ if ! reflect .DeepEqual (pipeline .Spec .Steps , spec .Steps ) {
497
+ return fmt .Errorf ("Expected Step %v. Got %v" , spec .Steps , pipeline .Spec .Steps )
498
+ }
499
+ if ! reflect .DeepEqual (pipeline .Spec .Stages , spec .Stages ) {
500
+ return fmt .Errorf ("Expected Stages %v. Got %v" , spec .Stages , pipeline .Spec .Stages )
501
+ }
502
+ if ! reflect .DeepEqual (pipeline .Spec .Hooks , spec .Hooks ) {
503
+ return fmt .Errorf ("Expected Hooks %v. Got %v" , spec .Hooks , pipeline .Spec .Hooks )
504
+ }
505
+ if err != nil {
506
+ return fmt .Errorf ("error fetching pipeline with resource %s. %s" , resource , err )
507
+ }
508
+ return nil
509
+ }
510
+ }
511
+
429
512
// CONFIGS
430
513
func testAccCodefreshPipelineBasicConfig (rName , repo , path , revision , context string ) string {
431
514
return fmt .Sprintf (`
0 commit comments