Skip to content

Commit 077d045

Browse files
author
Yevhen Miroshnychenko
authored
Merge pull request magento#757 from magento/MCLOUD-6235
MCLOUD-6235: Cover new functionality with functional tests
2 parents 4e3547d + 823972b commit 077d045

File tree

3 files changed

+109
-0
lines changed

3 files changed

+109
-0
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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_CONFIGURATION_STATE_NOT_IDEAL, $errors);
44+
$I->assertArrayHasKey(Error::WARN_DEPRECATED_MYSQL_SEARCH_ENGINE, $errors);
45+
$I->assertArrayHasKey(Error::DEPLOY_WRONG_CONFIGURATION_DB, $errors);
46+
47+
$I->runDockerComposeCommand('run deploy ece-command error:show');
48+
$I->seeInOutput('errorCode: ' . Error::WARN_MISSED_MODULE_SECTION);
49+
$I->seeInOutput('errorCode: ' . Error::WARN_CONFIGURATION_STATE_NOT_IDEAL);
50+
$I->seeInOutput('errorCode: ' . Error::WARN_DEPRECATED_MYSQL_SEARCH_ENGINE);
51+
$I->seeInOutput('errorCode: ' . Error::DEPLOY_WRONG_CONFIGURATION_DB);
52+
$I->seeInOutput('type: critical');
53+
}
54+
55+
/**
56+
* @param \CliTester $I
57+
* @throws \Robo\Exception\TaskException
58+
*/
59+
public function testDeploySuccess(\CliTester $I): void
60+
{
61+
$I->runEceDockerCommand('build:compose --mode=production');
62+
$I->copyFileToWorkDir('files/error_codes/.magento.env.success.yaml', '.magento.env.yaml');
63+
64+
$I->runDockerComposeCommand('run build cloud-build');
65+
$I->startEnvironment();
66+
$I->assertTrue($I->runDockerComposeCommand('run deploy cloud-deploy'));
67+
$I->assertTrue($I->runDockerComposeCommand('run deploy cloud-post-deploy'));
68+
$I->doNotSeeInOutput('returned non-zero exit status');
69+
70+
$errorLog = $I->grabFileContent('/var/log/cloud.error.log');
71+
72+
$errors = $this->getErrors($errorLog);
73+
74+
$I->assertArrayHasKey(Error::WARN_MISSED_MODULE_SECTION, $errors);
75+
$I->assertArrayHasKey(Error::WARN_CONFIGURATION_STATE_NOT_IDEAL, $errors);
76+
77+
$I->runDockerComposeCommand('run deploy ece-command error:show');
78+
$I->seeInOutput('errorCode: ' . Error::WARN_MISSED_MODULE_SECTION);
79+
$I->seeInOutput('errorCode: ' . Error::WARN_CONFIGURATION_STATE_NOT_IDEAL);
80+
$I->doNotSeeInOutput('type: critical');
81+
}
82+
83+
/**
84+
* @param string $errorLog
85+
* @return array
86+
*/
87+
private function getErrors(string $errorLog): array
88+
{
89+
$errors = [];
90+
91+
foreach (explode("\n", $errorLog) as $errorLine) {
92+
$error = json_decode(trim($errorLine), true);
93+
$errors[$error['errorCode']] = $error;
94+
}
95+
96+
return $errors;
97+
}
98+
}
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)