-
Notifications
You must be signed in to change notification settings - Fork 60
/
go_cd_configurator_test.py
executable file
·2309 lines (1884 loc) · 114 KB
/
go_cd_configurator_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import unittest
import xml.etree.ElementTree as ET
import os
from decimal import Decimal
from xml.dom.minidom import parseString
from gomatic import (
ExecTask,
FetchArtifactDir,
FetchArtifactFile,
FetchArtifactTask,
GitMaterial,
GoCdConfigurator,
Pipeline,
PipelineMaterial,
RakeTask,
Security,
Tab
)
from gomatic.fake import FakeHostRestClient, config, config_18_3_0, empty_config, empty_config_xml, load_file
from gomatic.gocd.artifacts import Artifact, ArtifactFor, BuildArtifact, TestArtifact, ExternalArtifact
from gomatic.gocd.artifact_stores import ArtifactStores, ArtifactStore
from gomatic.gocd.pipelines import DEFAULT_LABEL_TEMPLATE
from gomatic.xml_operations import prettify
def find_with_matching_name(things, name):
return [thing for thing in things if thing.name == name]
def standard_pipeline_group():
return GoCdConfigurator(config('config-with-typical-pipeline')).ensure_pipeline_group('P.Group')
def typical_pipeline():
return standard_pipeline_group().find_pipeline('typical')
def more_options_pipeline():
return GoCdConfigurator(config('config-with-more-options-pipeline')).ensure_pipeline_group('P.Group').find_pipeline('more-options')
def more_options_pipeline_with_artifacts_type():
return GoCdConfigurator(config('config-with-more-options-pipeline-including-artifacts-type')).ensure_pipeline_group('P.Group').find_pipeline('more-options')
def more_options_pipeline_with_external_artifacts():
return GoCdConfigurator(config_18_3_0('config-with-more-options-pipeline-including-artifacts-type')).ensure_pipeline_group('P.Group').find_pipeline('more-options')
def empty_pipeline():
return GoCdConfigurator(empty_config()).ensure_pipeline_group("pg").ensure_pipeline("pl").set_git_url("gurl")
def empty_stage():
return empty_pipeline().ensure_stage("deploy-to-dev")
class TestAgents(unittest.TestCase):
def _agents_from_config(self):
return GoCdConfigurator(config('config-with-just-agents')).agents
def test_could_have_no_agents(self):
agents = GoCdConfigurator(empty_config()).agents
self.assertEqual(0, len(agents))
def test_agents_have_resources(self):
agents = self._agents_from_config()
self.assertEqual(2, len(agents))
self.assertEqual({'a-resource', 'b-resource'}, agents[0].resources)
def test_agents_have_names(self):
agents = self._agents_from_config()
self.assertEqual('go-agent-1', agents[0].hostname)
self.assertEqual('go-agent-2', agents[1].hostname)
def test_agent_could_have_no_resources(self):
agents = self._agents_from_config()
self.assertEqual(0, len(agents[1].resources))
def test_can_add_resource_to_agent_with_no_resources(self):
agent = self._agents_from_config()[1]
agent.ensure_resource('a-resource-that-it-does-not-already-have')
self.assertEqual(1, len(agent.resources))
def test_can_add_resource_to_agent(self):
agent = self._agents_from_config()[0]
self.assertEqual(2, len(agent.resources))
agent.ensure_resource('a-resource-that-it-does-not-already-have')
self.assertEqual(3, len(agent.resources))
class TestJobs(unittest.TestCase):
def test_jobs_have_resources(self):
stages = typical_pipeline().stages
job = stages[0].jobs[0]
resources = job.resources
self.assertEqual(1, len(resources))
self.assertEqual({'a-resource'}, resources)
def test_job_has_nice_tostring(self):
job = typical_pipeline().stages[0].jobs[0]
self.assertEqual("Job('compile', [ExecTask(['make', 'options', 'source code'])])", str(job))
def test_jobs_can_have_timeout(self):
job = typical_pipeline().ensure_stage("deploy").ensure_job("upload")
self.assertEqual(True, job.has_timeout)
self.assertEqual('20', job.timeout)
def test_can_set_timeout(self):
job = empty_stage().ensure_job("j")
j = job.set_timeout("42")
self.assertEqual(j, job)
self.assertEqual(True, job.has_timeout)
self.assertEqual('42', job.timeout)
def test_jobs_do_not_have_to_have_timeout(self):
stages = typical_pipeline().stages
job = stages[0].jobs[0]
self.assertEqual(False, job.has_timeout)
try:
timeout = job.timeout
self.fail("should have thrown exception")
except RuntimeError:
pass
def test_jobs_can_run_on_all_agents(self):
job = more_options_pipeline().ensure_stage("earlyStage").ensure_job("earlyWorm")
self.assertEqual(True, job.runs_on_all_agents)
def test_jobs_do_not_have_to_run_on_all_agents(self):
job = typical_pipeline().ensure_stage("build").ensure_job("compile")
self.assertEqual(False, job.runs_on_all_agents)
def test_jobs_can_be_made_to_run_on_all_agents(self):
job = typical_pipeline().ensure_stage("build").ensure_job("compile")
j = job.set_runs_on_all_agents()
self.assertEqual(j, job)
self.assertEqual(True, job.runs_on_all_agents)
def test_jobs_can_be_made_to_not_run_on_all_agents(self):
job = typical_pipeline().ensure_stage("build").ensure_job("compile")
j = job.set_runs_on_all_agents(False)
self.assertEqual(j, job)
self.assertEqual(False, job.runs_on_all_agents)
def test_jobs_can_have_elastic_profile_id(self):
job = typical_pipeline().ensure_stage("package").ensure_job("docker")
self.assertEqual(True, job.has_elastic_profile_id)
self.assertEqual('docker.unit-test', job.elastic_profile_id)
def test_can_set_elastic_profile_id(self):
job = empty_stage().ensure_job("j")
j = job.set_elastic_profile_id("docker.unit-test")
self.assertEqual(j, job)
self.assertEqual(True, job.has_elastic_profile_id)
self.assertEqual('docker.unit-test', job.elastic_profile_id)
def test_jobs_do_not_have_to_have_elastic_profile_id(self):
stages = typical_pipeline().stages
job = stages[0].jobs[0]
self.assertEqual(False, job.has_elastic_profile_id)
try:
elastic_profile_id = job.elastic_profile_id
self.fail("should have thrown exception")
except RuntimeError:
pass
def test_jobs_can_have_run_instance_count(self):
job = typical_pipeline().ensure_stage("package").ensure_job("docker")
self.assertEqual(True, job.has_run_instance_count)
self.assertEqual("2", job.run_instance_count)
def test_can_set_run_instance_count(self):
job = empty_stage().ensure_job("j")
j = job.set_run_instance_count(2)
self.assertEqual(j, job)
self.assertEqual(True, job.has_run_instance_count)
self.assertEqual(2, job.run_instance_count)
def test_jobs_do_not_have_to_have_run_instance_count(self):
stages = typical_pipeline().stages
job = stages[0].jobs[0]
self.assertEqual(False, job.has_run_instance_count)
try:
run_instance_count = job.run_instance_count
self.fail("should have thrown exception")
except RuntimeError:
pass
def test_can_ensure_job_has_resource(self):
stages = typical_pipeline().stages
job = stages[0].jobs[0]
j = job.ensure_resource('moo')
self.assertEqual(j, job)
self.assertEqual(2, len(job.resources))
self.assertEqual({'a-resource', 'moo'}, job.resources)
def test_jobs_have_artifacts(self):
job = more_options_pipeline().ensure_stage("earlyStage").ensure_job("earlyWorm")
artifacts = job.artifacts
self.assertEqual({
Artifact.get_build_artifact("target/universal/myapp*.zip", "artifacts"),
Artifact.get_build_artifact("scripts/*", "files"),
Artifact.get_test_artifact("from", "to")},
artifacts)
def test_jobs_have_artifacts_with_type(self):
job = more_options_pipeline_with_artifacts_type().ensure_stage("earlyStage").ensure_job("earlyWorm")
artifacts = job.artifacts
self.assertEqual({
Artifact.get_build_artifact("target/universal/myapp*.zip", "artifacts"),
Artifact.get_build_artifact("scripts/*", "files"),
Artifact.get_test_artifact("from", "to"),
Artifact.get_external_artifact("docker-image",
"docker-registry", {'Image':
'docker-image-name', 'Tag': 'latest',
'BuildFile': 'buildfile.json'})},
artifacts)
def test_job_that_has_no_artifacts_has_no_artifacts_element_to_reduce_thrash(self):
go_cd_configurator = GoCdConfigurator(empty_config())
job = go_cd_configurator.ensure_pipeline_group("g").ensure_pipeline("p").ensure_stage("s").ensure_job("j")
job.ensure_artifacts(set())
self.assertEqual(set(), job.artifacts)
xml = parseString(go_cd_configurator.config)
self.assertEqual(0, len(xml.getElementsByTagName('artifacts')))
def test_artifacts_might_have_no_dest(self):
job = more_options_pipeline().ensure_stage("s1").ensure_job("rake-job")
artifacts = job.artifacts
self.assertEqual(1, len(artifacts))
self.assertEqual({Artifact.get_build_artifact("things/*")}, artifacts)
def test_artifacts_with_type_might_have_no_dest(self):
job = more_options_pipeline_with_artifacts_type().ensure_stage("s1").ensure_job("rake-job")
artifacts = job.artifacts
self.assertEqual(1, len(artifacts))
self.assertEqual({Artifact.get_build_artifact("things/*")}, artifacts)
def test_can_add_build_artifacts_to_job(self):
job = more_options_pipeline().ensure_stage("earlyStage").ensure_job("earlyWorm")
job_with_artifacts = job.ensure_artifacts({
Artifact.get_build_artifact("a1", "artifacts"),
Artifact.get_build_artifact("a2", "others")})
self.assertEqual(job, job_with_artifacts)
artifacts = job.artifacts
self.assertEqual(5, len(artifacts))
self.assertTrue({Artifact.get_build_artifact("a1", "artifacts"), Artifact.get_build_artifact("a2", "others")}.issubset(artifacts))
def test_can_add_test_artifacts_to_job(self):
job = more_options_pipeline().ensure_stage("earlyStage").ensure_job("earlyWorm")
job_with_artifacts = job.ensure_artifacts({
Artifact.get_test_artifact("a1"),
Artifact.get_test_artifact("a2")})
self.assertEqual(job, job_with_artifacts)
artifacts = job.artifacts
self.assertEqual(5, len(artifacts))
self.assertTrue({Artifact.get_test_artifact("a1"), Artifact.get_test_artifact("a2")}.issubset(artifacts))
def test_can_add_external_artifacts_to_job(self):
properties = {'key1': 'value', 'key2': None }
job = more_options_pipeline_with_external_artifacts().ensure_stage("earlyStage").ensure_job("earlyWorm")
job_with_artifacts = job.ensure_artifacts({
ExternalArtifact("id1", "store_id1", properties),
ExternalArtifact("id2", "store_id2", properties)})
self.assertEqual(job, job_with_artifacts)
artifacts = job.artifacts
self.assertEqual(6, len(artifacts))
self.assertTrue({
ExternalArtifact("id1", "store_id1", properties),
ExternalArtifact("id2", "store_id2", properties)}.issubset(artifacts))
def test_can_add_external_artifact_fetch_task_to_job(self):
job = more_options_pipeline_with_external_artifacts().ensure_stage("earlyStage").ensure_job("earlyWorm")
job_with_fetch_external_artifact_task = job.add_task(
FetchArtifactTask("docker-image", "build", "build",
id="docker-image", config={'EnvironmentVariablePrefix':
None, 'SkipImagePulling': 'true'}, artifactOrigin="external"))
self.assertIn(job_with_fetch_external_artifact_task, job.tasks)
def test_can_ensure_artifacts(self):
job = more_options_pipeline().ensure_stage("earlyStage").ensure_job("earlyWorm")
job.ensure_artifacts({
Artifact.get_test_artifact("from", "to"),
Artifact.get_build_artifact("target/universal/myapp*.zip", "somewhereElse"),
Artifact.get_test_artifact("another", "with dest"),
Artifact.get_build_artifact("target/universal/myapp*.zip", "artifacts")})
self.assertEqual({
Artifact.get_build_artifact("target/universal/myapp*.zip", "artifacts"),
Artifact.get_build_artifact("scripts/*", "files"),
Artifact.get_test_artifact("from", "to"),
Artifact.get_build_artifact("target/universal/myapp*.zip", "somewhereElse"),
Artifact.get_test_artifact("another", "with dest")
},
job.artifacts)
def test_jobs_have_tasks(self):
job = more_options_pipeline().ensure_stage("s1").jobs[2]
tasks = job.tasks
self.assertEqual(4, len(tasks))
self.assertEqual('rake', tasks[0].type)
self.assertEqual('sometarget', tasks[0].target)
self.assertEqual('passed', tasks[0].runif)
self.assertEqual('fetchartifact', tasks[1].type)
self.assertEqual('more-options', tasks[1].pipeline)
self.assertEqual('earlyStage', tasks[1].stage)
self.assertEqual('earlyWorm', tasks[1].job)
self.assertEqual(FetchArtifactDir('sourceDir'), tasks[1].src)
self.assertEqual('destDir', tasks[1].dest)
self.assertEqual('passed', tasks[1].runif)
def test_runif_defaults_to_passed(self):
pipeline = typical_pipeline()
tasks = pipeline.ensure_stage("build").ensure_job("compile").tasks
self.assertEqual("passed", tasks[0].runif)
def test_jobs_can_have_rake_tasks(self):
job = more_options_pipeline().ensure_stage("s1").jobs[0]
tasks = job.tasks
self.assertEqual(1, len(tasks))
self.assertEqual('rake', tasks[0].type)
self.assertEqual("boo", tasks[0].target)
def test_can_ensure_rake_task(self):
job = more_options_pipeline().ensure_stage("s1").jobs[0]
job.ensure_task(RakeTask("boo"))
self.assertEqual(1, len(job.tasks))
def test_can_add_rake_task(self):
job = more_options_pipeline().ensure_stage("s1").jobs[0]
job.ensure_task(RakeTask("another"))
self.assertEqual(2, len(job.tasks))
self.assertEqual("another", job.tasks[1].target)
def test_can_add_exec_task_with_runif(self):
stages = typical_pipeline().stages
job = stages[0].jobs[0]
added_task = job.add_task(ExecTask(['ls', '-la'], 'some/dir', "failed"))
self.assertEqual(2, len(job.tasks))
task = job.tasks[1]
self.assertEqual(task, added_task)
self.assertEqual(['ls', '-la'], task.command_and_args)
self.assertEqual('some/dir', task.working_dir)
self.assertEqual('failed', task.runif)
def test_can_add_exec_task(self):
stages = typical_pipeline().stages
job = stages[0].jobs[0]
added_task = job.add_task(ExecTask(['ls', '-la'], 'some/dir'))
self.assertEqual(2, len(job.tasks))
task = job.tasks[1]
self.assertEqual(task, added_task)
self.assertEqual(['ls', '-la'], task.command_and_args)
self.assertEqual('some/dir', task.working_dir)
def test_can_ensure_exec_task(self):
stages = typical_pipeline().stages
job = stages[0].jobs[0]
t1 = job.ensure_task(ExecTask(['ls', '-la'], 'some/dir'))
t2 = job.ensure_task(ExecTask(['make', 'options', 'source code']))
job.ensure_task(ExecTask(['ls', '-la'], 'some/otherdir'))
job.ensure_task(ExecTask(['ls', '-la'], 'some/dir'))
self.assertEqual(3, len(job.tasks))
self.assertEqual(t2, job.tasks[0])
self.assertEqual(['make', 'options', 'source code'], (job.tasks[0]).command_and_args)
self.assertEqual(t1, job.tasks[1])
self.assertEqual(['ls', '-la'], (job.tasks[1]).command_and_args)
self.assertEqual('some/dir', (job.tasks[1]).working_dir)
self.assertEqual(['ls', '-la'], (job.tasks[2]).command_and_args)
self.assertEqual('some/otherdir', (job.tasks[2]).working_dir)
def test_exec_task_args_are_unescaped_as_appropriate(self):
job = more_options_pipeline().ensure_stage("earlyStage").ensure_job("earlyWorm")
task = job.tasks[1]
self.assertEqual(["bash", "-c",
'curl "http://domain.com/service/check?target=one+two+three&key=2714_beta%40domain.com"'],
task.command_and_args)
def test_exec_task_args_are_escaped_as_appropriate(self):
job = empty_stage().ensure_job("j")
task = job.add_task(ExecTask(["bash", "-c",
'curl "http://domain.com/service/check?target=one+two+three&key=2714_beta%40domain.com"']))
self.assertEqual(["bash", "-c",
'curl "http://domain.com/service/check?target=one+two+three&key=2714_beta%40domain.com"'],
task.command_and_args)
def test_can_have_no_tasks(self):
self.assertEqual(0, len(empty_stage().ensure_job("empty_job").tasks))
def test_can_add_fetch_artifact_task_to_job(self):
stages = typical_pipeline().stages
job = stages[0].jobs[0]
added_task = job.add_task(FetchArtifactTask('p', 's', 'j', FetchArtifactDir('d'), runif="any"))
self.assertEqual(2, len(job.tasks))
task = job.tasks[1]
self.assertEqual(added_task, task)
self.assertEqual('p', task.pipeline)
self.assertEqual('s', task.stage)
self.assertEqual('j', task.job)
self.assertEqual(FetchArtifactDir('d'), task.src)
self.assertEqual('any', task.runif)
def test_fetch_artifact_task_can_have_src_file_rather_than_src_dir(self):
job = more_options_pipeline().ensure_stage("s1").ensure_job("variety-of-tasks")
tasks = job.tasks
self.assertEqual(4, len(tasks))
self.assertEqual('more-options', tasks[1].pipeline)
self.assertEqual('earlyStage', tasks[1].stage)
self.assertEqual('earlyWorm', tasks[1].job)
self.assertEqual(FetchArtifactFile('someFile'), tasks[2].src)
self.assertEqual('passed', tasks[1].runif)
self.assertEqual(['true'], tasks[3].command_and_args)
def test_fetch_artifact_task_can_have_dest(self):
pipeline = more_options_pipeline()
job = pipeline.ensure_stage("s1").ensure_job("variety-of-tasks")
tasks = job.tasks
self.assertEqual(FetchArtifactTask("more-options",
"earlyStage",
"earlyWorm",
FetchArtifactDir("sourceDir"),
dest="destDir"),
tasks[1])
def test_fetch_artifact_task_can_have_origin(self):
pipeline = more_options_pipeline_with_artifacts_type()
job = pipeline.ensure_stage("s1").ensure_job("variety-of-tasks")
tasks = job.tasks
self.assertEqual(FetchArtifactTask("more-options",
"earlyStage",
"earlyWorm",
FetchArtifactDir("sourceDir"),
dest="destDir",
origin="gocd",
artifactOrigin="gocd"),
tasks[1])
def test_can_ensure_fetch_artifact_tasks(self):
job = more_options_pipeline().ensure_stage("s1").ensure_job("variety-of-tasks")
job.ensure_task(FetchArtifactTask("more-options", "middleStage", "middleJob", FetchArtifactFile("someFile")))
first_added_task = job.ensure_task(FetchArtifactTask('p', 's', 'j', FetchArtifactDir('dir')))
self.assertEqual(5, len(job.tasks))
self.assertEqual(first_added_task, job.tasks[4])
self.assertEqual('p', (job.tasks[4]).pipeline)
self.assertEqual('s', (job.tasks[4]).stage)
self.assertEqual('j', (job.tasks[4]).job)
self.assertEqual(FetchArtifactDir('dir'), (job.tasks[4]).src)
self.assertEqual('passed', (job.tasks[4]).runif)
job.ensure_task(FetchArtifactTask('p', 's', 'j', FetchArtifactFile('f')))
self.assertEqual(FetchArtifactFile('f'), (job.tasks[5]).src)
job.ensure_task(FetchArtifactTask('p', 's', 'j', FetchArtifactDir('dir'), dest="somedest"))
self.assertEqual("somedest", (job.tasks[6]).dest)
job.ensure_task(FetchArtifactTask('p', 's', 'j', FetchArtifactDir('dir'), runif="failed"))
self.assertEqual('failed', (job.tasks[7]).runif)
def test_tasks_run_if_defaults_to_passed(self):
job = empty_stage().ensure_job("j")
job.add_task(ExecTask(['ls', '-la'], 'some/dir'))
job.add_task(FetchArtifactTask('p', 's', 'j', FetchArtifactDir('dir')))
job.add_task(RakeTask('x'))
self.assertEqual('passed', (job.tasks[0]).runif)
self.assertEqual('passed', (job.tasks[1]).runif)
self.assertEqual('passed', (job.tasks[2]).runif)
def test_tasks_run_if_variants(self):
job = more_options_pipeline().ensure_stage("s1").ensure_job("run-if-variants")
tasks = job.tasks
self.assertEqual('t-passed', tasks[0].command_and_args[0])
self.assertEqual('passed', tasks[0].runif)
self.assertEqual('t-none', tasks[1].command_and_args[0])
self.assertEqual('passed', tasks[1].runif)
self.assertEqual('t-failed', tasks[2].command_and_args[0])
self.assertEqual('failed', tasks[2].runif)
self.assertEqual('t-any', tasks[3].command_and_args[0])
self.assertEqual('any', tasks[3].runif)
self.assertEqual('t-both', tasks[4].command_and_args[0])
self.assertEqual('any', tasks[4].runif)
def test_cannot_set_runif_to_random_things(self):
try:
ExecTask(['x'], runif='whatever')
self.fail("should have thrown exception")
except RuntimeError as e:
self.assertTrue(str(e).count("whatever") > 0)
def test_can_set_runif_to_particular_values(self):
self.assertEqual('passed', ExecTask(['x'], runif='passed').runif)
self.assertEqual('failed', ExecTask(['x'], runif='failed').runif)
self.assertEqual('any', ExecTask(['x'], runif='any').runif)
def test_tasks_dest_defaults_to_none(self): # TODO: maybe None could be avoided
job = empty_stage().ensure_job("j")
job.add_task(FetchArtifactTask('p', 's', 'j', FetchArtifactDir('dir')))
self.assertEqual(None, (job.tasks[0]).dest)
def test_can_add_exec_task_to_empty_job(self):
job = empty_stage().ensure_job("j")
added_task = job.add_task(ExecTask(['ls', '-la'], 'some/dir', "any"))
self.assertEqual(1, len(job.tasks))
task = job.tasks[0]
self.assertEqual(task, added_task)
self.assertEqual(['ls', '-la'], task.command_and_args)
self.assertEqual('some/dir', task.working_dir)
self.assertEqual('any', task.runif)
def test_can_remove_all_tasks(self):
stages = typical_pipeline().stages
job = stages[0].jobs[0]
self.assertEqual(1, len(job.tasks))
j = job.without_any_tasks()
self.assertEqual(j, job)
self.assertEqual(0, len(job.tasks))
def test_can_have_encrypted_environment_variables(self):
pipeline = GoCdConfigurator(config('config-with-encrypted-variable')).ensure_pipeline_group("defaultGroup").find_pipeline("example")
job = pipeline.ensure_stage('defaultStage').ensure_job('defaultJob')
self.assertEqual({"MY_JOB_PASSWORD": "yq5qqPrrD9/j=="}, job.encrypted_environment_variables)
def test_can_set_encrypted_environment_variables(self):
job = empty_stage().ensure_job("j")
job.ensure_encrypted_environment_variables({'one': 'blah=='})
self.assertEqual({"one": "blah=="}, job.encrypted_environment_variables)
def test_can_add_unencrypted_secure_environment_variables_to_stage(self):
job = empty_stage().ensure_job("j")
job.ensure_unencrypted_secure_environment_variables({"new": "one", "again": "two"})
self.assertEqual({"new": "one", "again": "two"}, job.unencrypted_secure_environment_variables)
def test_can_add_environment_variables(self):
job = typical_pipeline() \
.ensure_stage("build") \
.ensure_job("compile")
j = job.ensure_environment_variables({"new": "one"})
self.assertEqual(j, job)
self.assertEqual({"CF_COLOR": "false", "new": "one"}, job.environment_variables)
def test_environment_variables_get_added_in_sorted_order_to_reduce_config_thrash(self):
go_cd_configurator = GoCdConfigurator(empty_config())
job = go_cd_configurator\
.ensure_pipeline_group('P.Group')\
.ensure_pipeline('P.Name') \
.ensure_stage("build") \
.ensure_job("compile")
job.ensure_environment_variables({"ant": "a", "badger": "a", "zebra": "a"})
xml = parseString(go_cd_configurator.config)
names = [e.getAttribute('name') for e in xml.getElementsByTagName('variable')]
self.assertEqual([u'ant', u'badger', u'zebra'], names)
def test_can_remove_all_environment_variables(self):
job = typical_pipeline() \
.ensure_stage("build") \
.ensure_job("compile")
j = job.without_any_environment_variables()
self.assertEqual(j, job)
self.assertEqual({}, job.environment_variables)
def test_job_can_haveTabs(self):
job = typical_pipeline() \
.ensure_stage("build") \
.ensure_job("compile")
self.assertEqual([Tab("Time_Taken", "artifacts/test-run-times.html")], job.tabs)
def test_can_addTab(self):
job = typical_pipeline() \
.ensure_stage("build") \
.ensure_job("compile")
j = job.ensure_tab(Tab("n", "p"))
self.assertEqual(j, job)
self.assertEqual([Tab("Time_Taken", "artifacts/test-run-times.html"), Tab("n", "p")], job.tabs)
def test_can_ensure_tab(self):
job = typical_pipeline() \
.ensure_stage("build") \
.ensure_job("compile")
job.ensure_tab(Tab("Time_Taken", "artifacts/test-run-times.html"))
self.assertEqual([Tab("Time_Taken", "artifacts/test-run-times.html")], job.tabs)
class TestTasks(unittest.TestCase):
def test_fetch_artifact_task_object_representation_format(self):
correct_format = 'FetchArtifactTask("p", "s", "j", FetchArtifactFile("f"), dest="d", runif="any", origin="gocd")'
current_object_repr = repr(FetchArtifactTask('p', 's', 'j', FetchArtifactFile('f'), runif="any", dest='d', origin='gocd'))
self.assertEqual(correct_format, current_object_repr)
def test_renders_fetch_artifact_task_with_dest_origin(self):
element = ET.Element('fetchartifact')
fetch_artifact_task = FetchArtifactTask('p', 's', 'j', FetchArtifactDir('d'), dest='dest_path', origin='gocd')
fetch_artifact_task.append_to(element)
self.assertEqual(element[0].tag, 'tasks')
self.assertEqual(element[0][0].tag, 'fetchartifact')
self.assertEqual(element[0][0].attrib['dest'], 'dest_path')
self.assertEqual(element[0][0].attrib['origin'], 'gocd')
def test_renders_fetch_artifact_task_without_dest_origin(self):
element = ET.Element('fetchartifact')
fetch_artifact_task = FetchArtifactTask('p', 's', 'j', FetchArtifactDir('d'))
fetch_artifact_task.append_to(element)
self.assertEqual(element[0].tag, 'tasks')
self.assertEqual(element[0][0].tag, 'fetchartifact')
self.assertEqual('dest' in element[0][0].attrib, False)
self.assertEqual('origin' in element[0][0].attrib, False)
class TestStages(unittest.TestCase):
def test_pipelines_have_stages(self):
self.assertEqual(3, len(typical_pipeline().stages))
def test_stages_have_names(self):
stages = typical_pipeline().stages
self.assertEqual('build', stages[0].name)
self.assertEqual('package', stages[1].name)
self.assertEqual('deploy', stages[2].name)
def test_stages_can_have_manual_approval(self):
self.assertEqual(False, typical_pipeline().stages[0].has_manual_approval)
self.assertEqual(False, typical_pipeline().stages[1].has_manual_approval)
self.assertEqual(True, typical_pipeline().stages[2].has_manual_approval)
def test_can_set_manual_approval(self):
stage = typical_pipeline().stages[0]
s = stage.set_has_manual_approval()
self.assertEqual(s, stage)
self.assertEqual(True, stage.has_manual_approval)
def test_manual_approval_can_have_authorization(self):
stage = typical_pipeline().stages[0]
s = stage.set_has_manual_approval(authorize_users=['user1'], authorize_roles=['role1'])
self.assertEqual(True, stage.has_manual_approval)
self.assertEqual(['user1'], stage.authorized_users)
self.assertEqual(['role1'], stage.authorized_roles)
def test_stages_have_fetch_materials_flag(self):
stage = typical_pipeline().ensure_stage("build")
self.assertEqual(True, stage.fetch_materials)
stage = more_options_pipeline().ensure_stage("s1")
self.assertEqual(False, stage.fetch_materials)
def test_can_set_fetch_materials_flag(self):
stage = typical_pipeline().ensure_stage("build")
s = stage.set_fetch_materials(False)
self.assertEqual(s, stage)
self.assertEqual(False, stage.fetch_materials)
stage = more_options_pipeline().ensure_stage("s1")
stage.set_fetch_materials(True)
self.assertEqual(True, stage.fetch_materials)
def test_stages_have_jobs(self):
stages = typical_pipeline().stages
jobs = stages[0].jobs
self.assertEqual(1, len(jobs))
self.assertEqual('compile', jobs[0].name)
def test_can_add_job(self):
stage = typical_pipeline().ensure_stage("deploy")
self.assertEqual(1, len(stage.jobs))
ensured_job = stage.ensure_job("new-job")
self.assertEqual(2, len(stage.jobs))
self.assertEqual(ensured_job, stage.jobs[1])
self.assertEqual("new-job", stage.jobs[1].name)
def test_can_add_job_to_empty_stage(self):
stage = empty_stage()
self.assertEqual(0, len(stage.jobs))
ensured_job = stage.ensure_job("new-job")
self.assertEqual(1, len(stage.jobs))
self.assertEqual(ensured_job, stage.jobs[0])
self.assertEqual("new-job", stage.jobs[0].name)
def test_can_ensure_job_exists(self):
stage = typical_pipeline().ensure_stage("deploy")
self.assertEqual(1, len(stage.jobs))
ensured_job = stage.ensure_job("upload")
self.assertEqual(1, len(stage.jobs))
self.assertEqual("upload", ensured_job.name)
def test_can_have_encrypted_environment_variables(self):
pipeline = GoCdConfigurator(config('config-with-encrypted-variable')).ensure_pipeline_group("defaultGroup").find_pipeline("example")
stage = pipeline.ensure_stage('defaultStage')
self.assertEqual({"MY_STAGE_PASSWORD": "yq5qqPrrD9/s=="}, stage.encrypted_environment_variables)
def test_can_set_encrypted_environment_variables(self):
stage = typical_pipeline().ensure_stage("deploy")
stage.ensure_encrypted_environment_variables({'one': 'blah=='})
self.assertEqual({"one": "blah=="}, stage.encrypted_environment_variables)
def test_can_set_environment_variables(self):
stage = typical_pipeline().ensure_stage("deploy")
s = stage.ensure_environment_variables({"new": "one"})
self.assertEqual(s, stage)
self.assertEqual({"BASE_URL": "http://myurl", "new": "one"}, stage.environment_variables)
def test_can_add_unencrypted_secure_environment_variables_to_stage(self):
stage = typical_pipeline().ensure_stage("deploy")
stage.ensure_unencrypted_secure_environment_variables({"new": "one", "again": "two"})
self.assertEqual({"new": "one", "again": "two"}, stage.unencrypted_secure_environment_variables)
def test_can_remove_all_environment_variables(self):
stage = typical_pipeline().ensure_stage("deploy")
s = stage.without_any_environment_variables()
self.assertEqual(s, stage)
self.assertEqual({}, stage.environment_variables)
class TestConfigRepo(unittest.TestCase):
def setUp(self):
self.configurator = GoCdConfigurator(empty_config())
def test_ensure_replacement_of_config_repos(self):
self.configurator.ensure_config_repos().ensure_config_repo('git://url', 'yaml.config.plugin')
self.assertEqual(len(self.configurator.config_repos.config_repo), 1)
self.configurator.ensure_replacement_of_config_repos().ensure_config_repo('git://otherurl', 'yaml.config.plugin')
self.assertEqual(len(self.configurator.config_repos.config_repo), 1)
def test_can_ensure_config_repo_with_git_url_and_plugin(self):
self.configurator.ensure_config_repos().ensure_config_repo('git://url', 'yaml.config.plugin')
self.assertEqual(self.configurator.config_repos.config_repo[0].url, 'git://url')
self.assertEqual(self.configurator.config_repos.config_repo[0].plugin, 'yaml.config.plugin')
self.assertIsNone(self.configurator.config_repos.config_repo[0].branch)
def test_can_ensure_config_repo_with_git_url_and_branch(self):
self.configurator.ensure_config_repos().ensure_config_repo('git://url', 'yaml.config.plugin', branch='release')
self.assertEqual(self.configurator.config_repos.config_repo[0].url, 'git://url')
self.assertEqual(self.configurator.config_repos.config_repo[0].plugin, 'yaml.config.plugin')
self.assertEqual(self.configurator.config_repos.config_repo[0].branch, 'release')
def test_can_ensure_yaml_config_repo_with_git_url(self):
self.configurator.ensure_config_repos().ensure_yaml_config_repo('git://url')
self.assertEqual(self.configurator.config_repos.config_repo[0].url, 'git://url')
self.assertEqual(self.configurator.config_repos.config_repo[0].plugin, 'yaml.config.plugin')
def test_can_ensure_json_config_repo_with_git_url(self):
self.configurator.ensure_config_repos().ensure_json_config_repo('git://url')
self.assertEqual(self.configurator.config_repos.config_repo[0].url, 'git://url')
self.assertEqual(self.configurator.config_repos.config_repo[0].plugin, 'json.config.plugin')
def test_can_ensure_repo_for_different_cvs(self):
self.configurator.ensure_config_repos().ensure_config_repo('svn://url', 'json.config.plugin', cvs='svn')
self.assertEqual(self.configurator.config_repos.config_repo[0].url, 'svn://url')
self.assertEqual(self.configurator.config_repos.config_repo[0].plugin, 'json.config.plugin')
def test_can_ensure_config_repo_with_configuration(self):
self.configurator.ensure_config_repos().ensure_config_repo('yml://url', 'yml.config.plugin', cvs='yml',
configuration={
'file_pattern': '*.gocd.yml'
})
self.assertEqual(self.configurator.config_repos.config_repo[0].configuration, {
'file_pattern': '*.gocd.yml'
})
def test_can_ensure_replacement_of_config_repo(self):
self.configurator.ensure_config_repos().ensure_config_repo('git://url', 'yml.config.plugin')
self.configurator.ensure_config_repos().ensure_replacement_of_config_repo('git://url', 'json.config.plugin')
self.assertEqual(self.configurator.config_repos.config_repo[0].url, 'git://url')
self.assertEqual(self.configurator.config_repos.config_repo[0].plugin, 'json.config.plugin')
def test_doesnt_duplicate_config_repos(self):
self.configurator.ensure_config_repos().ensure_yaml_config_repo('git://url')
self.configurator.ensure_config_repos().ensure_yaml_config_repo('git://url')
self.assertEqual(len(self.configurator.config_repos.config_repo), 1)
def test_can_add_more_than_2_config_repos(self):
self.configurator.ensure_config_repos().ensure_yaml_config_repo('git://url')
self.configurator.ensure_config_repos().ensure_json_config_repo('git://url')
self.configurator.ensure_config_repos().ensure_yaml_config_repo('git://url2')
self.assertEqual(len(self.configurator.config_repos.config_repo), 3)
def test_changes_attrs_for_new_server_versions(self):
configurator = GoCdConfigurator(FakeHostRestClient(empty_config_xml, version='17.9.0'))
configurator.ensure_config_repos().ensure_config_repo('git://url', 'yml.config.plugin', repo_id='myRepo')
self.assertEqual(configurator.config_repos.config_repo[0].element.get('pluginId'), 'yml.config.plugin')
self.assertEqual(configurator.config_repos.config_repo[0].plugin, 'yml.config.plugin')
self.assertEqual(configurator.config_repos.config_repo[0].repo_id, 'myRepo')
def test_handles_unspecified_id_for_migration(self):
configurator = GoCdConfigurator(FakeHostRestClient(empty_config_xml, version='17.8.0'))
configurator.ensure_config_repos().ensure_config_repo('git://url', 'yml.config.plugin')
self.assertIsNotNone(configurator.config_repos.config_repo[0].repo_id)
class TestPipeline(unittest.TestCase):
def test_pipelines_have_names(self):
pipeline = typical_pipeline()
self.assertEqual('typical', pipeline.name)
def test_can_add_stage(self):
pipeline = empty_pipeline()
self.assertEqual(0, len(pipeline.stages))
new_stage = pipeline.ensure_stage("some_stage")
self.assertEqual(1, len(pipeline.stages))
self.assertEqual(new_stage, pipeline.stages[0])
self.assertEqual("some_stage", new_stage.name)
def test_can_ensure_stage(self):
pipeline = typical_pipeline()
self.assertEqual(3, len(pipeline.stages))
ensured_stage = pipeline.ensure_stage("deploy")
self.assertEqual(3, len(pipeline.stages))
self.assertEqual("deploy", ensured_stage.name)
def test_can_remove_stage(self):
pipeline = typical_pipeline()
self.assertEqual(3, len(pipeline.stages))
p = pipeline.ensure_removal_of_stage("deploy")
self.assertEqual(p, pipeline)
self.assertEqual(2, len(pipeline.stages))
self.assertEqual(0, len([s for s in pipeline.stages if s.name == "deploy"]))
def test_can_ensure_removal_of_stage(self):
pipeline = typical_pipeline()
self.assertEqual(3, len(pipeline.stages))
pipeline.ensure_removal_of_stage("stage-that-has-already-been-deleted")
self.assertEqual(3, len(pipeline.stages))
def test_can_ensure_initial_stage(self):
pipeline = typical_pipeline()
stage = pipeline.ensure_initial_stage("first")
self.assertEqual(stage, pipeline.stages[0])
self.assertEqual(4, len(pipeline.stages))
def test_can_ensure_initial_stage_if_already_exists_as_initial(self):
pipeline = typical_pipeline()
stage = pipeline.ensure_initial_stage("build")
self.assertEqual(stage, pipeline.stages[0])
self.assertEqual(3, len(pipeline.stages))
def test_can_ensure_initial_stage_if_already_exists(self):
pipeline = typical_pipeline()
stage = pipeline.ensure_initial_stage("deploy")
self.assertEqual(stage, pipeline.stages[0])
self.assertEqual("build", pipeline.stages[1].name)
self.assertEqual(3, len(pipeline.stages))
def test_can_set_stage_clean_policy(self):
pipeline = empty_pipeline()
stage1 = pipeline.ensure_stage("some_stage1").set_clean_working_dir()
stage2 = pipeline.ensure_stage("some_stage2")
self.assertEqual(True, pipeline.stages[0].clean_working_dir)
self.assertEqual(True, stage1.clean_working_dir)
self.assertEqual(False, pipeline.stages[1].clean_working_dir)
self.assertEqual(False, stage2.clean_working_dir)
def test_pipelines_can_have_git_urls(self):
pipeline = typical_pipeline()
self.assertEqual("git@bitbucket.org:springersbm/gomatic.git", pipeline.git_url)
def test_git_is_polled_by_default(self):
pipeline = GoCdConfigurator(empty_config()).ensure_pipeline_group("g").ensure_pipeline("p")
pipeline.set_git_url("some git url")
self.assertEqual(True, pipeline.git_material.polling)
def test_pipelines_can_have_git_material_with_material_name(self):
pipeline = more_options_pipeline()
self.assertEqual("git@bitbucket.org:springersbm/gomatic.git", pipeline.git_url)
self.assertEqual("some-material-name", pipeline.git_material.material_name)
def test_git_material_can_ignore_sources(self):
pipeline = GoCdConfigurator(config('config-with-source-exclusions')).ensure_pipeline_group("P.Group").find_pipeline("with-exclusions")
self.assertEqual({"excluded-folder", "another-excluded-folder"}, pipeline.git_material.ignore_patterns)
def test_can_set_pipeline_git_url(self):
pipeline = typical_pipeline()
p = pipeline.set_git_url("git@bitbucket.org:springersbm/changed.git")
self.assertEqual(p, pipeline)
self.assertEqual("git@bitbucket.org:springersbm/changed.git", pipeline.git_url)
self.assertEqual('master', pipeline.git_branch)
def test_can_set_pipeline_git_url_with_options(self):
pipeline = typical_pipeline()
p = pipeline.set_git_material(GitMaterial(
"git@bitbucket.org:springersbm/changed.git",
branch="branch",
destination_directory="foo",
material_name="material-name",
ignore_patterns={"ignoreMe", "ignoreThisToo"},
polling=False))
self.assertEqual(p, pipeline)
self.assertEqual("branch", pipeline.git_branch)
self.assertEqual("foo", pipeline.git_material.destination_directory)
self.assertEqual("material-name", pipeline.git_material.material_name)
self.assertEqual({"ignoreMe", "ignoreThisToo"}, pipeline.git_material.ignore_patterns)
self.assertFalse(pipeline.git_material.polling, "git polling")
def test_throws_exception_if_no_git_url(self):
pipeline = GoCdConfigurator(empty_config()).ensure_pipeline_group("g").ensure_pipeline("p")
self.assertEqual(False, pipeline.has_single_git_material)
try:
url = pipeline.git_url
self.fail("should have thrown exception")
except RuntimeError:
pass
def test_git_url_throws_exception_if_multiple_git_materials(self):
pipeline = GoCdConfigurator(empty_config()).ensure_pipeline_group("g").ensure_pipeline("p")
pipeline.ensure_material(GitMaterial("git@bitbucket.org:springersbm/one.git"))
pipeline.ensure_material(GitMaterial("git@bitbucket.org:springersbm/two.git"))
self.assertEqual(False, pipeline.has_single_git_material)
try:
url = pipeline.git_url
self.fail("should have thrown exception")
except RuntimeError:
pass
def test_set_git_url_throws_exception_if_multiple_git_materials(self):
pipeline = GoCdConfigurator(empty_config()).ensure_pipeline_group("g").ensure_pipeline("p")
pipeline.ensure_material(GitMaterial("git@bitbucket.org:springersbm/one.git"))
pipeline.ensure_material(GitMaterial("git@bitbucket.org:springersbm/two.git"))
try:
pipeline.set_git_url("git@bitbucket.org:springersbm/three.git")
self.fail("should have thrown exception")
except RuntimeError:
pass
def test_can_add_git_material(self):
pipeline = GoCdConfigurator(empty_config()).ensure_pipeline_group("g").ensure_pipeline("p")
p = pipeline.ensure_material(GitMaterial("git@bitbucket.org:springersbm/changed.git"))
self.assertEqual(p, pipeline)
self.assertEqual("git@bitbucket.org:springersbm/changed.git", pipeline.git_url)
def test_can_ensure_git_material(self):
pipeline = typical_pipeline()
pipeline.ensure_material(GitMaterial("git@bitbucket.org:springersbm/gomatic.git"))
self.assertEqual("git@bitbucket.org:springersbm/gomatic.git", pipeline.git_url)
self.assertEqual([GitMaterial("git@bitbucket.org:springersbm/gomatic.git")], pipeline.materials)
def test_can_have_multiple_git_materials(self):
pipeline = typical_pipeline()
pipeline.ensure_material(GitMaterial("git@bitbucket.org:springersbm/changed.git"))
self.assertEqual([GitMaterial("git@bitbucket.org:springersbm/gomatic.git"), GitMaterial("git@bitbucket.org:springersbm/changed.git")],
pipeline.materials)
def test_pipelines_can_have_pipeline_materials(self):
pipeline = more_options_pipeline()
self.assertEqual(2, len(pipeline.materials))
self.assertEqual(GitMaterial('git@bitbucket.org:springersbm/gomatic.git', branch="a-branch", material_name="some-material-name", polling=False),
pipeline.materials[0])
def test_pipelines_can_have_more_complicated_pipeline_materials(self):
pipeline = more_options_pipeline()
self.assertEqual(2, len(pipeline.materials))
self.assertEqual(True, pipeline.materials[0].is_git)
self.assertEqual(PipelineMaterial('pipeline2', 'build'), pipeline.materials[1])
def test_pipelines_can_have_no_materials(self):
pipeline = GoCdConfigurator(empty_config()).ensure_pipeline_group("g").ensure_pipeline("p")
self.assertEqual(0, len(pipeline.materials))
def test_can_add_pipeline_material(self):
pipeline = GoCdConfigurator(empty_config()).ensure_pipeline_group("g").ensure_pipeline("p")
p = pipeline.ensure_material(PipelineMaterial('deploy-qa', 'baseline-user-data'))
self.assertEqual(p, pipeline)
self.assertEqual(PipelineMaterial('deploy-qa', 'baseline-user-data'), pipeline.materials[0])
def test_can_add_more_complicated_pipeline_material(self):
pipeline = GoCdConfigurator(empty_config()).ensure_pipeline_group("g").ensure_pipeline("p")
p = pipeline.ensure_material(PipelineMaterial('p', 's', 'm'))
self.assertEqual(p, pipeline)
self.assertEqual(PipelineMaterial('p', 's', 'm'), pipeline.materials[0])
def test_can_ensure_pipeline_material(self):
pipeline = more_options_pipeline()
self.assertEqual(2, len(pipeline.materials))
pipeline.ensure_material(PipelineMaterial('pipeline2', 'build'))
self.assertEqual(2, len(pipeline.materials))
def test_can_remove_all_pipeline_materials(self):
pipeline = more_options_pipeline()
pipeline.remove_materials()
self.assertEqual(0, len(pipeline.materials))
def test_materials_are_sorted(self):
go_cd_configurator = GoCdConfigurator(empty_config())