|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* this file is part of pipelines */ |
|
4
|
|
|
|
|
5
|
|
|
namespace Ktomk\Pipelines\Integration\Runner\Docker\Binary; |
|
6
|
|
|
|
|
7
|
|
|
use Ktomk\Pipelines\Cli\Exec; |
|
8
|
|
|
use Ktomk\Pipelines\Cli\ExecTester; |
|
9
|
|
|
use Ktomk\Pipelines\Cli\Streams; |
|
10
|
|
|
use Ktomk\Pipelines\File\Pipeline\Step; |
|
11
|
|
|
use Ktomk\Pipelines\LibFs; |
|
12
|
|
|
use Ktomk\Pipelines\LibFsPath; |
|
13
|
|
|
use Ktomk\Pipelines\LibTmp; |
|
14
|
|
|
use Ktomk\Pipelines\Project; |
|
15
|
|
|
use Ktomk\Pipelines\Runner\Directories; |
|
16
|
|
|
use Ktomk\Pipelines\Runner\DirectoriesTest; |
|
17
|
|
|
use Ktomk\Pipelines\Runner\Docker\Binary\Repository; |
|
18
|
|
|
use Ktomk\Pipelines\Runner\Env; |
|
19
|
|
|
use Ktomk\Pipelines\Runner\Flags; |
|
20
|
|
|
use Ktomk\Pipelines\Runner\Runner; |
|
21
|
|
|
use Ktomk\Pipelines\Runner\RunOpts; |
|
22
|
|
|
use Ktomk\Pipelines\TestCase; |
|
23
|
|
|
use Ktomk\Pipelines\Value\SideEffect\DestructibleString; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Class DockerBinaryTest |
|
27
|
|
|
* |
|
28
|
|
|
* @covers \Ktomk\Pipelines\Runner\Docker\Binary\Repository |
|
29
|
|
|
*/ |
|
30
|
|
|
class RepositoryTest extends TestCase |
|
31
|
|
|
{ |
|
32
|
|
|
/** |
|
33
|
|
|
* @var array store destructible objects to test-case life-time |
|
34
|
|
|
*/ |
|
35
|
|
|
private $cleaners; |
|
36
|
|
|
|
|
37
|
|
|
public function testCreation() |
|
38
|
|
|
{ |
|
39
|
|
|
$binary = Repository::create(new ExecTester($this), $this->createMock('Ktomk\Pipelines\Runner\Directories')); |
|
40
|
|
|
self::assertInstanceOf('Ktomk\Pipelines\Runner\Docker\Binary\Repository', $binary); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* test injection but also take care that the test home directory is prepped with |
|
45
|
|
|
* the package downloads. |
|
46
|
|
|
* |
|
47
|
|
|
* downloads 60.3 MiB docker-19.03.1.tgz and untars 65.6 MiB docker binary from it |
|
48
|
|
|
*/ |
|
49
|
|
|
public function testInjection() |
|
50
|
|
|
{ |
|
51
|
|
|
// TODO $homeDir = LibFs::tmpDir('pipelines-test-home.'); |
|
52
|
|
|
// currently using project local directory to keep artifacts on local build, but |
|
53
|
|
|
// there should be the local test-package with the stub which works completely |
|
54
|
|
|
// offline. |
|
55
|
|
|
$homeDir = LibFsPath::normalizeSegments(__DIR__ . '/../../../../../build/store/home'); |
|
56
|
|
|
LibFs::mkDir($homeDir); |
|
57
|
|
|
|
|
58
|
|
|
$exec = new Exec(); |
|
59
|
|
|
$repository = Repository::create( |
|
60
|
|
|
$exec, |
|
61
|
|
|
new Directories(array('HOME' => $homeDir), DirectoriesTest::getTestProject()) |
|
62
|
|
|
); |
|
63
|
|
|
$repository->resolve(Repository::PKG_INTEGRATE); |
|
64
|
|
|
$containerId = '424242-so-long-and-thanks-for-all-the-fish'; |
|
65
|
|
|
list($status, $message) = $repository->inject($containerId); |
|
66
|
|
|
self::assertSame(1, $status); |
|
67
|
|
|
self::assertMatchesRegularExpression("~${containerId}~", $message); |
|
68
|
|
|
$this->addToAssertionCount(1); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* integration test w/ temporary home directory (works offline but needs a writeable /tmp directory) |
|
73
|
|
|
*/ |
|
74
|
|
|
public function testInjectIntegration() |
|
75
|
|
|
{ |
|
76
|
|
|
$homeDir = DestructibleString::rmDir(LibTmp::tmpDir('pipelines-test-home.')); |
|
77
|
|
|
|
|
78
|
|
|
$directories = new Directories(array('HOME' => (string)$homeDir), new Project('bar')); |
|
79
|
|
|
$repository = Repository::create(new Exec(), $directories); |
|
80
|
|
|
$repository->resolve(Repository::PKG_TEST); |
|
81
|
|
|
$actual = $repository->inject('42-bin-sh'); |
|
82
|
|
|
self::assertSame(array(1, "Error: No such container: 42-bin-sh\n"), $actual); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* NOTE: This test still requires to have the download untarred |
|
87
|
|
|
* |
|
88
|
|
|
* testInjection dependency creates build home and local docker binary to inject |
|
89
|
|
|
* |
|
90
|
|
|
* @depends testInjection |
|
91
|
|
|
* @covers \Ktomk\Pipelines\Runner\Runner |
|
92
|
|
|
*/ |
|
93
|
|
|
public function testRunnerWithDeploy() |
|
94
|
|
|
{ |
|
95
|
|
|
$prefix = 'pipelinesintegrationtest'; |
|
96
|
|
|
|
|
97
|
|
|
$homeDir = LibFsPath::normalizeSegments(__DIR__ . '/../../../../../build/store/home'); |
|
98
|
|
|
$project = LibTmp::tmpDir('pipelines-test-suite.'); |
|
99
|
|
|
$this->cleaners[] = DestructibleString::rmDir($project); |
|
100
|
|
|
$directories = new Directories(array('HOME' => $homeDir), new Project($project)); |
|
101
|
|
|
$exec = new ExecTester($this); |
|
102
|
|
|
$env = new Env(); |
|
103
|
|
|
$streams = new Streams(null, 'php://output'); |
|
104
|
|
|
$runner = Runner::createEx( |
|
105
|
|
|
RunOpts::create($prefix, Repository::PKG_INTEGRATE), |
|
106
|
|
|
$directories, |
|
107
|
|
|
$exec, |
|
108
|
|
|
new Flags(), |
|
109
|
|
|
$env, |
|
110
|
|
|
$streams |
|
111
|
|
|
); |
|
112
|
|
|
|
|
113
|
|
|
$pipeline = $this->createMock('Ktomk\Pipelines\File\Pipeline'); |
|
114
|
|
|
$file = $this->createMock('Ktomk\Pipelines\File\File'); |
|
115
|
|
|
$image = $this->createMock('Ktomk\Pipelines\File\Image'); |
|
116
|
|
|
$definitions = $this->createMock('Ktomk\Pipelines\File\Definitions'); |
|
117
|
|
|
$caches = $this->createPartialMock('Ktomk\Pipelines\File\Definitions\Caches', array()); |
|
118
|
|
|
$definitions->method('getCaches')->willReturn($caches); |
|
119
|
|
|
$services = $this->createMock('Ktomk\Pipelines\File\Definitions\Services'); |
|
120
|
|
|
$definitions->method('getServices')->willReturn($services); |
|
121
|
|
|
|
|
122
|
|
|
$image->method('getProperties')->willReturn(array()); |
|
123
|
|
|
$file->method('getImage')->willReturn($image); |
|
124
|
|
|
$pipeline->method('getFile')->willReturn($file); |
|
125
|
|
|
$file->method('getDefinitions')->willReturn($definitions); |
|
126
|
|
|
|
|
127
|
|
|
$array = array( |
|
128
|
|
|
'script' => array(':'), |
|
129
|
|
|
'services' => array('docker'), |
|
130
|
|
|
); |
|
131
|
|
|
$step = new Step($pipeline, 1, $array); |
|
132
|
|
|
|
|
133
|
|
|
$exec->expect('capture', 'docker', 0, 'container id by name'); |
|
134
|
|
|
$exec->expect('capture', 'docker', 0, 'run container'); |
|
135
|
|
|
$exec->expect('pass', '~^<<\'SCRIPT\' docker exec ~', 0, 'run step script'); |
|
136
|
|
|
$exec->expect('capture', 'docker', 'kill'); |
|
137
|
|
|
$exec->expect('capture', 'docker', 'rm'); |
|
138
|
|
|
|
|
139
|
|
|
$this->expectOutputRegex('~\Qpipelinesintegrationtest-2.no-name.null.pipelines-test-suite\E~'); |
|
140
|
|
|
$actual = $runner->runStep($step); |
|
141
|
|
|
self::assertSame(0, $actual); |
|
142
|
|
|
} |
|
143
|
|
|
} |
|
144
|
|
|
|