|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class EmergencyRollbackStepTest extends PipelineTest { |
|
|
|
|
|
|
4
|
|
|
|
|
5
|
|
|
protected static $fixture_file = 'PipelineTest.yml'; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Makse the dummy deployment step |
|
9
|
|
|
* |
|
10
|
|
|
* @return EmergencyRollbackStep |
|
11
|
|
|
*/ |
|
12
|
|
View Code Duplication |
public function getDummyConfirmationStep() { |
|
|
|
|
|
|
13
|
|
|
// Load config |
|
14
|
|
|
$data = $this->getPipelineConfig(); |
|
15
|
|
|
|
|
16
|
|
|
// Load data into step and pipeline |
|
17
|
|
|
$emergencyRollback = $this->objFromFixture('EmergencyRollbackStep', 'testdeploy'); |
|
18
|
|
|
$pipeline = $emergencyRollback->Pipeline(); |
|
19
|
|
|
$pipeline->Config = serialize($data); |
|
20
|
|
|
$pipeline->write(); |
|
21
|
|
|
$emergencyRollback->Config = serialize($pipeline->getConfigSetting('Steps', 'RollbackWindowStep')); |
|
22
|
|
|
$emergencyRollback->write(); |
|
23
|
|
|
|
|
24
|
|
|
return $emergencyRollback; |
|
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 hours in the future |
|
38
|
|
|
SS_Datetime::set_mock_now(date('Y-m-d H:i:s', strtotime('+2 hours'))); |
|
39
|
|
|
|
|
40
|
|
|
// Retry step |
|
41
|
|
|
$step->start(); |
|
42
|
|
|
$this->assertEquals('Finished', $step->Status); |
|
|
|
|
|
|
43
|
|
|
$this->assertTrue($step->isTimedOut()); |
|
|
|
|
|
|
44
|
|
|
|
|
45
|
|
|
// check a log entry exists |
|
46
|
|
|
$this->assertHasLog('RollbackWindowStep is older than 3600 seconds and has timed out'); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function testRollback() { |
|
50
|
|
|
SS_Datetime::set_mock_now(date('Y-m-d H:i:s')); |
|
51
|
|
|
$step = $this->getDummyConfirmationStep(); |
|
52
|
|
|
|
|
53
|
|
|
$step->start(); |
|
54
|
|
|
$step->rollback(); |
|
55
|
|
|
|
|
56
|
|
|
// Assert not error at startup |
|
57
|
|
|
$this->assertEquals('Started', $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->RolledBack); |
|
|
|
|
|
|
61
|
|
|
|
|
62
|
|
|
$this->assertHasLog('RollbackWindowStep is being rolled back'); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function testDismiss() { |
|
66
|
|
|
SS_Datetime::set_mock_now(date('Y-m-d H:i:s')); |
|
67
|
|
|
$step = $this->getDummyConfirmationStep(); |
|
68
|
|
|
|
|
69
|
|
|
$step->start(); |
|
70
|
|
|
$step->dismiss(); |
|
71
|
|
|
|
|
72
|
|
|
// Assert not error at startup |
|
73
|
|
|
$this->assertEquals('Finished', $step->Status); |
|
|
|
|
|
|
74
|
|
|
$this->assertHasLog('Dismissing rollback window.'); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
View Code Duplication |
public function testCanRollback() { |
|
|
|
|
|
|
78
|
|
|
$step = $this->getDummyConfirmationStep(); |
|
79
|
|
|
|
|
80
|
|
|
$step->start(); |
|
81
|
|
|
|
|
82
|
|
|
// can the author trigger a rollback |
|
83
|
|
|
$member = Member::get_by_id('Member', $step->Pipeline()->AuthorID); |
|
84
|
|
|
$member->logIn(); |
|
85
|
|
|
|
|
86
|
|
|
$this->assertTrue($step->canTriggerRollback()); |
|
|
|
|
|
|
87
|
|
|
|
|
88
|
|
|
// can another member with deploy permissions trigger a rollback |
|
89
|
|
|
$member = Member::get() |
|
90
|
|
|
->filter('Email', '[email protected]') |
|
91
|
|
|
->first(); |
|
92
|
|
|
$member->logIn(); |
|
93
|
|
|
$this->assertTrue($step->canTriggerRollback()); |
|
|
|
|
|
|
94
|
|
|
|
|
95
|
|
|
$this->logInWithPermission('APPLY_ROLES'); |
|
96
|
|
|
$this->assertFalse($step->canTriggerRollback()); |
|
|
|
|
|
|
97
|
|
|
|
|
98
|
|
|
$this->logInWithPermission('ADMIN'); |
|
99
|
|
|
$this->assertTrue($step->canTriggerRollback()); |
|
|
|
|
|
|
100
|
|
|
|
|
101
|
|
|
// confirm other members without admin permissions can not trigger a rollback |
|
102
|
|
|
$member = Member::get() |
|
103
|
|
|
->filter('Email', '[email protected]') |
|
104
|
|
|
->first(); |
|
105
|
|
|
$member->logIn(); |
|
106
|
|
|
$this->assertFalse($step->canTriggerRollback()); |
|
|
|
|
|
|
107
|
|
|
|
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
public function testBeginRollbackWindow() { |
|
111
|
|
|
$step = $this->getDummyConfirmationStep(); |
|
112
|
|
|
|
|
113
|
|
|
$step->start(); |
|
114
|
|
|
|
|
115
|
|
|
$this->logInWithPermission('APPLY_ROLES'); |
|
116
|
|
|
$this->assertTrue($step->beginRollbackWindow()); |
|
|
|
|
|
|
117
|
|
|
|
|
118
|
|
|
// Check that the message is sent |
|
119
|
|
|
$this->assertSentMessage('Deployment for testproject/uat has successfully completed', '[email protected]'); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
public function testRunningConfiguration() { |
|
123
|
|
|
$step = $this->getDummyConfirmationStep(); |
|
124
|
|
|
|
|
125
|
|
|
$step->start(); |
|
126
|
|
|
$this->logInWithPermission('ADMIN'); |
|
127
|
|
|
$this->assertEquals('You may now roll back to the previous version, if needed.', |
|
|
|
|
|
|
128
|
|
|
$step->getRunningDescription()); |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
public function testStartFail() { |
|
132
|
|
|
$step = $this->getDummyConfirmationStep(); |
|
133
|
|
|
// set status so it fails |
|
134
|
|
|
$step->Status = 'Failed'; |
|
135
|
|
|
|
|
136
|
|
|
$this->assertFalse($step->start()); |
|
|
|
|
|
|
137
|
|
|
|
|
138
|
|
|
// Check that the message is sent |
|
139
|
|
|
$this->assertNotSentMessage('Deployment for testproject/uat has successfully completed', '[email protected]'); |
|
140
|
|
|
} |
|
141
|
|
|
} |
|
142
|
|
|
|
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.