forked from docker-php/docker-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImageResourceTest.php
More file actions
91 lines (69 loc) · 2.73 KB
/
Copy pathImageResourceTest.php
File metadata and controls
91 lines (69 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
declare(strict_types=1);
namespace Docker\Tests\Resource;
use Docker\API\Client;
use Docker\API\Model\AuthConfig;
use Docker\Context\ContextBuilder;
use Docker\Tests\TestCase;
class ImageResourceTest extends TestCase
{
/**
* Return a container manager.
*/
private function getManager()
{
return self::getDocker();
}
public function testBuild(): void
{
$contextBuilder = new ContextBuilder();
$contextBuilder->from('ubuntu:precise');
$contextBuilder->add('/test', 'test file content');
$context = $contextBuilder->getContext();
$buildStream = $this->getManager()->imageBuild($context->read(), ['t' => 'test-image']);
$this->assertInstanceOf('Docker\Stream\BuildStream', $buildStream);
$lastMessage = '';
$buildStream->onFrame(function ($frame) use (&$lastMessage): void {
$lastMessage = $frame->getStream();
});
$buildStream->wait();
$this->assertContains('Successfully', $lastMessage);
}
public function testCreate(): void
{
$createImageStream = $this->getManager()->imageCreate('', [
'fromImage' => 'registry:latest',
]);
$this->assertInstanceOf('Docker\Stream\CreateImageStream', $createImageStream);
$firstMessage = null;
$createImageStream->onFrame(function ($createImageInfo) use (&$firstMessage): void {
if (null === $firstMessage) {
$firstMessage = $createImageInfo->getStatus();
}
});
$createImageStream->wait();
$this->assertContains('Pulling from library/registry', $firstMessage);
}
public function testPushStream(): void
{
$contextBuilder = new ContextBuilder();
$contextBuilder->from('ubuntu:precise');
$contextBuilder->add('/test', 'test file content');
$context = $contextBuilder->getContext();
$this->getManager()->imageBuild($context->read(), ['t' => 'localhost:5000/test-image'], [], Client::FETCH_OBJECT);
$registryConfig = new AuthConfig();
$registryConfig->setServeraddress('localhost:5000');
$pushImageStream = $this->getManager()->imagePush('localhost:5000/test-image', [], [
'X-Registry-Auth' => $registryConfig,
]);
$this->assertInstanceOf('Docker\Stream\PushStream', $pushImageStream);
$firstMessage = null;
$pushImageStream->onFrame(function ($pushImageInfo) use (&$firstMessage): void {
if (null === $firstMessage) {
$firstMessage = $pushImageInfo->getStatus();
}
});
$pushImageStream->wait();
$this->assertContains('repository [localhost:5000/test-image]', $firstMessage);
}
}