Skip to content

Commit 049c8d9

Browse files
committed
MCLOUD-6235: Cover new functionality with functional tests
1 parent f784060 commit 049c8d9

File tree

3 files changed

+113
-0
lines changed

3 files changed

+113
-0
lines changed
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\MagentoCloud\Test\Functional\Acceptance;
9+
10+
use Magento\MagentoCloud\App\Error;
11+
12+
/**
13+
* This test cover functionality of state-aware error codes.
14+
* Checks that failed scenario returns correct error code different to 1 or 255.
15+
* Checks that var/log/cloud.error.log file was created and contains correct data.
16+
* Checks that `ece-tools error:show` command returns correct errors info
17+
*/
18+
class ErrorCodesCest extends AbstractCest
19+
{
20+
/**
21+
* @param \CliTester $I
22+
* @throws \Robo\Exception\TaskException
23+
*/
24+
public function testDeployFailed(\CliTester $I): void
25+
{
26+
$I->runEceDockerCommand('build:compose --mode=production');
27+
$I->copyFileToWorkDir('files/error_codes/.magento.env.fail.yaml', '.magento.env.yaml');
28+
29+
$I->runDockerComposeCommand('run build cloud-build');
30+
$I->startEnvironment();
31+
$I->assertFalse($I->runDockerComposeCommand('run deploy cloud-deploy'));
32+
$I->seeInOutput(sprintf(
33+
'[%d] Variable DATABASE_CONFIGURATION is not configured properly',
34+
Error::DEPLOY_WRONG_CONFIGURATION_DB
35+
));
36+
$I->seeInOutput('returned non-zero exit status ' . Error::DEPLOY_WRONG_CONFIGURATION_DB);
37+
38+
$errorLog = $I->grabFileContent('/var/log/cloud.error.log');
39+
40+
$errors = $this->getErrors($errorLog);
41+
42+
$I->assertArrayHasKey(Error::WARN_MISSED_MODULE_SECTION, $errors);
43+
$I->assertArrayHasKey(Error::WARN_SCD_OPTIONS_IGNORANCE, $errors);
44+
$I->assertArrayHasKey(Error::WARN_CONFIGURATION_STATE_NOT_IDEAL, $errors);
45+
$I->assertArrayHasKey(Error::WARN_DEPRECATED_MYSQL_SEARCH_ENGINE, $errors);
46+
$I->assertArrayHasKey(Error::DEPLOY_WRONG_CONFIGURATION_DB, $errors);
47+
48+
$I->runDockerComposeCommand('run deploy ece-command error:show');
49+
$I->seeInOutput('errorCode: ' . Error::WARN_MISSED_MODULE_SECTION);
50+
$I->seeInOutput('errorCode: ' . Error::WARN_SCD_OPTIONS_IGNORANCE);
51+
$I->seeInOutput('errorCode: ' . Error::WARN_CONFIGURATION_STATE_NOT_IDEAL);
52+
$I->seeInOutput('errorCode: ' . Error::WARN_DEPRECATED_MYSQL_SEARCH_ENGINE);
53+
$I->seeInOutput('errorCode: ' . Error::DEPLOY_WRONG_CONFIGURATION_DB);
54+
$I->seeInOutput('type: critical');
55+
}
56+
57+
/**
58+
* @param \CliTester $I
59+
* @throws \Robo\Exception\TaskException
60+
*/
61+
public function testDeploySuccess(\CliTester $I): void
62+
{
63+
$I->runEceDockerCommand('build:compose --mode=production');
64+
$I->copyFileToWorkDir('files/error_codes/.magento.env.success.yaml', '.magento.env.yaml');
65+
66+
$I->runDockerComposeCommand('run build cloud-build');
67+
$I->startEnvironment();
68+
$I->assertTrue($I->runDockerComposeCommand('run deploy cloud-deploy'));
69+
$I->assertTrue($I->runDockerComposeCommand('run deploy cloud-post-deploy'));
70+
$I->doNotSeeInOutput('returned non-zero exit status');
71+
72+
$errorLog = $I->grabFileContent('/var/log/cloud.error.log');
73+
74+
$errors = $this->getErrors($errorLog);
75+
76+
$I->assertArrayHasKey(Error::WARN_MISSED_MODULE_SECTION, $errors);
77+
$I->assertArrayHasKey(Error::WARN_SCD_OPTIONS_IGNORANCE, $errors);
78+
$I->assertArrayHasKey(Error::WARN_CONFIGURATION_STATE_NOT_IDEAL, $errors);
79+
80+
$I->runDockerComposeCommand('run deploy ece-command error:show');
81+
$I->seeInOutput('errorCode: ' . Error::WARN_MISSED_MODULE_SECTION);
82+
$I->seeInOutput('errorCode: ' . Error::WARN_SCD_OPTIONS_IGNORANCE);
83+
$I->seeInOutput('errorCode: ' . Error::WARN_CONFIGURATION_STATE_NOT_IDEAL);
84+
$I->doNotSeeInOutput('type: critical');
85+
}
86+
87+
/**
88+
* @param string $errorLog
89+
* @return array
90+
*/
91+
private function getErrors(string $errorLog): array
92+
{
93+
$errors = [];
94+
95+
foreach (explode("\n", $errorLog) as $errorLine) {
96+
$error = json_decode(trim($errorLine), true);
97+
$errors[$error['errorCode']] = $error;
98+
}
99+
100+
return $errors;
101+
}
102+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
stage:
2+
build:
3+
SCD_THREADS: 3
4+
global:
5+
SCD_ON_DEMAND: true
6+
deploy:
7+
DATABASE_CONFIGURATION:
8+
host:
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
stage:
2+
global:
3+
SCD_ON_DEMAND: true

0 commit comments

Comments
 (0)