From 078379254d742dc7b1b15cc4d9b041c6490d539d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Mon, 12 Aug 2024 11:06:27 +0000 Subject: [PATCH 01/23] Add large log test --- composer.lock | 28 +++++++++++------------ tests/Orchestration/Base.php | 26 +++++++++++++++++++++ tests/Orchestration/Resources/php/logs.sh | 17 ++++++++++++++ 3 files changed, 57 insertions(+), 14 deletions(-) create mode 100644 tests/Orchestration/Resources/php/logs.sh diff --git a/composer.lock b/composer.lock index 93e43eb..44535d1 100644 --- a/composer.lock +++ b/composer.lock @@ -178,16 +178,16 @@ }, { "name": "laravel/pint", - "version": "v1.17.0", + "version": "v1.17.2", "source": { "type": "git", "url": "https://github.com/laravel/pint.git", - "reference": "4dba80c1de4b81dc4c4fb10ea6f4781495eb29f5" + "reference": "e8a88130a25e3f9d4d5785e6a1afca98268ab110" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/pint/zipball/4dba80c1de4b81dc4c4fb10ea6f4781495eb29f5", - "reference": "4dba80c1de4b81dc4c4fb10ea6f4781495eb29f5", + "url": "https://api.github.com/repos/laravel/pint/zipball/e8a88130a25e3f9d4d5785e6a1afca98268ab110", + "reference": "e8a88130a25e3f9d4d5785e6a1afca98268ab110", "shasum": "" }, "require": { @@ -198,13 +198,13 @@ "php": "^8.1.0" }, "require-dev": { - "friendsofphp/php-cs-fixer": "^3.59.3", - "illuminate/view": "^10.48.12", - "larastan/larastan": "^2.9.7", + "friendsofphp/php-cs-fixer": "^3.61.1", + "illuminate/view": "^10.48.18", + "larastan/larastan": "^2.9.8", "laravel-zero/framework": "^10.4.0", "mockery/mockery": "^1.6.12", "nunomaduro/termwind": "^1.15.1", - "pestphp/pest": "^2.34.8" + "pestphp/pest": "^2.35.0" }, "bin": [ "builds/pint" @@ -240,7 +240,7 @@ "issues": "https://github.com/laravel/pint/issues", "source": "https://github.com/laravel/pint" }, - "time": "2024-07-23T16:40:20+00:00" + "time": "2024-08-06T15:11:54+00:00" }, { "name": "myclabs/deep-copy", @@ -480,16 +480,16 @@ }, { "name": "phpstan/phpstan", - "version": "1.11.8", + "version": "1.11.10", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "6adbd118e6c0515dd2f36b06cde1d6da40f1b8ec" + "reference": "640410b32995914bde3eed26fa89552f9c2c082f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/6adbd118e6c0515dd2f36b06cde1d6da40f1b8ec", - "reference": "6adbd118e6c0515dd2f36b06cde1d6da40f1b8ec", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/640410b32995914bde3eed26fa89552f9c2c082f", + "reference": "640410b32995914bde3eed26fa89552f9c2c082f", "shasum": "" }, "require": { @@ -534,7 +534,7 @@ "type": "github" } ], - "time": "2024-07-24T07:01:22+00:00" + "time": "2024-08-08T09:02:50+00:00" }, { "name": "phpunit/php-code-coverage", diff --git a/tests/Orchestration/Base.php b/tests/Orchestration/Base.php index b6be5f7..d98f61e 100644 --- a/tests/Orchestration/Base.php +++ b/tests/Orchestration/Base.php @@ -317,6 +317,32 @@ public function testExecContainer(): void ); $this->assertEquals('Hello World! testEnviromentVariable', $output); + + /** + * Test for Success + */ + $output = ''; + + static::getOrchestration()->execute( + 'TestContainer', + [ + 'sh', + 'logs.sh' + ], + $output, + [ + 'test' => 'testEnviromentVariable', + ], + ); + + $length = 0; + $length += 917504; // 128kb * 7 + $length += 5; // "start" + $length += 3; // "end" + + $this->assertStringStartsWith($length, \strlen($output)); + $this->assertEquals("start", $output); + $this->assertStringEndsWith("end", $output); } /** diff --git a/tests/Orchestration/Resources/php/logs.sh b/tests/Orchestration/Resources/php/logs.sh new file mode 100644 index 0000000..1ade1aa --- /dev/null +++ b/tests/Orchestration/Resources/php/logs.sh @@ -0,0 +1,17 @@ +set -e + +CHARS_128="11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111" +CHARS_1KB="$CHARS_128$CHARS_128$CHARS_128$CHARS_128$CHARS_128$CHARS_128$CHARS_128$CHARS_128" +CHARS_16KB="$CHARS_1KB$CHARS_1KB$CHARS_1KB$CHARS_1KB$CHARS_1KB$CHARS_1KB$CHARS_1KB$CHARS_1KB$CHARS_1KB$CHARS_1KB$CHARS_1KB$CHARS_1KB$CHARS_1KB$CHARS_1KB$CHARS_1KB$CHARS_1KB" +CHARS_128KB="$CHARS_16KB$CHARS_16KB$CHARS_16KB$CHARS_16KB$CHARS_16KB$CHARS_16KB$CHARS_16KB$CHARS_16KB" + +# 7 * 128KB +echo -n "START" +echo -n "$CHARS_128KB" +echo -n "$CHARS_128KB" +echo -n "$CHARS_128KB" +echo -n "$CHARS_128KB" +echo -n "$CHARS_128KB" +echo -n "$CHARS_128KB" +echo -n "$CHARS_128KB" +echo -n "END" \ No newline at end of file From 9d23687049752ac80d56f17f292c85182d9210d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Mon, 12 Aug 2024 11:11:28 +0000 Subject: [PATCH 02/23] linter fix --- tests/Orchestration/Base.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Orchestration/Base.php b/tests/Orchestration/Base.php index d98f61e..83877a7 100644 --- a/tests/Orchestration/Base.php +++ b/tests/Orchestration/Base.php @@ -327,7 +327,7 @@ public function testExecContainer(): void 'TestContainer', [ 'sh', - 'logs.sh' + 'logs.sh', ], $output, [ @@ -341,8 +341,8 @@ public function testExecContainer(): void $length += 3; // "end" $this->assertStringStartsWith($length, \strlen($output)); - $this->assertEquals("start", $output); - $this->assertStringEndsWith("end", $output); + $this->assertEquals('start', $output); + $this->assertStringEndsWith('end', $output); } /** From 8ae4e4e90c11dc75caabad0e9ac46e535e2e25d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Mon, 12 Aug 2024 11:18:48 +0000 Subject: [PATCH 03/23] Fix test --- tests/Orchestration/Base.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/tests/Orchestration/Base.php b/tests/Orchestration/Base.php index 83877a7..11caef0 100644 --- a/tests/Orchestration/Base.php +++ b/tests/Orchestration/Base.php @@ -329,10 +329,7 @@ public function testExecContainer(): void 'sh', 'logs.sh', ], - $output, - [ - 'test' => 'testEnviromentVariable', - ], + $output ); $length = 0; @@ -340,8 +337,8 @@ public function testExecContainer(): void $length += 5; // "start" $length += 3; // "end" - $this->assertStringStartsWith($length, \strlen($output)); - $this->assertEquals('start', $output); + $this->assertEquals($length, \strlen($output)); + $this->assertStringStartsWith('start', $output); $this->assertStringEndsWith('end', $output); } From b39595cfeaef60f641ac4d74315c1908b980bb82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Mon, 12 Aug 2024 13:04:59 +0000 Subject: [PATCH 04/23] Fix tests & CI/CD flow --- .github/workflows/test.yml | 7 ++++--- Dockerfile | 10 +++++++-- docker-compose.yml | 4 +++- phpunit.xml | 2 +- tests/Orchestration/Base.php | 39 +++++++++++++++++++----------------- 5 files changed, 37 insertions(+), 25 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 00096f3..c5e5ce5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -21,8 +21,9 @@ jobs: - name: Validate composer.json and composer.lock run: composer validate --strict - - name: Compose install - run: composer install --ignore-platform-reqs + - name: Start container + # For local testing, also run this before retrying tests: docker rm --force $(docker ps -aq) + run: docker compose up -d && sleep 15 - name: Run tests - run: composer test \ No newline at end of file + run: docker compose exec tests vendor/bin/phpunit --configuration phpunit.xml \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 5e8a951..e913320 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,16 +9,22 @@ COPY composer.lock /usr/local/src/ COPY composer.json /usr/local/src/ RUN composer install --ignore-platform-reqs --optimize-autoloader --no-plugins --no-scripts --prefer-dist - + +RUN docker-php-ext-install sockets + FROM php:8.0-cli-alpine as final +ENV DOCKER_CONFIG=${DOCKER_CONFIG:-$HOME/.docker} +ENV DOCKER_API_VERSION=1.43 + LABEL maintainer="team@appwrite.io" RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone RUN \ apk update \ - && apk add --no-cache make automake autoconf gcc g++ git brotli-dev \ + && apk add --no-cache make automake autoconf gcc g++ git brotli-dev docker-cli \ + && docker-php-ext-install sockets \ && docker-php-ext-install opcache WORKDIR /usr/src/code diff --git a/docker-compose.yml b/docker-compose.yml index d7c2211..9123116 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,7 +7,9 @@ services: context: . networks: - orchestration - volumes: + environment: + HOST_DIR: "$PWD" # Nessessary to mount test resources to child containers + volumes: - ./:/usr/src/code - /var/run/docker.sock:/var/run/docker.sock diff --git a/phpunit.xml b/phpunit.xml index ec39a7e..10d408c 100755 --- a/phpunit.xml +++ b/phpunit.xml @@ -6,7 +6,7 @@ convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" - stopOnFailure="false" + stopOnFailure="true" > diff --git a/tests/Orchestration/Base.php b/tests/Orchestration/Base.php index 11caef0..f9ca81b 100644 --- a/tests/Orchestration/Base.php +++ b/tests/Orchestration/Base.php @@ -58,10 +58,10 @@ public function testCreateContainer(): void '', '/usr/local/src/', [ - __DIR__.'/Resources:/test:rw', + \getenv('HOST_DIR').'/tests/Orchestration/Resources:/test:rw', ], [], - __DIR__.'/Resources' + \getenv('HOST_DIR').'/tests/Orchestration/Resources' ); $this->assertNotEmpty($response); @@ -78,22 +78,22 @@ public function testCreateContainer(): void '', '/usr/local/src/', [ - __DIR__.'/Resources:/test:rw', + \getenv('HOST_DIR').'/tests/Orchestration/Resources:/test:rw', ], [], - __DIR__.'/Resources', + \getenv('HOST_DIR').'/tests/Orchestration/Resources', restart: DockerAPI::RESTART_ALWAYS ); $this->assertNotEmpty($response); - sleep(7); + sleep(10); // Docker restart can take quite long to restart. This is safety to prevent flaky tests $output = []; \exec('docker logs '.$response, $output); $output = \implode("\n", $output); $occurances = \substr_count($output, 'Custom start'); - $this->assertGreaterThanOrEqual(5, $occurances); + $this->assertGreaterThanOrEqual(2, $occurances); // 2 logs mean it restarted at least once $response = static::getOrchestration()->remove('TestContainerWithRestart', true); $this->assertEquals(true, $response); @@ -110,10 +110,10 @@ public function testCreateContainer(): void '', '/usr/local/src/', [ - __DIR__.'/Resources:/test:rw', + \getenv('HOST_DIR').'/tests/Orchestration/Resources:/test:rw', ], [], - __DIR__.'/Resources', + \getenv('HOST_DIR').'/tests/Orchestration/Resources', restart: DockerAPI::RESTART_NO ); @@ -147,7 +147,7 @@ public function testCreateContainer(): void '/usr/local/src/', [], [], - __DIR__.'/Resources', + \getenv('HOST_DIR').'/tests/Orchestration/Resources', ); /** @@ -167,7 +167,7 @@ public function testCreateContainer(): void '/usr/local/src/', [], [], - __DIR__.'/Resources', + \getenv('HOST_DIR').'/tests/Orchestration/Resources', ); } @@ -220,7 +220,7 @@ public function testNetworkConnect(): void [ 'teasdsa' => '', ], - __DIR__.'/Resources', + \getenv('HOST_DIR').'/tests/Orchestration/Resources', [ 'test2' => 'Hello World!', ], @@ -321,6 +321,7 @@ public function testExecContainer(): void /** * Test for Success */ + /* $output = ''; static::getOrchestration()->execute( @@ -340,6 +341,7 @@ public function testExecContainer(): void $this->assertEquals($length, \strlen($output)); $this->assertStringStartsWith('start', $output); $this->assertStringEndsWith('end', $output); + */ } /** @@ -381,7 +383,7 @@ public function testTimeoutContainer(): void [ 'teasdsa' => '', ], - __DIR__.'/Resources', + \getenv('HOST_DIR').'/tests/Orchestration/Resources', [ 'test2' => 'Hello World!', ] @@ -477,7 +479,7 @@ public function testListFilters(): void } /** - * @depends testCreateContainer + * @depends testExecContainer */ public function testRemoveContainer(): void { @@ -553,7 +555,7 @@ public function testRunRemove(): void [ 'teasdsa' => '', ], - __DIR__.'/Resources', + \getenv('HOST_DIR').'/tests/Orchestration/Resources', [ 'test2' => 'Hello World!', ], @@ -580,7 +582,8 @@ public function testUsageStats(): void * Test for Success */ $stats = static::getOrchestration()->getStats(); - $this->assertCount(0, $stats, 'Container(s) still running: '.\json_encode($stats, JSON_PRETTY_PRINT)); + // 1 expected due to container running tests + $this->assertCount(1, $stats, 'Container(s) still running: '.\json_encode($stats, JSON_PRETTY_PRINT)); // This allows CPU-heavy load check static::getOrchestration()->setCpus(1); @@ -594,7 +597,7 @@ public function testUsageStats(): void 'apk update && apk add screen && tail -f /dev/null', ], workdir: '/usr/local/src/', - mountFolder: __DIR__.'/Resources', + mountFolder: \getenv('HOST_DIR').'/tests/Orchestration/Resources', labels: ['utopia-container-type' => 'stats'] ); @@ -609,7 +612,7 @@ public function testUsageStats(): void 'apk update && apk add screen && tail -f /dev/null', ], workdir: '/usr/local/src/', - mountFolder: __DIR__.'/Resources', + mountFolder: \getenv('HOST_DIR').'/tests/Orchestration/Resources', ); $this->assertNotEmpty($containerId2); @@ -626,7 +629,7 @@ public function testUsageStats(): void // Fetch stats, should include high CPU usage $stats = static::getOrchestration()->getStats(); - $this->assertCount(2, $stats); + $this->assertCount(2 + 1, $stats); // +1 due to container running tests $this->assertNotEmpty($stats[0]->getContainerId()); $this->assertEquals(64, \strlen($stats[0]->getContainerId())); From c6d30a4e9d5e2092f8e673697d64b1ffd19ad3ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Mon, 12 Aug 2024 13:23:17 +0000 Subject: [PATCH 05/23] Fix tests --- .github/workflows/test.yml | 3 ++ tests/Orchestration/Base.php | 91 +++++++++++++++++++++--------------- 2 files changed, 56 insertions(+), 38 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c5e5ce5..ff12c67 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,6 +20,9 @@ jobs: - name: Validate composer.json and composer.lock run: composer validate --strict + + - name: Install dependencies + run: composer install --ignore-platform-reqs --optimize-autoloader --no-plugins --no-scripts --prefer-dist - name: Start container # For local testing, also run this before retrying tests: docker rm --force $(docker ps -aq) diff --git a/tests/Orchestration/Base.php b/tests/Orchestration/Base.php index f9ca81b..6ca26d8 100644 --- a/tests/Orchestration/Base.php +++ b/tests/Orchestration/Base.php @@ -268,36 +268,44 @@ public function testExecContainer(): void */ $output = ''; - $this->expectException(\Exception::class); - - static::getOrchestration()->execute( - '60clotVWpufbEpy33zJLcoYHrUTqWaD1FV0FZWsw', // Non-Existent Container - [ - 'php', - 'index.php', - ], - $output - ); + $threwException = false; + try { + static::getOrchestration()->execute( + '60clotVWpufbEpy33zJLcoYHrUTqWaD1FV0FZWsw', // Non-Existent Container + [ + 'php', + 'index.php', + ], + $output + ); + } catch(\Exception $err) { + $threwException = true; + } + $this->assertTrue($threwException); /** * Test for Failure */ $output = ''; - $this->expectException(\Exception::class); - - static::getOrchestration()->execute( - 'TestContainer', - [ - 'php', - 'doesnotexist.php', // Non-Existent File - ], - $output, - [ - 'test' => 'testEnviromentVariable', - ], - 1 - ); + $threwException = false; + try { + static::getOrchestration()->execute( + 'TestContainer', + [ + 'php', + 'doesnotexist.php', // Non-Existent File + ], + $output, + [ + 'test' => 'testEnviromentVariable', + ], + 1 + ); + } catch(\Exception $err) { + $threwException = true; + } + $this->assertTrue($threwException); /** * Test for Success @@ -338,6 +346,10 @@ public function testExecContainer(): void $length += 5; // "start" $length += 3; // "end" + \var_dump(\strlen($output)); + \var_dump(\substr($output, 0, 100)); + \var_dump(\substr($output, -100)); + $this->assertEquals($length, \strlen($output)); $this->assertStringStartsWith('start', $output); $this->assertStringEndsWith('end', $output); @@ -397,19 +409,22 @@ public function testTimeoutContainer(): void * Test for Failure */ $output = ''; - - $this->expectException(\Exception::class); - - $response = static::getOrchestration()->execute( - 'TestContainerTimeout', - [ - 'php', - 'index.php', - ], - $output, - [], - 1 - ); + $threwException = false; + try { + $response = static::getOrchestration()->execute( + 'TestContainerTimeout', + [ + 'php', + 'index.php', + ], + $output, + [], + 1 + ); + } catch(\Exception $err) { + $threwException = true; + } + $this->assertTrue($threwException); /** * Test for Success @@ -439,7 +454,7 @@ public function testTimeoutContainer(): void [ 'sh', '-c', - 'echo Hello World!', + 'echo -n Hello World!', // -n prevents from adding linebreak afterwards ], $output, [], From 41644a81ff73eaaec3956837cfbd77e6b836bad0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Mon, 12 Aug 2024 13:28:32 +0000 Subject: [PATCH 06/23] Fix linter --- tests/Orchestration/Base.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/Orchestration/Base.php b/tests/Orchestration/Base.php index 6ca26d8..f687661 100644 --- a/tests/Orchestration/Base.php +++ b/tests/Orchestration/Base.php @@ -277,8 +277,8 @@ public function testExecContainer(): void 'index.php', ], $output - ); - } catch(\Exception $err) { + ); + } catch (\Exception $err) { $threwException = true; } $this->assertTrue($threwException); @@ -302,7 +302,7 @@ public function testExecContainer(): void ], 1 ); - } catch(\Exception $err) { + } catch (\Exception $err) { $threwException = true; } $this->assertTrue($threwException); @@ -421,7 +421,7 @@ public function testTimeoutContainer(): void [], 1 ); - } catch(\Exception $err) { + } catch (\Exception $err) { $threwException = true; } $this->assertTrue($threwException); From fd6c22458a510a182c62ab7efeb244147da22c40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Mon, 12 Aug 2024 13:32:25 +0000 Subject: [PATCH 07/23] Add code QA ci/cd --- .github/workflows/codeql-analysis.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 .github/workflows/codeql-analysis.yml diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml new file mode 100644 index 0000000..3253e2c --- /dev/null +++ b/.github/workflows/codeql-analysis.yml @@ -0,0 +1,16 @@ +name: "CodeQL" + +on: [pull_request] +jobs: + lint: + name: CodeQL + runs-on: ubuntu-latest + + steps: + - name: Check out the repo + uses: actions/checkout@v2 + + - name: Run CodeQL + run: | + docker run --rm -v $PWD:/app composer sh -c \ + "composer install --profile --ignore-platform-reqs && composer check" \ No newline at end of file From ae4c2029c5a227365051fc87ba6864120ad203a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Mon, 12 Aug 2024 14:08:19 +0000 Subject: [PATCH 08/23] Enable logs test --- tests/Orchestration/Base.php | 14 +++++--------- tests/Orchestration/Resources/php.tar.gz | Bin 196 -> 326 bytes tests/Orchestration/Resources/php/README.md | 5 +++++ tests/Orchestration/Resources/timeout.tar.gz | Bin 166 -> 321 bytes tests/Orchestration/Resources/timeout/README.md | 5 +++++ 5 files changed, 15 insertions(+), 9 deletions(-) create mode 100644 tests/Orchestration/Resources/php/README.md create mode 100644 tests/Orchestration/Resources/timeout/README.md diff --git a/tests/Orchestration/Base.php b/tests/Orchestration/Base.php index f687661..a969d79 100644 --- a/tests/Orchestration/Base.php +++ b/tests/Orchestration/Base.php @@ -17,7 +17,9 @@ abstract protected static function getAdapterName(): string; */ public static $containerID; - public function setUp(): void {} + public function setUp(): void { + \exec("rm -rf /usr/src/code/tests/Orchestration/Resources/screens"); // cleanup + } public function tearDown(): void {} @@ -329,7 +331,6 @@ public function testExecContainer(): void /** * Test for Success */ - /* $output = ''; static::getOrchestration()->execute( @@ -346,14 +347,9 @@ public function testExecContainer(): void $length += 5; // "start" $length += 3; // "end" - \var_dump(\strlen($output)); - \var_dump(\substr($output, 0, 100)); - \var_dump(\substr($output, -100)); - $this->assertEquals($length, \strlen($output)); - $this->assertStringStartsWith('start', $output); - $this->assertStringEndsWith('end', $output); - */ + $this->assertStringStartsWith('START', $output); + $this->assertStringEndsWith('END', $output); } /** diff --git a/tests/Orchestration/Resources/php.tar.gz b/tests/Orchestration/Resources/php.tar.gz index a2fccbb55bbbe1d3efe2896f1357e844ba67687c..0127e319737842f6afb07391bcb5734054653a20 100644 GIT binary patch literal 326 zcmV-M0lEGkiwFP!000001MSs8YlAQp2XN2%6j>$+gE|vU9BgH@TcJ?sp)K2Cj54Ow zf>fyv_VE`ts`gNNX=ca%KM%h6Lh|78Fi-Mp%P>z1rL;V*AJuv{EFLJSd?iE0b)E~M zEGkVGR{1E(w=JdCYF*}8ba>yf{2!I;{;xMt{ORh*&>dBSRS+ERzx3<=D-r6v?*-DL zo}qg7{PX_b-Rr&+62B)Ib;fa;X7oARrqKm;Tzfg1KD{_)T$Il1E$O;cFrb?MG+PyJ zkr=z<$oz9(h~4}v;a7Pf1;_mVh9WL$FDB$+JebXwT-@{-?-<(^Ga2@oT^Dwms6Je^ zPoE6WGh$6&+U2Td&q+c?$R!Qw75%>F=V#E{P&Qu-W((G=?N&8s`FS*bWL-}b00000 Y000000000006;gs09tHDAOI);0DF;_Qvd(} literal 196 zcmV;#06YI5iwFSKr14+?1Jl!IpgAxwFfcbYRRGe4=B5Tv+7Lv;fr6olfw_sXk&%&! zp@M;-p^2$EgMumToyNdWT3nJ?1awMfeqLrW9(9D|q5go=Lj>sQXXd4(R_GOE6wu5L zV0f6BnBa+jVB&zqzpK>^%Ir$3V y`9(P?iVErqdI~D>u6|+BN+qeqB}%c@Tm$XcQ7{Td!6+C7R09ANx1N#!3IG7C@L8z< diff --git a/tests/Orchestration/Resources/php/README.md b/tests/Orchestration/Resources/php/README.md new file mode 100644 index 0000000..8f9b2f4 --- /dev/null +++ b/tests/Orchestration/Resources/php/README.md @@ -0,0 +1,5 @@ +If you do changes to confent of this folder, run following command inside `Resources` directory: + +```sh +tar -zcf ./php.tar.gz php +``` \ No newline at end of file diff --git a/tests/Orchestration/Resources/timeout.tar.gz b/tests/Orchestration/Resources/timeout.tar.gz index d1c7c03b9e59c8043f7455f94d39f15e7266f935..5010c0cdd0aa5fec158e47999aca4170bc693d50 100644 GIT binary patch literal 321 zcmV-H0lxkpiwFP!000001MSp7YlAQp2XN1Rig(;#vyB>sZ7>GwVTWD%2`naRpeAA> zTl?u3SxX0_^khrv|0iNJ4}9e1#i>@B!OemR&ApuSV9xxN{dpb)EX{b9vY4mie9TxD z5T7!sy}`OwPZZS3bw(VIJ2ii$+^+sg3;7*&O*g?m#sX()dc6KI`>lWC?>P7KNuJ~Z z%_qp^pBu0L%d4+>7}~Xz-5tMw4lkV$oYlVnmy5Ue&qdTuvBOXGf6Vyd{O8%&|4Gi# z|L5>g(Z&oU43*7F*V2;nL!&FH9hr(;qbyZsEoA>d{h-J3+I%Tp`>3{EX+cU`B_tI~ zY0c1=(iS9CFH2|o%~Kc_MPZw8T;#`XSy43GZMn#Qis~)xUdOmgF9rYr0000000000 T00000z?J#|TnH=P04M+e!TFnV literal 166 zcmb2|=3oE;Cg!&nPjekI5NLh4=C?@XE4AENx1A2A3-V}m@aD40-`{e&X}Yh-$Ny%+ zX-twuA-Y}Jn;zVW*_=A}{H>ORIoI#`{1u4OUZTB!mcaGIJKux4_Psuq{ypw&{ghSy z)1CLMEb%#dZwAx1Yj)@M$39uV)!6d?Ghz7;&wu8ZTmD=nb Date: Mon, 12 Aug 2024 14:14:31 +0000 Subject: [PATCH 09/23] Fix linter --- tests/Orchestration/Base.php | 12 ++++++++---- tests/Orchestration/Resources/php.tar.gz | Bin 326 -> 475 bytes tests/Orchestration/Resources/php/logs.sh | 15 +++++++-------- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/tests/Orchestration/Base.php b/tests/Orchestration/Base.php index a969d79..abeaecb 100644 --- a/tests/Orchestration/Base.php +++ b/tests/Orchestration/Base.php @@ -17,11 +17,15 @@ abstract protected static function getAdapterName(): string; */ public static $containerID; - public function setUp(): void { - \exec("rm -rf /usr/src/code/tests/Orchestration/Resources/screens"); // cleanup + public function setUp(): void + { + \exec('rm -rf /usr/src/code/tests/Orchestration/Resources/screens'); // cleanup } - public function tearDown(): void {} + public function tearDown(): void + { + \exec('rm -rf /usr/src/code/tests/Orchestration/Resources/screens'); // cleanup + } public function testPullImage(): void { @@ -343,7 +347,7 @@ public function testExecContainer(): void ); $length = 0; - $length += 917504; // 128kb * 7 + $length += 1024 * 1024 * 5; // 5MB $length += 5; // "start" $length += 3; // "end" diff --git a/tests/Orchestration/Resources/php.tar.gz b/tests/Orchestration/Resources/php.tar.gz index 0127e319737842f6afb07391bcb5734054653a20..ed71e865cb87f9bd4067371d7519a4b8d17ece15 100644 GIT binary patch literal 475 zcmV<10VMt(iwFP!000001MSyeOY1Nc0PsHNQylAHAg(rT(}`ZWOdWU;eVB565V508 z|3H_FCgWcH^fyIp=Y#BJwO2jAF?PCy=8&_b*)m@qSRHeXF=LiX%`05{Y*{o2Sr|~y zAG@ZVdepaob)8skrS!Z4u(CogW%7Q%P3@o5($v2Y3IFSusG~9J0*68He*KyMQh(pP zy|HQc-GEu(c9hQ>-@N`meww-y!sA@R@Pe16ggaT4$qo#i!Q=G$_x(_FrH2p4r0-Nw z2kP}-%1k*b?`(_>>z@YHf8GE6&<#zy$0)A<523h*5hvvAVlumVq~76)O?zg)CUbdu zVh@_cwi7is57+O0dHR1wc3YSAbi=mKR>EeOt2Z;=_St4^6S4~o_MjQ_<>@mLVBg$M zX18{GJ!txL{N?oe-0piR_M+bZXVb~~)zn#ZwYzOP|9LKJ&i^d%>is`3e*8e|GOFBGJ*On9{q)k@THDgP8AGrbmzxk#W8sz^9QGp^*S zin)p)DJmXoSv?&Q5=D{9Nj=G<=QsuD!2IMKbLnKyP@g?bd*73Q5JCtcgb+dqA%qY@ R2qE-^`~%824#WT`000~$+gE|vU9BgH@TcJ?sp)K2Cj54Ow zf>fyv_VE`ts`gNNX=ca%KM%h6Lh|78Fi-Mp%P>z1rL;V*AJuv{EFLJSd?iE0b)E~M zEGkVGR{1E(w=JdCYF*}8ba>yf{2!I;{;xMt{ORh*&>dBSRS+ERzx3<=D-r6v?*-DL zo}qg7{PX_b-Rr&+62B)Ib;fa;X7oARrqKm;Tzfg1KD{_)T$Il1E$O;cFrb?MG+PyJ zkr=z<$oz9(h~4}v;a7Pf1;_mVh9WL$FDB$+JebXwT-@{-?-<(^Ga2@oT^Dwms6Je^ zPoE6WGh$6&+U2Td&q+c?$R!Qw75%>F=V#E{P&Qu-W((G=?N&8s`FS*bWL-}b00000 Y000000000006;gs09tHDAOI);0DF;_Qvd(} diff --git a/tests/Orchestration/Resources/php/logs.sh b/tests/Orchestration/Resources/php/logs.sh index 1ade1aa..f8d0e2b 100644 --- a/tests/Orchestration/Resources/php/logs.sh +++ b/tests/Orchestration/Resources/php/logs.sh @@ -4,14 +4,13 @@ CHARS_128="111111111111111111111111111111111111111111111111111111111111111111111 CHARS_1KB="$CHARS_128$CHARS_128$CHARS_128$CHARS_128$CHARS_128$CHARS_128$CHARS_128$CHARS_128" CHARS_16KB="$CHARS_1KB$CHARS_1KB$CHARS_1KB$CHARS_1KB$CHARS_1KB$CHARS_1KB$CHARS_1KB$CHARS_1KB$CHARS_1KB$CHARS_1KB$CHARS_1KB$CHARS_1KB$CHARS_1KB$CHARS_1KB$CHARS_1KB$CHARS_1KB" CHARS_128KB="$CHARS_16KB$CHARS_16KB$CHARS_16KB$CHARS_16KB$CHARS_16KB$CHARS_16KB$CHARS_16KB$CHARS_16KB" +CHARS_1MB="$CHARS_128KB$CHARS_128KB$CHARS_128KB$CHARS_128KB$CHARS_128KB$CHARS_128KB$CHARS_128KB$CHARS_128KB" -# 7 * 128KB +# 5 * CHARS_1MB echo -n "START" -echo -n "$CHARS_128KB" -echo -n "$CHARS_128KB" -echo -n "$CHARS_128KB" -echo -n "$CHARS_128KB" -echo -n "$CHARS_128KB" -echo -n "$CHARS_128KB" -echo -n "$CHARS_128KB" +echo -n "$CHARS_1MB" +echo -n "$CHARS_1MB" +echo -n "$CHARS_1MB" +echo -n "$CHARS_1MB" +echo -n "$CHARS_1MB" echo -n "END" \ No newline at end of file From e25ca28e562309f68468c6700ac9c81f17ff3aef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Mon, 12 Aug 2024 15:22:28 +0000 Subject: [PATCH 10/23] Fix DockerAPI stream multiplexing --- src/Orchestration/Adapter/DockerAPI.php | 58 +++++++++++++++-------- tests/Orchestration/Resources/php.tar.gz | Bin 475 -> 478 bytes 2 files changed, 37 insertions(+), 21 deletions(-) diff --git a/src/Orchestration/Adapter/DockerAPI.php b/src/Orchestration/Adapter/DockerAPI.php index 2b6d785..056af31 100644 --- a/src/Orchestration/Adapter/DockerAPI.php +++ b/src/Orchestration/Adapter/DockerAPI.php @@ -130,34 +130,50 @@ protected function streamCall(string $url, int $timeout = -1): array $stdout = ''; $stderr = ''; - $callback = function (mixed $ch, string $str) use (&$stdout, &$stderr): int { + $isHeader = true; + $currentHeader = null; + $currentData = ''; + + $callback = function (mixed $ch, string $str) use (&$stdout, &$stderr, &$isHeader, &$currentHeader, &$currentData): int { if (empty($str)) { return 0; } - $rawStream = unpack('C*', $str); - $stream = $rawStream[1]; // 1-based index, not 0-based - - // Ascii encoding support - if ($stream === \ord('1')) { - $stream = 1; - } elseif ($stream === \ord('2')) { - $stream = 2; - } - - switch ($stream) { // only 1 or 2, as set while creating exec - case 1: - $packed = pack('C*', ...\array_slice($rawStream, 8)); - $stdout .= $packed; - break; - case 2: - $packed = pack('C*', ...\array_slice($rawStream, 8)); - $stderr .= $packed; - break; + $originalSize = \mb_strlen($str); + + while (! empty($str)) { + if ($isHeader) { + $header = \unpack('Ctype/Cfill1/Cfill2/Cfill3/Nsize', $str); + $str = \mb_strcut($str, 8, null); + $isHeader = false; + $currentHeader = $header; + } else { + $size = $currentHeader['size']; + $type = $currentHeader['type']; + + if (\strlen($str) >= $size) { + $currentData .= \mb_substr($str, 0, $size); + $str = \mb_strcut($str, $size, null); + $isHeader = true; + $currentHeader = null; + + if ($type === 1) { + $stdout .= $currentData; + } else { + $stderr .= $currentData; + } + $currentData = ''; + } else { + $currentHeader['size'] -= \mb_strlen($str); + $currentData .= $str; + $str = ''; + } + } } - return strlen($str); // must return full frame from callback + return $originalSize; // must return full frame from callback }; + \curl_setopt($ch, CURLOPT_WRITEFUNCTION, $callback); \curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); diff --git a/tests/Orchestration/Resources/php.tar.gz b/tests/Orchestration/Resources/php.tar.gz index ed71e865cb87f9bd4067371d7519a4b8d17ece15..ddaa2d400e7f583db7ae482873b2483e8f77b5a9 100644 GIT binary patch literal 478 zcmV<40U`b$iwFP!000001MSyaYuhjs0AN4sSDbl)z-U}cmYlJzjC2ijl=dMl+rt=j zu;mLlQm`C)`Sq38%}yUmUgCON&lf_DBViqMB3W7I>qDn!zBLuX@u_`Ujk3c$&VdaaY^`|WD~N3CuB3zf)Q&qh6s(G)o3{Q3He;IaOJ zeY2@;4}2~h@O#SViC13#PoHhw36XKGVSFmfQp0y$mB||zd!y_5#kU{hTAF(N^CKBL zRn&uK{g*m3p2>R~W5@cZoc><_oN=Eq+s=eP#r6LZjI3cI3Hfq5TU=gK_WsDF19Sf* zb9Q{>j@rcb6SX%Fx9@&-{C7rfSC{Q{!>-R>!giSRCo|sl*=Ot$@)iWVgLcfvr_V%z zdwDfmT)Ex#sO{79m-CAgcj%=!h-Uv^%x5R(b8pqx?zZdv$9&PA{{{cG|8x5{0QdhF z@HK@yy@5nSoG(=-4b(Q&DwV1RokE=#22x!nvO0ijqnfzXH-*Y1FrOoIP#((35}=LI@#*5JCtc Ugb+dqA@m=40K_Q0{{Sce0IW9mS^xk5 literal 475 zcmV<10VMt(iwFP!000001MSyeOY1Nc0PsHNQylAHAg(rT(}`ZWOdWU;eVB565V508 z|3H_FCgWcH^fyIp=Y#BJwO2jAF?PCy=8&_b*)m@qSRHeXF=LiX%`05{Y*{o2Sr|~y zAG@ZVdepaob)8skrS!Z4u(CogW%7Q%P3@o5($v2Y3IFSusG~9J0*68He*KyMQh(pP zy|HQc-GEu(c9hQ>-@N`meww-y!sA@R@Pe16ggaT4$qo#i!Q=G$_x(_FrH2p4r0-Nw z2kP}-%1k*b?`(_>>z@YHf8GE6&<#zy$0)A<523h*5hvvAVlumVq~76)O?zg)CUbdu zVh@_cwi7is57+O0dHR1wc3YSAbi=mKR>EeOt2Z;=_St4^6S4~o_MjQ_<>@mLVBg$M zX18{GJ!txL{N?oe-0piR_M+bZXVb~~)zn#ZwYzOP|9LKJ&i^d%>is`3e*8e|GOFBGJ*On9{q)k@THDgP8AGrbmzxk#W8sz^9QGp^*S zin)p)DJmXoSv?&Q5=D{9Nj=G<=QsuD!2IMKbLnKyP@g?bd*73Q5JCtcgb+dqA%qY@ R2qE-^`~%824#WT`000~ Date: Mon, 12 Aug 2024 15:29:36 +0000 Subject: [PATCH 11/23] Automate test build step --- tests/Orchestration/Base.php | 3 +++ tests/Orchestration/Resources/.gitignore | 1 + tests/Orchestration/Resources/php.tar.gz | Bin 478 -> 445 bytes tests/Orchestration/Resources/php/README.md | 5 ----- tests/Orchestration/Resources/timeout.tar.gz | Bin 321 -> 308 bytes tests/Orchestration/Resources/timeout/README.md | 5 ----- 6 files changed, 4 insertions(+), 10 deletions(-) create mode 100644 tests/Orchestration/Resources/.gitignore delete mode 100644 tests/Orchestration/Resources/php/README.md delete mode 100644 tests/Orchestration/Resources/timeout/README.md diff --git a/tests/Orchestration/Base.php b/tests/Orchestration/Base.php index abeaecb..2cac60a 100644 --- a/tests/Orchestration/Base.php +++ b/tests/Orchestration/Base.php @@ -20,6 +20,9 @@ abstract protected static function getAdapterName(): string; public function setUp(): void { \exec('rm -rf /usr/src/code/tests/Orchestration/Resources/screens'); // cleanup + + \exec('sh -c "cd /usr/src/code/tests/Orchestration/Resources && tar -zcf ./php.tar.gz php"'); + \exec('sh -c "cd /usr/src/code/tests/Orchestration/Resources && tar -zcf ./timeout.tar.gz timeout"'); } public function tearDown(): void diff --git a/tests/Orchestration/Resources/.gitignore b/tests/Orchestration/Resources/.gitignore new file mode 100644 index 0000000..8ae9393 --- /dev/null +++ b/tests/Orchestration/Resources/.gitignore @@ -0,0 +1 @@ +./*.tar.gz \ No newline at end of file diff --git a/tests/Orchestration/Resources/php.tar.gz b/tests/Orchestration/Resources/php.tar.gz index ddaa2d400e7f583db7ae482873b2483e8f77b5a9..ee3ce17d657c3396e2aba30275c9527d12eed403 100644 GIT binary patch literal 445 zcmV;u0Yd&CiwFP!000001MSw$YQjJe0N|YWDW<6)lp2#XSxZ|fwiPU*2bK0vijibv z0=g^NNPnKb8%h&xDPD{U&ga2N95Ta>gD#>)T`QTXG+b9RE%l-+?*+|rs7oE&X*6tg zpHh=*;FjH3W+~H20_d%Q#@* z4VV7|-7nO0w~$-Y}f zCCK)FCZ^JmQE4?c?7!t$fA-%}e+h8^cR;cfYK)NkPHQk6TlQsBxAsi`X{LME)GK*o z+llgr)77VU?+!E4i@B_}ON*SXgn60X+KCrA+l+NWPQisU$ZLN8`qVh+!%=H6(u?a# no>TJ8cK<=&_bMWU5JCtcgb+dqA%qY@2yMj|t525!04M+ek#yBq literal 478 zcmV<40U`b$iwFP!000001MSyaYuhjs0AN4sSDbl)z-U}cmYlJzjC2ijl=dMl+rt=j zu;mLlQm`C)`Sq38%}yUmUgCON&lf_DBViqMB3W7I>qDn!zBLuX@u_`Ujk3c$&VdaaY^`|WD~N3CuB3zf)Q&qh6s(G)o3{Q3He;IaOJ zeY2@;4}2~h@O#SViC13#PoHhw36XKGVSFmfQp0y$mB||zd!y_5#kU{hTAF(N^CKBL zRn&uK{g*m3p2>R~W5@cZoc><_oN=Eq+s=eP#r6LZjI3cI3Hfq5TU=gK_WsDF19Sf* zb9Q{>j@rcb6SX%Fx9@&-{C7rfSC{Q{!>-R>!giSRCo|sl*=Ot$@)iWVgLcfvr_V%z zdwDfmT)Ex#sO{79m-CAgcj%=!h-Uv^%x5R(b8pqx?zZdv$9&PA{{{cG|8x5{0QdhF z@HK@yy@5nSoG(=-4b(Q&DwV1RokE=#22x!nvO0ijqnfzXH-*Y1FrOoIP#((35}=LI@#*5JCtc Ugb+dqA@m=40K_Q0{{Sce0IW9mS^xk5 diff --git a/tests/Orchestration/Resources/php/README.md b/tests/Orchestration/Resources/php/README.md deleted file mode 100644 index 8f9b2f4..0000000 --- a/tests/Orchestration/Resources/php/README.md +++ /dev/null @@ -1,5 +0,0 @@ -If you do changes to confent of this folder, run following command inside `Resources` directory: - -```sh -tar -zcf ./php.tar.gz php -``` \ No newline at end of file diff --git a/tests/Orchestration/Resources/timeout.tar.gz b/tests/Orchestration/Resources/timeout.tar.gz index 5010c0cdd0aa5fec158e47999aca4170bc693d50..de562b27ea526b44fabd8413b2fde50cc5cf02ae 100644 GIT binary patch literal 308 zcmV-40n7d$iwFP!000001MSq!YJ@Np1z^`c#a*`0I%B5Ev0>J-^I|IPaG>17>se1RHMz-f~FntvRzulYw|mc|~13-t2Cndkpp z(N>SdHI+@FYGKH_rB;Q||1x2x+4#Yrk7xuAR_j2?$l zn4GvAL}~S~z4iS(&rRb`hkU&&D+*TgCl|O^LA|5-aoTt6!#G3x`Im}|x1ewO1#0{? z|LzCyZT_R1D8>9A!u^BG-1ki@M1R39@BCvo1ONa4000000000000000|Mm_rkQw*@ GC;$MTgOkGm literal 321 zcmV-H0lxkpiwFP!000001MSp7YlAQp2XN1Rig(;#vyB>sZ7>GwVTWD%2`naRpeAA> zTl?u3SxX0_^khrv|0iNJ4}9e1#i>@B!OemR&ApuSV9xxN{dpb)EX{b9vY4mie9TxD z5T7!sy}`OwPZZS3bw(VIJ2ii$+^+sg3;7*&O*g?m#sX()dc6KI`>lWC?>P7KNuJ~Z z%_qp^pBu0L%d4+>7}~Xz-5tMw4lkV$oYlVnmy5Ue&qdTuvBOXGf6Vyd{O8%&|4Gi# z|L5>g(Z&oU43*7F*V2;nL!&FH9hr(;qbyZsEoA>d{h-J3+I%Tp`>3{EX+cU`B_tI~ zY0c1=(iS9CFH2|o%~Kc_MPZw8T;#`XSy43GZMn#Qis~)xUdOmgF9rYr0000000000 T00000z?J#|TnH=P04M+e!TFnV diff --git a/tests/Orchestration/Resources/timeout/README.md b/tests/Orchestration/Resources/timeout/README.md deleted file mode 100644 index aa24845..0000000 --- a/tests/Orchestration/Resources/timeout/README.md +++ /dev/null @@ -1,5 +0,0 @@ -If you do changes to confent of this folder, run following command inside `Resources` directory: - -```sh -tar -zcf ./timeout.tar.gz timeout -``` \ No newline at end of file From ca9103f7cbe74b524cb7fb46ffda152d43c1a4cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Mon, 12 Aug 2024 15:30:00 +0000 Subject: [PATCH 12/23] Remove temp files --- tests/Orchestration/Resources/php.tar.gz | Bin 445 -> 0 bytes tests/Orchestration/Resources/timeout.tar.gz | Bin 308 -> 0 bytes 2 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 tests/Orchestration/Resources/php.tar.gz delete mode 100644 tests/Orchestration/Resources/timeout.tar.gz diff --git a/tests/Orchestration/Resources/php.tar.gz b/tests/Orchestration/Resources/php.tar.gz deleted file mode 100644 index ee3ce17d657c3396e2aba30275c9527d12eed403..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 445 zcmV;u0Yd&CiwFP!000001MSw$YQjJe0N|YWDW<6)lp2#XSxZ|fwiPU*2bK0vijibv z0=g^NNPnKb8%h&xDPD{U&ga2N95Ta>gD#>)T`QTXG+b9RE%l-+?*+|rs7oE&X*6tg zpHh=*;FjH3W+~H20_d%Q#@* z4VV7|-7nO0w~$-Y}f zCCK)FCZ^JmQE4?c?7!t$fA-%}e+h8^cR;cfYK)NkPHQk6TlQsBxAsi`X{LME)GK*o z+llgr)77VU?+!E4i@B_}ON*SXgn60X+KCrA+l+NWPQisU$ZLN8`qVh+!%=H6(u?a# no>TJ8cK<=&_bMWU5JCtcgb+dqA%qY@2yMj|t525!04M+ek#yBq diff --git a/tests/Orchestration/Resources/timeout.tar.gz b/tests/Orchestration/Resources/timeout.tar.gz deleted file mode 100644 index de562b27ea526b44fabd8413b2fde50cc5cf02ae..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 308 zcmV-40n7d$iwFP!000001MSq!YJ@Np1z^`c#a*`0I%B5Ev0>J-^I|IPaG>17>se1RHMz-f~FntvRzulYw|mc|~13-t2Cndkpp z(N>SdHI+@FYGKH_rB;Q||1x2x+4#Yrk7xuAR_j2?$l zn4GvAL}~S~z4iS(&rRb`hkU&&D+*TgCl|O^LA|5-aoTt6!#G3x`Im}|x1ewO1#0{? z|LzCyZT_R1D8>9A!u^BG-1ki@M1R39@BCvo1ONa4000000000000000|Mm_rkQw*@ GC;$MTgOkGm From f22d56bba373e4f625e98129a3ca61554f65e7c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Mon, 12 Aug 2024 15:31:01 +0000 Subject: [PATCH 13/23] Fix ignore file bug --- tests/Orchestration/Resources/.gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Orchestration/Resources/.gitignore b/tests/Orchestration/Resources/.gitignore index 8ae9393..c32b546 100644 --- a/tests/Orchestration/Resources/.gitignore +++ b/tests/Orchestration/Resources/.gitignore @@ -1 +1 @@ -./*.tar.gz \ No newline at end of file +*.tar.gz \ No newline at end of file From c01e0bbd665c9d419902975dc079891eecf454ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Mon, 12 Aug 2024 15:35:34 +0000 Subject: [PATCH 14/23] Leftover --- phpunit.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpunit.xml b/phpunit.xml index 10d408c..ec39a7e 100755 --- a/phpunit.xml +++ b/phpunit.xml @@ -6,7 +6,7 @@ convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" - stopOnFailure="true" + stopOnFailure="false" > From 49d1d17e53f18d5137a7aeb5c6878add6b36f9cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Tue, 13 Aug 2024 18:14:57 +0000 Subject: [PATCH 15/23] attempt to fix --- src/Orchestration/Adapter/DockerAPI.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Orchestration/Adapter/DockerAPI.php b/src/Orchestration/Adapter/DockerAPI.php index 056af31..18da71b 100644 --- a/src/Orchestration/Adapter/DockerAPI.php +++ b/src/Orchestration/Adapter/DockerAPI.php @@ -139,7 +139,7 @@ protected function streamCall(string $url, int $timeout = -1): array return 0; } - $originalSize = \mb_strlen($str); + $originalSize = \strlen($str); while (! empty($str)) { if ($isHeader) { @@ -164,7 +164,7 @@ protected function streamCall(string $url, int $timeout = -1): array } $currentData = ''; } else { - $currentHeader['size'] -= \mb_strlen($str); + $currentHeader['size'] -= \strlen($str); $currentData .= $str; $str = ''; } From 135aed64f292e83c1c7b5fd997d99582310ebbb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Tue, 13 Aug 2024 18:25:44 +0000 Subject: [PATCH 16/23] Fix attempt --- src/Orchestration/Adapter/DockerAPI.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Orchestration/Adapter/DockerAPI.php b/src/Orchestration/Adapter/DockerAPI.php index 18da71b..3504f3c 100644 --- a/src/Orchestration/Adapter/DockerAPI.php +++ b/src/Orchestration/Adapter/DockerAPI.php @@ -141,10 +141,10 @@ protected function streamCall(string $url, int $timeout = -1): array $originalSize = \strlen($str); - while (! empty($str)) { + while (\strlen($str) > 0) { if ($isHeader) { $header = \unpack('Ctype/Cfill1/Cfill2/Cfill3/Nsize', $str); - $str = \mb_strcut($str, 8, null); + $str = \substr($str, 8, null); $isHeader = false; $currentHeader = $header; } else { @@ -152,8 +152,8 @@ protected function streamCall(string $url, int $timeout = -1): array $type = $currentHeader['type']; if (\strlen($str) >= $size) { - $currentData .= \mb_substr($str, 0, $size); - $str = \mb_strcut($str, $size, null); + $currentData .= \substr($str, 0, $size); + $str = \substr($str, $size, null); $isHeader = true; $currentHeader = null; From a0447f6ebde0ff6c1ae4ea03f858e125e68f17c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Tue, 13 Aug 2024 18:42:51 +0000 Subject: [PATCH 17/23] Use MB again --- src/Orchestration/Adapter/DockerAPI.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Orchestration/Adapter/DockerAPI.php b/src/Orchestration/Adapter/DockerAPI.php index 3504f3c..9f1220a 100644 --- a/src/Orchestration/Adapter/DockerAPI.php +++ b/src/Orchestration/Adapter/DockerAPI.php @@ -139,21 +139,21 @@ protected function streamCall(string $url, int $timeout = -1): array return 0; } - $originalSize = \strlen($str); + $originalSize = \mb_strlen($str); - while (\strlen($str) > 0) { + while (\mb_strlen($str) > 0) { if ($isHeader) { $header = \unpack('Ctype/Cfill1/Cfill2/Cfill3/Nsize', $str); - $str = \substr($str, 8, null); + $str = \mb_strcut($str, 8, null); $isHeader = false; $currentHeader = $header; } else { $size = $currentHeader['size']; $type = $currentHeader['type']; - if (\strlen($str) >= $size) { - $currentData .= \substr($str, 0, $size); - $str = \substr($str, $size, null); + if (\mb_strlen($str) >= $size) { + $currentData .= \mb_strcut($str, 0, $size); + $str = \mb_strcut($str, $size, null); $isHeader = true; $currentHeader = null; @@ -164,7 +164,7 @@ protected function streamCall(string $url, int $timeout = -1): array } $currentData = ''; } else { - $currentHeader['size'] -= \strlen($str); + $currentHeader['size'] -= \mb_strlen($str); $currentData .= $str; $str = ''; } From 7146eac7b0d03d10ba23846caabb305883ae8164 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Tue, 13 Aug 2024 19:29:02 +0000 Subject: [PATCH 18/23] Remove multibyte --- src/Orchestration/Adapter/DockerAPI.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Orchestration/Adapter/DockerAPI.php b/src/Orchestration/Adapter/DockerAPI.php index 9f1220a..24be5b7 100644 --- a/src/Orchestration/Adapter/DockerAPI.php +++ b/src/Orchestration/Adapter/DockerAPI.php @@ -139,21 +139,21 @@ protected function streamCall(string $url, int $timeout = -1): array return 0; } - $originalSize = \mb_strlen($str); + $originalSize = \strlen($str); - while (\mb_strlen($str) > 0) { + while (\strlen($str) > 0) { if ($isHeader) { $header = \unpack('Ctype/Cfill1/Cfill2/Cfill3/Nsize', $str); - $str = \mb_strcut($str, 8, null); + $str = \substr($str, 8, null); $isHeader = false; $currentHeader = $header; } else { $size = $currentHeader['size']; $type = $currentHeader['type']; - if (\mb_strlen($str) >= $size) { - $currentData .= \mb_strcut($str, 0, $size); - $str = \mb_strcut($str, $size, null); + if (\strlen($str) >= $size) { + $currentData .= \substr($str, 0, $size); + $str = \strcut($str, $size, null); $isHeader = true; $currentHeader = null; @@ -164,7 +164,7 @@ protected function streamCall(string $url, int $timeout = -1): array } $currentData = ''; } else { - $currentHeader['size'] -= \mb_strlen($str); + $currentHeader['size'] -= \strlen($str); $currentData .= $str; $str = ''; } From 00e78059a639a0e1eddbdc0630944f823b9edc63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Tue, 13 Aug 2024 19:31:43 +0000 Subject: [PATCH 19/23] Fix bug --- src/Orchestration/Adapter/DockerAPI.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Orchestration/Adapter/DockerAPI.php b/src/Orchestration/Adapter/DockerAPI.php index 24be5b7..3504f3c 100644 --- a/src/Orchestration/Adapter/DockerAPI.php +++ b/src/Orchestration/Adapter/DockerAPI.php @@ -153,7 +153,7 @@ protected function streamCall(string $url, int $timeout = -1): array if (\strlen($str) >= $size) { $currentData .= \substr($str, 0, $size); - $str = \strcut($str, $size, null); + $str = \substr($str, $size, null); $isHeader = true; $currentHeader = null; From 1d0054500867bf3a605b6722c3ec99f6cfea5c71 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Wed, 28 Aug 2024 11:22:25 +0400 Subject: [PATCH 20/23] feat: add networkExists() method --- composer.lock | 44 ++++++++++++------------- src/Orchestration/Adapter.php | 5 +++ src/Orchestration/Adapter/DockerAPI.php | 10 ++++++ src/Orchestration/Adapter/DockerCLI.php | 12 +++++++ src/Orchestration/Orchestration.php | 8 +++++ tests/Orchestration/Base.php | 20 +++++++++++ 6 files changed, 77 insertions(+), 22 deletions(-) diff --git a/composer.lock b/composer.lock index 44535d1..e0890e8 100644 --- a/composer.lock +++ b/composer.lock @@ -480,16 +480,16 @@ }, { "name": "phpstan/phpstan", - "version": "1.11.10", + "version": "1.12.0", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "640410b32995914bde3eed26fa89552f9c2c082f" + "reference": "384af967d35b2162f69526c7276acadce534d0e1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/640410b32995914bde3eed26fa89552f9c2c082f", - "reference": "640410b32995914bde3eed26fa89552f9c2c082f", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/384af967d35b2162f69526c7276acadce534d0e1", + "reference": "384af967d35b2162f69526c7276acadce534d0e1", "shasum": "" }, "require": { @@ -534,39 +534,39 @@ "type": "github" } ], - "time": "2024-08-08T09:02:50+00:00" + "time": "2024-08-27T09:18:05+00:00" }, { "name": "phpunit/php-code-coverage", - "version": "9.2.31", + "version": "9.2.32", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "48c34b5d8d983006bd2adc2d0de92963b9155965" + "reference": "85402a822d1ecf1db1096959413d35e1c37cf1a5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/48c34b5d8d983006bd2adc2d0de92963b9155965", - "reference": "48c34b5d8d983006bd2adc2d0de92963b9155965", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/85402a822d1ecf1db1096959413d35e1c37cf1a5", + "reference": "85402a822d1ecf1db1096959413d35e1c37cf1a5", "shasum": "" }, "require": { "ext-dom": "*", "ext-libxml": "*", "ext-xmlwriter": "*", - "nikic/php-parser": "^4.18 || ^5.0", + "nikic/php-parser": "^4.19.1 || ^5.1.0", "php": ">=7.3", - "phpunit/php-file-iterator": "^3.0.3", - "phpunit/php-text-template": "^2.0.2", - "sebastian/code-unit-reverse-lookup": "^2.0.2", - "sebastian/complexity": "^2.0", - "sebastian/environment": "^5.1.2", - "sebastian/lines-of-code": "^1.0.3", - "sebastian/version": "^3.0.1", - "theseer/tokenizer": "^1.2.0" + "phpunit/php-file-iterator": "^3.0.6", + "phpunit/php-text-template": "^2.0.4", + "sebastian/code-unit-reverse-lookup": "^2.0.3", + "sebastian/complexity": "^2.0.3", + "sebastian/environment": "^5.1.5", + "sebastian/lines-of-code": "^1.0.4", + "sebastian/version": "^3.0.2", + "theseer/tokenizer": "^1.2.3" }, "require-dev": { - "phpunit/phpunit": "^9.3" + "phpunit/phpunit": "^9.6" }, "suggest": { "ext-pcov": "PHP extension that provides line coverage", @@ -575,7 +575,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "9.2-dev" + "dev-main": "9.2.x-dev" } }, "autoload": { @@ -604,7 +604,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", "security": "https://github.com/sebastianbergmann/php-code-coverage/security/policy", - "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.31" + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.32" }, "funding": [ { @@ -612,7 +612,7 @@ "type": "github" } ], - "time": "2024-03-02T06:37:42+00:00" + "time": "2024-08-22T04:23:01+00:00" }, { "name": "phpunit/php-file-iterator", diff --git a/src/Orchestration/Adapter.php b/src/Orchestration/Adapter.php index 0fefb74..9f62aba 100644 --- a/src/Orchestration/Adapter.php +++ b/src/Orchestration/Adapter.php @@ -60,6 +60,11 @@ abstract public function networkConnect(string $container, string $network): boo */ abstract public function networkDisconnect(string $container, string $network, bool $force = false): bool; + /** + * Check if a network exists + */ + abstract public function networkExists(string $name): bool; + /** * List Networks * diff --git a/src/Orchestration/Adapter/DockerAPI.php b/src/Orchestration/Adapter/DockerAPI.php index 3504f3c..44eb4e5 100644 --- a/src/Orchestration/Adapter/DockerAPI.php +++ b/src/Orchestration/Adapter/DockerAPI.php @@ -281,6 +281,16 @@ public function networkDisconnect(string $container, string $network, bool $forc return $result['code'] === 200; } + /** + * Check if a network exists + */ + public function networkExists(string $name): bool + { + $result = $this->call('http://localhost/networks/'.$name, 'GET'); + + return $result['code'] === 200; + } + /** * Get usage stats of containers * diff --git a/src/Orchestration/Adapter/DockerCLI.php b/src/Orchestration/Adapter/DockerCLI.php index f4e9019..e23f0b3 100644 --- a/src/Orchestration/Adapter/DockerCLI.php +++ b/src/Orchestration/Adapter/DockerCLI.php @@ -76,6 +76,18 @@ public function networkDisconnect(string $container, string $network, bool $forc return $result === 0; } + /** + * Check if a network exists + */ + public function networkExists(string $name): bool + { + $output = ''; + + $result = Console::execute('docker network inspect '.$name.' --format "{{.Name}}"', '', $output); + + return $result === 0 && trim($output) === $name; + } + /** * Get usage stats of containers * diff --git a/src/Orchestration/Orchestration.php b/src/Orchestration/Orchestration.php index 5ae5922..6e366b7 100644 --- a/src/Orchestration/Orchestration.php +++ b/src/Orchestration/Orchestration.php @@ -125,6 +125,14 @@ public function networkDisconnect(string $container, string $network, bool $forc return $this->adapter->networkDisconnect($container, $network, $force); } + /** + * Check if a network exists + */ + public function networkExists(string $name): bool + { + return $this->adapter->networkExists($name); + } + /** * Pull Image */ diff --git a/tests/Orchestration/Base.php b/tests/Orchestration/Base.php index 2cac60a..34f53ae 100644 --- a/tests/Orchestration/Base.php +++ b/tests/Orchestration/Base.php @@ -716,4 +716,24 @@ public function testUsageStats(): void $stats = static::getOrchestration()->getStats('IDontExist'); } + + public function testNetworkExists(): void + { + $networkName = 'test_network_' . uniqid(); + + // Test non-existent network + $this->assertFalse(static::getOrchestration()->networkExists($networkName)); + + // Create network and test it exists + $response = static::getOrchestration()->createNetwork($networkName); + $this->assertTrue($response); + $this->assertTrue(static::getOrchestration()->networkExists($networkName)); + + // Remove network + $response = static::getOrchestration()->removeNetwork($networkName); + $this->assertTrue($response); + + // Test removed network + $this->assertFalse(static::getOrchestration()->networkExists($networkName)); + } } From 207313a47636b05d294b48f66ae0043c15790465 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Wed, 28 Aug 2024 11:53:28 +0400 Subject: [PATCH 21/23] feat: refactor existing method names --- README.md | 4 ++-- src/Orchestration/Adapter.php | 4 ++-- src/Orchestration/Adapter/DockerAPI.php | 4 ++-- src/Orchestration/Adapter/DockerCLI.php | 4 ++-- src/Orchestration/Orchestration.php | 8 ++++---- tests/Orchestration/Base.php | 16 ++++++++-------- 6 files changed, 20 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index fca9c5e..ce415a2 100644 --- a/README.md +++ b/README.md @@ -281,7 +281,7 @@ Once you have initialised your Orchestration object the following methods can be This method creates a new network and returns a boolean value indicating if the network was created successfully. ```php - $orchestration->createNetwork('name', false); + $orchestration->networkCreate('name', false); ```
@@ -305,7 +305,7 @@ Once you have initialised your Orchestration object the following methods can be This method removes a network and returns a boolean value indicating if the network was removed successfully. ```php - $orchestration->removeNetwork('network_id'); + $orchestration->networkRemove('network_id'); ```
diff --git a/src/Orchestration/Adapter.php b/src/Orchestration/Adapter.php index 9f62aba..e70e16f 100644 --- a/src/Orchestration/Adapter.php +++ b/src/Orchestration/Adapter.php @@ -43,12 +43,12 @@ public function filterEnvKey(string $string): string /** * Create Network */ - abstract public function createNetwork(string $name, bool $internal = false): bool; + abstract public function networkCreate(string $name, bool $internal = false): bool; /** * Remove Network */ - abstract public function removeNetwork(string $name): bool; + abstract public function networkRemove(string $name): bool; /** * Connect a container to a network diff --git a/src/Orchestration/Adapter/DockerAPI.php b/src/Orchestration/Adapter/DockerAPI.php index 44eb4e5..6c2aff0 100644 --- a/src/Orchestration/Adapter/DockerAPI.php +++ b/src/Orchestration/Adapter/DockerAPI.php @@ -201,7 +201,7 @@ protected function streamCall(string $url, int $timeout = -1): array /** * Create Network */ - public function createNetwork(string $name, bool $internal = false): bool + public function networkCreate(string $name, bool $internal = false): bool { $body = \json_encode([ 'Name' => $name, @@ -225,7 +225,7 @@ public function createNetwork(string $name, bool $internal = false): bool /** * Remove Network */ - public function removeNetwork(string $name): bool + public function networkRemove(string $name): bool { $result = $this->call('http://localhost/networks/'.$name, 'DELETE'); diff --git a/src/Orchestration/Adapter/DockerCLI.php b/src/Orchestration/Adapter/DockerCLI.php index e23f0b3..dd68550 100644 --- a/src/Orchestration/Adapter/DockerCLI.php +++ b/src/Orchestration/Adapter/DockerCLI.php @@ -31,7 +31,7 @@ public function __construct(?string $username = null, ?string $password = null) /** * Create Network */ - public function createNetwork(string $name, bool $internal = false): bool + public function networkCreate(string $name, bool $internal = false): bool { $output = ''; @@ -43,7 +43,7 @@ public function createNetwork(string $name, bool $internal = false): bool /** * Remove Network */ - public function removeNetwork(string $name): bool + public function networkRemove(string $name): bool { $output = ''; diff --git a/src/Orchestration/Orchestration.php b/src/Orchestration/Orchestration.php index 6e366b7..d0f52da 100644 --- a/src/Orchestration/Orchestration.php +++ b/src/Orchestration/Orchestration.php @@ -75,17 +75,17 @@ public function parseCommandString(string $command): array /** * Create Network */ - public function createNetwork(string $name, bool $internal = false): bool + public function networkCreate(string $name, bool $internal = false): bool { - return $this->adapter->createNetwork($name, $internal); + return $this->adapter->networkCreate($name, $internal); } /** * Remove Network */ - public function removeNetwork(string $name): bool + public function networkRemove(string $name): bool { - return $this->adapter->removeNetwork($name); + return $this->adapter->networkRemove($name); } /** diff --git a/tests/Orchestration/Base.php b/tests/Orchestration/Base.php index 34f53ae..ac857c3 100644 --- a/tests/Orchestration/Base.php +++ b/tests/Orchestration/Base.php @@ -185,15 +185,15 @@ public function testCreateContainer(): void /** * @depends testCreateContainer */ - public function testCreateNetwork(): void + public function testNetworkCreate(): void { - $response = static::getOrchestration()->createNetwork('TestNetwork'); + $response = static::getOrchestration()->networkCreate('TestNetwork'); $this->assertEquals(true, $response); } /** - * @depends testCreateNetwork + * @depends testNetworkCreate */ public function testListNetworks(): void { @@ -211,7 +211,7 @@ public function testListNetworks(): void } /** - * @depends testCreateNetwork + * @depends testNetworkCreate */ public function testNetworkConnect(): void { @@ -260,9 +260,9 @@ public function testNetworkDisconnect(): void /** * @depends testNetworkDisconnect */ - public function testRemoveNetwork(): void + public function testNetworkRemove(): void { - $response = static::getOrchestration()->removeNetwork('TestNetwork'); + $response = static::getOrchestration()->networkRemove('TestNetwork'); $this->assertEquals(true, $response); } @@ -725,12 +725,12 @@ public function testNetworkExists(): void $this->assertFalse(static::getOrchestration()->networkExists($networkName)); // Create network and test it exists - $response = static::getOrchestration()->createNetwork($networkName); + $response = static::getOrchestration()->networkCreate($networkName); $this->assertTrue($response); $this->assertTrue(static::getOrchestration()->networkExists($networkName)); // Remove network - $response = static::getOrchestration()->removeNetwork($networkName); + $response = static::getOrchestration()->networkRemove($networkName); $this->assertTrue($response); // Test removed network From 6fd9d4a3077f67a8c06e5c89b9654741c1515b6f Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Wed, 28 Aug 2024 12:02:51 +0400 Subject: [PATCH 22/23] chore: linter --- tests/Orchestration/Base.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Orchestration/Base.php b/tests/Orchestration/Base.php index ac857c3..c2d53b4 100644 --- a/tests/Orchestration/Base.php +++ b/tests/Orchestration/Base.php @@ -719,7 +719,7 @@ public function testUsageStats(): void public function testNetworkExists(): void { - $networkName = 'test_network_' . uniqid(); + $networkName = 'test_network_'.uniqid(); // Test non-existent network $this->assertFalse(static::getOrchestration()->networkExists($networkName)); From be8eeee8a9d5544e284ebb217fbf144d71451eff Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Wed, 28 Aug 2024 13:35:22 +0400 Subject: [PATCH 23/23] chore: revert renaming methods --- README.md | 4 ++-- src/Orchestration/Adapter.php | 4 ++-- src/Orchestration/Adapter/DockerAPI.php | 4 ++-- src/Orchestration/Adapter/DockerCLI.php | 4 ++-- src/Orchestration/Orchestration.php | 8 ++++---- tests/Orchestration/Base.php | 16 ++++++++-------- 6 files changed, 20 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index ce415a2..fca9c5e 100644 --- a/README.md +++ b/README.md @@ -281,7 +281,7 @@ Once you have initialised your Orchestration object the following methods can be This method creates a new network and returns a boolean value indicating if the network was created successfully. ```php - $orchestration->networkCreate('name', false); + $orchestration->createNetwork('name', false); ```
@@ -305,7 +305,7 @@ Once you have initialised your Orchestration object the following methods can be This method removes a network and returns a boolean value indicating if the network was removed successfully. ```php - $orchestration->networkRemove('network_id'); + $orchestration->removeNetwork('network_id'); ```
diff --git a/src/Orchestration/Adapter.php b/src/Orchestration/Adapter.php index e70e16f..9f62aba 100644 --- a/src/Orchestration/Adapter.php +++ b/src/Orchestration/Adapter.php @@ -43,12 +43,12 @@ public function filterEnvKey(string $string): string /** * Create Network */ - abstract public function networkCreate(string $name, bool $internal = false): bool; + abstract public function createNetwork(string $name, bool $internal = false): bool; /** * Remove Network */ - abstract public function networkRemove(string $name): bool; + abstract public function removeNetwork(string $name): bool; /** * Connect a container to a network diff --git a/src/Orchestration/Adapter/DockerAPI.php b/src/Orchestration/Adapter/DockerAPI.php index 6c2aff0..44eb4e5 100644 --- a/src/Orchestration/Adapter/DockerAPI.php +++ b/src/Orchestration/Adapter/DockerAPI.php @@ -201,7 +201,7 @@ protected function streamCall(string $url, int $timeout = -1): array /** * Create Network */ - public function networkCreate(string $name, bool $internal = false): bool + public function createNetwork(string $name, bool $internal = false): bool { $body = \json_encode([ 'Name' => $name, @@ -225,7 +225,7 @@ public function networkCreate(string $name, bool $internal = false): bool /** * Remove Network */ - public function networkRemove(string $name): bool + public function removeNetwork(string $name): bool { $result = $this->call('http://localhost/networks/'.$name, 'DELETE'); diff --git a/src/Orchestration/Adapter/DockerCLI.php b/src/Orchestration/Adapter/DockerCLI.php index dd68550..e23f0b3 100644 --- a/src/Orchestration/Adapter/DockerCLI.php +++ b/src/Orchestration/Adapter/DockerCLI.php @@ -31,7 +31,7 @@ public function __construct(?string $username = null, ?string $password = null) /** * Create Network */ - public function networkCreate(string $name, bool $internal = false): bool + public function createNetwork(string $name, bool $internal = false): bool { $output = ''; @@ -43,7 +43,7 @@ public function networkCreate(string $name, bool $internal = false): bool /** * Remove Network */ - public function networkRemove(string $name): bool + public function removeNetwork(string $name): bool { $output = ''; diff --git a/src/Orchestration/Orchestration.php b/src/Orchestration/Orchestration.php index d0f52da..6e366b7 100644 --- a/src/Orchestration/Orchestration.php +++ b/src/Orchestration/Orchestration.php @@ -75,17 +75,17 @@ public function parseCommandString(string $command): array /** * Create Network */ - public function networkCreate(string $name, bool $internal = false): bool + public function createNetwork(string $name, bool $internal = false): bool { - return $this->adapter->networkCreate($name, $internal); + return $this->adapter->createNetwork($name, $internal); } /** * Remove Network */ - public function networkRemove(string $name): bool + public function removeNetwork(string $name): bool { - return $this->adapter->networkRemove($name); + return $this->adapter->removeNetwork($name); } /** diff --git a/tests/Orchestration/Base.php b/tests/Orchestration/Base.php index c2d53b4..5cf7082 100644 --- a/tests/Orchestration/Base.php +++ b/tests/Orchestration/Base.php @@ -185,15 +185,15 @@ public function testCreateContainer(): void /** * @depends testCreateContainer */ - public function testNetworkCreate(): void + public function testCreateNetwork(): void { - $response = static::getOrchestration()->networkCreate('TestNetwork'); + $response = static::getOrchestration()->createNetwork('TestNetwork'); $this->assertEquals(true, $response); } /** - * @depends testNetworkCreate + * @depends testCreateNetwork */ public function testListNetworks(): void { @@ -211,7 +211,7 @@ public function testListNetworks(): void } /** - * @depends testNetworkCreate + * @depends testCreateNetwork */ public function testNetworkConnect(): void { @@ -260,9 +260,9 @@ public function testNetworkDisconnect(): void /** * @depends testNetworkDisconnect */ - public function testNetworkRemove(): void + public function testRemoveNetwork(): void { - $response = static::getOrchestration()->networkRemove('TestNetwork'); + $response = static::getOrchestration()->removeNetwork('TestNetwork'); $this->assertEquals(true, $response); } @@ -725,12 +725,12 @@ public function testNetworkExists(): void $this->assertFalse(static::getOrchestration()->networkExists($networkName)); // Create network and test it exists - $response = static::getOrchestration()->networkCreate($networkName); + $response = static::getOrchestration()->createNetwork($networkName); $this->assertTrue($response); $this->assertTrue(static::getOrchestration()->networkExists($networkName)); // Remove network - $response = static::getOrchestration()->networkRemove($networkName); + $response = static::getOrchestration()->removeNetwork($networkName); $this->assertTrue($response); // Test removed network