1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class TriggerDeployStepTest extends PipelineTest { |
|
|
|
|
4
|
|
|
|
5
|
|
|
protected static $fixture_file = 'PipelineTest.yml'; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Makse the dummy deployment step |
9
|
|
|
* |
10
|
|
|
* @return TriggerDeployStep |
11
|
|
|
*/ |
12
|
|
View Code Duplication |
public function getDummyConfirmationStep() { |
|
|
|
|
13
|
|
|
// Load config |
14
|
|
|
$data = $this->getPipelineConfig(); |
15
|
|
|
|
16
|
|
|
// Load data into step and pipeline |
17
|
|
|
$triggerDeployStep = $this->objFromFixture('TriggerDeployStep', 'testdeploy'); |
18
|
|
|
$pipeline = $triggerDeployStep->Pipeline(); |
19
|
|
|
$pipeline->Config = serialize($data); |
20
|
|
|
$pipeline->write(); |
21
|
|
|
$triggerDeployStep->Config = serialize($pipeline->getConfigSetting('Steps', 'RequestDeploymentStep')); |
22
|
|
|
$triggerDeployStep->write(); |
23
|
|
|
|
24
|
|
|
return $triggerDeployStep; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Test that timeout expiry works |
29
|
|
|
*/ |
30
|
|
View Code Duplication |
public function testTimeout() { |
|
|
|
|
31
|
|
|
$step = $this->getDummyConfirmationStep(); |
32
|
|
|
$step->start(); |
33
|
|
|
|
34
|
|
|
// Assert not error at startup |
35
|
|
|
$this->assertEquals('Started', $step->Status); |
|
|
|
|
36
|
|
|
|
37
|
|
|
// Go to two weeks into the future |
38
|
|
|
SS_Datetime::set_mock_now(date('Y-m-d H:i:s', strtotime('+2 weeks'))); |
39
|
|
|
|
40
|
|
|
// Retry step |
41
|
|
|
$step->start(); |
42
|
|
|
$this->assertEquals('Failed', $step->Status); |
|
|
|
|
43
|
|
|
$this->assertTrue($step->isTimedOut()); |
|
|
|
|
44
|
|
|
|
45
|
|
|
// check a log entry exists |
46
|
|
|
$this->assertHasLog('Deployment step is older then 86400 seconds and has timed out'); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function testDeploy() { |
50
|
|
|
SS_Datetime::set_mock_now(date('Y-m-d H:i:s')); |
51
|
|
|
$step = $this->getDummyConfirmationStep(); |
52
|
|
|
|
53
|
|
|
$step->start(); |
54
|
|
|
$step->deploy(); |
55
|
|
|
|
56
|
|
|
// Assert not error at startup |
57
|
|
|
$this->assertEquals('Finished', $step->Status); |
|
|
|
|
58
|
|
|
|
59
|
|
|
// Assert that 'now' is used for the deployment date |
60
|
|
|
$this->assertEquals(SS_Datetime::now()->Format('Y-m-d H:i:s'), $step->Deployed); |
|
|
|
|
61
|
|
|
|
62
|
|
|
$this->assertHasLog('RequestDeploymentStep is being deployed'); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
View Code Duplication |
public function testCanTrigger() { |
|
|
|
|
66
|
|
|
$step = $this->getDummyConfirmationStep(); |
67
|
|
|
|
68
|
|
|
$step->start(); |
69
|
|
|
|
70
|
|
|
// can the author trigger the deploy |
71
|
|
|
$member = Member::get_by_id('Member', $step->Pipeline()->AuthorID); |
72
|
|
|
$member->logIn(); |
73
|
|
|
|
74
|
|
|
$this->assertTrue($step->canTriggerDeploy()); |
|
|
|
|
75
|
|
|
|
76
|
|
|
// can another member with deploy permissions trigger the deploy |
77
|
|
|
$member = Member::get() |
78
|
|
|
->filter('Email', '[email protected]') |
79
|
|
|
->first(); |
80
|
|
|
$member->logIn(); |
81
|
|
|
$this->assertTrue($step->canTriggerDeploy()); |
|
|
|
|
82
|
|
|
|
83
|
|
|
$this->logInWithPermission('APPLY_ROLES'); |
84
|
|
|
$this->assertFalse($step->canTriggerDeploy()); |
|
|
|
|
85
|
|
|
|
86
|
|
|
$this->logInWithPermission('ADMIN'); |
87
|
|
|
$this->assertTrue($step->canTriggerDeploy()); |
|
|
|
|
88
|
|
|
|
89
|
|
|
// confirm other members without admin permissions can not trigger the deploy |
90
|
|
|
$member = Member::get() |
91
|
|
|
->filter('Email', '[email protected]') |
92
|
|
|
->first(); |
93
|
|
|
$member->logIn(); |
94
|
|
|
$this->assertFalse($step->canTriggerDeploy()); |
|
|
|
|
95
|
|
|
|
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function testStartDeployment() { |
99
|
|
|
$step = $this->getDummyConfirmationStep(); |
100
|
|
|
|
101
|
|
|
$step->start(); |
102
|
|
|
|
103
|
|
|
$this->logInWithPermission('APPLY_ROLES'); |
104
|
|
|
$this->assertTrue($step->startDeployment()); |
|
|
|
|
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
public function testRunningConfiguration() { |
108
|
|
|
$step = $this->getDummyConfirmationStep(); |
109
|
|
|
|
110
|
|
|
$step->start(); |
111
|
|
|
$this->logInWithPermission('ADMIN'); |
112
|
|
|
$this->assertEquals('Please press the "Deploy" button to continue deployment', |
|
|
|
|
113
|
|
|
$step->getRunningDescription()); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
public function testStartFail() { |
117
|
|
|
$step = $this->getDummyConfirmationStep(); |
118
|
|
|
// set status so it fails |
119
|
|
|
$step->Status = 'Failed'; |
120
|
|
|
|
121
|
|
|
$this->assertFalse($step->start()); |
|
|
|
|
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.