|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* this file is part of pipelines */ |
|
4
|
|
|
|
|
5
|
|
|
namespace Ktomk\Pipelines\Utility; |
|
6
|
|
|
|
|
7
|
|
|
use Ktomk\Pipelines\Cli\Args; |
|
8
|
|
|
use Ktomk\Pipelines\Cli\ArgsException; |
|
9
|
|
|
use Ktomk\Pipelines\Cli\ExecTester; |
|
10
|
|
|
use Ktomk\Pipelines\Cli\Streams; |
|
11
|
|
|
use Ktomk\Pipelines\TestCase; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @covers \Ktomk\Pipelines\Utility\RunnerOptions |
|
15
|
|
|
*/ |
|
16
|
|
|
class RunnerOptionsTest extends TestCase |
|
17
|
|
|
{ |
|
18
|
|
|
public function testCreation() |
|
19
|
|
|
{ |
|
20
|
|
|
$args = Args::create(array('cmd', '--error-keep', '--prefix', 'prefix', '--docker-client', __FILE__)); |
|
21
|
|
|
$runner = RunnerOptions::bind($args, Streams::create()); |
|
22
|
|
|
self::assertInstanceOf('Ktomk\Pipelines\Utility\RunnerOptions', $runner); |
|
23
|
|
|
|
|
24
|
|
|
return $runner; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @depends testCreation |
|
29
|
|
|
* |
|
30
|
|
|
* @param RunnerOptions $runner |
|
31
|
|
|
* |
|
32
|
|
|
* @throws ArgsException |
|
33
|
|
|
* @throws StatusException |
|
34
|
|
|
*/ |
|
35
|
|
|
public function testParse(RunnerOptions $runner) |
|
36
|
|
|
{ |
|
37
|
|
|
$actual = $runner->run(); |
|
38
|
|
|
self::assertInstanceOf('Ktomk\Pipelines\Runner\RunOpts', $actual); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @throws ArgsException |
|
43
|
|
|
* @throws StatusException |
|
44
|
|
|
*/ |
|
45
|
|
|
public function testInvalidPrefix() |
|
46
|
|
|
{ |
|
47
|
|
|
$args = Args::create(array('cmd', '--prefix', '123')); |
|
48
|
|
|
$this->expectException('Ktomk\Pipelines\Cli\ArgsException'); |
|
49
|
|
|
$this->expectExceptionMessage('invalid prefix: \'123\''); |
|
50
|
|
|
RunnerOptions::bind($args, Streams::create())->run(); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @throws ArgsException |
|
55
|
|
|
* @throws StatusException |
|
56
|
|
|
*/ |
|
57
|
|
|
public function testListPackages() |
|
58
|
|
|
{ |
|
59
|
|
|
$args = Args::create(array('cmd', '--docker-client-pkgs')); |
|
60
|
|
|
$streams = new Streams(null, 'php://output', null); |
|
61
|
|
|
$this->expectOutputRegex('(^\Qdocker-42.42.1-binsh-test-stub\E$)m'); |
|
62
|
|
|
$this->expectException('Ktomk\Pipelines\Utility\StatusException'); |
|
63
|
|
|
$this->expectExceptionMessage(''); |
|
64
|
|
|
$this->expectExceptionCode(0); |
|
65
|
|
|
RunnerOptions::bind($args, $streams)->run(); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @throws ArgsException |
|
70
|
|
|
* @throws StatusException |
|
71
|
|
|
*/ |
|
72
|
|
|
public function testListPackagesOnInvalidClient() |
|
73
|
|
|
{ |
|
74
|
|
|
$args = Args::create(array('cmd', '--docker-client', 'oh-so-much-fake')); |
|
75
|
|
|
$streams = new Streams(null, 'php://output', null); |
|
76
|
|
|
$this->expectException( |
|
77
|
|
|
'Ktomk\Pipelines\Cli\ArgsException' |
|
78
|
|
|
); |
|
79
|
|
|
$this->expectExceptionMessageMatches( |
|
80
|
|
|
'(\Q \'oh-so-much-fake\' given\E$)m' |
|
81
|
|
|
); |
|
82
|
|
|
$this->expectExceptionCode( |
|
83
|
|
|
1 |
|
84
|
|
|
); |
|
85
|
|
|
RunnerOptions::bind($args, $streams)->run(); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @throws ArgsException |
|
90
|
|
|
* @throws StatusException |
|
91
|
|
|
*/ |
|
92
|
|
|
public function testUserOptionSet() |
|
93
|
|
|
{ |
|
94
|
|
|
$args = Args::create(array('cmd', '--user', '--user')); # two tests |
|
95
|
|
|
|
|
96
|
|
|
$streams = new Streams(null, 'php://output', 'php://output'); |
|
97
|
|
|
|
|
98
|
|
|
$exec = new ExecTester($this); |
|
99
|
|
|
$runnerOptions = new RunnerOptions($args, $streams, $exec); |
|
100
|
|
|
|
|
101
|
|
|
$exec->expect('capture', '~^printf ~', 0); |
|
102
|
|
|
|
|
103
|
|
|
$runOpts = $runnerOptions->run(); |
|
104
|
|
|
self::assertIsString($runOpts->getUser()); |
|
105
|
|
|
|
|
106
|
|
|
$exec->expect('capture', '~^printf ~', 1); |
|
107
|
|
|
|
|
108
|
|
|
$this->expectException('Ktomk\Pipelines\Cli\ArgsException'); |
|
109
|
|
|
$this->expectExceptionMessage('--user internal error to resolve id -u / id -g: 1'); |
|
110
|
|
|
|
|
111
|
|
|
$runOpts = $runnerOptions->run(); |
|
112
|
|
|
$runOpts->getUser(); |
|
113
|
|
|
} |
|
114
|
|
|
} |
|
115
|
|
|
|