|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* this file is part of pipelines */ |
|
4
|
|
|
|
|
5
|
|
|
namespace Ktomk\Pipelines\Integration\Utility; |
|
6
|
|
|
|
|
7
|
|
|
use Ktomk\Pipelines\Cli\Streams; |
|
8
|
|
|
use Ktomk\Pipelines\TestCase; |
|
9
|
|
|
use Ktomk\Pipelines\Utility\App; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* @coversNothing |
|
13
|
|
|
*/ |
|
14
|
|
|
class AppTest extends TestCase |
|
15
|
|
|
{ |
|
16
|
|
|
public function provideArguments() |
|
17
|
|
|
{ |
|
18
|
|
|
return array( |
|
19
|
|
|
array(array('--version')), |
|
20
|
|
|
array(array('--help')), |
|
21
|
|
|
array(array('--show')), |
|
22
|
|
|
array(array('--images')), |
|
23
|
|
|
array(array('--list')), |
|
24
|
|
|
array(array('--dry-run')), |
|
25
|
|
|
array(array('--verbose', '--dry-run')), |
|
26
|
|
|
array(array('--keep', '--no-run')), |
|
27
|
|
|
array(array('--docker-list', '--dry-run')), |
|
28
|
|
|
array(array('--verbatim', '--dry-run')), |
|
29
|
|
|
); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @param array $arguments |
|
34
|
|
|
* @dataProvider provideArguments |
|
35
|
|
|
*/ |
|
36
|
|
|
public function testSuccessfulCommands(array $arguments) |
|
37
|
|
|
{ |
|
38
|
|
|
$app = new App(new Streams()); |
|
39
|
|
|
$args = array_merge((array)'pipelines-test', $arguments); |
|
40
|
|
|
$status = $app->main($args); |
|
41
|
|
|
self::assertSame(0, $status); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function testInvalidPrefixGivesError() |
|
45
|
|
|
{ |
|
46
|
|
|
$app = new App(new Streams(null, null, 'php://output')); |
|
47
|
|
|
$this->expectOutputString("pipelines: invalid prefix: '!\$\"'\n"); |
|
48
|
|
|
$args = array( |
|
49
|
|
|
'pipelines-test', |
|
50
|
|
|
'--prefix', |
|
51
|
|
|
'!$"', |
|
52
|
|
|
); |
|
53
|
|
|
$status = $app->main($args); |
|
54
|
|
|
self::assertSame(1, $status); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function testEmptyBasenameGivesError() |
|
58
|
|
|
{ |
|
59
|
|
|
$app = new App(new Streams(null, null, 'php://output')); |
|
60
|
|
|
$this->expectOutputString("pipelines: not a basename: ''\n"); |
|
61
|
|
|
$args = array( |
|
62
|
|
|
'pipelines-test', |
|
63
|
|
|
'--basename', |
|
64
|
|
|
'', |
|
65
|
|
|
); |
|
66
|
|
|
$status = $app->main($args); |
|
67
|
|
|
self::assertSame(1, $status); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function testFileOverridesBasenameVerbose() |
|
71
|
|
|
{ |
|
72
|
|
|
$app = new App(new Streams(null, 'php://output')); |
|
73
|
|
|
$this->expectOutputRegex( |
|
74
|
|
|
'{^info: --file overrides non-default --basename$}m' |
|
75
|
|
|
); |
|
76
|
|
|
$args = array( |
|
77
|
|
|
'pipelines-test', |
|
78
|
|
|
'--verbose', |
|
79
|
|
|
'--file', |
|
80
|
|
|
'super.yml', |
|
81
|
|
|
'--basename', |
|
82
|
|
|
'my.yml', |
|
83
|
|
|
'--no-run', |
|
84
|
|
|
); |
|
85
|
|
|
$status = $app->main($args); |
|
86
|
|
|
self::assertSame(1, $status); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
public function testNonReadableFilename() |
|
90
|
|
|
{ |
|
91
|
|
|
$app = new App(new Streams(null, null, 'php://output')); |
|
92
|
|
|
$this->expectOutputString( |
|
93
|
|
|
'pipelines: not a readable file: ' |
|
94
|
|
|
. "/rooter/home/galore/not/found/super.yml\n" |
|
95
|
|
|
); |
|
96
|
|
|
$args = array( |
|
97
|
|
|
'pipelines-test', |
|
98
|
|
|
'--file', |
|
99
|
|
|
'/rooter/home/galore/not/found/super.yml', |
|
100
|
|
|
'--no-run', |
|
101
|
|
|
); |
|
102
|
|
|
$status = $app->main($args); |
|
103
|
|
|
self::assertSame(1, $status); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
public function testUnknownOption() |
|
107
|
|
|
{ |
|
108
|
|
|
$app = new App(new Streams(null, null, 'php://output')); |
|
109
|
|
|
$this->expectOutputString( |
|
110
|
|
|
"pipelines: unknown option: --for-the-fish-thank-you\n" |
|
111
|
|
|
); |
|
112
|
|
|
$args = array( |
|
113
|
|
|
'pipelines-test', |
|
114
|
|
|
'--for-the-fish-thank-you', |
|
115
|
|
|
); |
|
116
|
|
|
$status = $app->main($args); |
|
117
|
|
|
self::assertSame(1, $status); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
public function testInvalidWrongPipelineNameArgumentException() |
|
121
|
|
|
{ |
|
122
|
|
|
$this->expectOutputRegex( |
|
123
|
|
|
"~^pipelines: pipeline 'test/more' unavailable\n~" |
|
124
|
|
|
); |
|
125
|
|
|
$app = new App(new Streams(null, null, 'php://output')); |
|
126
|
|
|
$args = array( |
|
127
|
|
|
'pipelines-test', |
|
128
|
|
|
'--debug', '--pipeline', 'test/more', |
|
129
|
|
|
); |
|
130
|
|
|
$status = $app->main($args); |
|
131
|
|
|
self::assertSame(1, $status); |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
public function testCopyDeployMode() |
|
135
|
|
|
{ |
|
136
|
|
|
$app = new App(new Streams(null, null, null)); |
|
137
|
|
|
$args = array( |
|
138
|
|
|
'pipelines-test', |
|
139
|
|
|
'--deploy', 'copy', '--dry-run', |
|
140
|
|
|
); |
|
141
|
|
|
$status = $app->main($args); |
|
142
|
|
|
self::assertSame(0, $status); |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
public function testArtifacts() |
|
146
|
|
|
{ |
|
147
|
|
|
$app = new App(new Streams(null, null, null)); |
|
148
|
|
|
$args = array( |
|
149
|
|
|
'pipelines-test', |
|
150
|
|
|
'--deploy', 'copy', '--pipeline', 'custom/artifact-tests', |
|
151
|
|
|
'--dry-run', |
|
152
|
|
|
); |
|
153
|
|
|
$status = $app->main($args); |
|
154
|
|
|
self::assertSame(0, $status); |
|
155
|
|
|
} |
|
156
|
|
|
} |
|
157
|
|
|
|