Skip to content
Snippets Groups Projects
Commit a1d5c884 authored by xiaohua guan's avatar xiaohua guan Committed by Yas Naoi
Browse files

Issue #3202931 by Xiaohua Guan, yas: Add test cases for K8s Schedule (Deployment)

parent e589ad9e
No related branches found
No related tags found
No related merge requests found
......@@ -43,6 +43,13 @@ class K8sScheduleTest extends K8sTestBase {
'edit any k8s pod',
'delete any k8s pod',
// Deployment.
'list k8s deployment',
'add k8s deployment',
'view any k8s deployment',
'edit any k8s deployment',
'delete any k8s deployment',
// Launch template.
'add cloud server templates',
'list cloud server template',
......@@ -58,12 +65,33 @@ class K8sScheduleTest extends K8sTestBase {
}
/**
* Tests CRUD for Schedule of Pod.
* Tests CRUD for Schedule of pod.
*
* @throws \Behat\Mink\Exception\ExpectationException
*/
public function testScheduleForPod(): void {
$this->runTestForObject('pod');
}
/**
* Tests CRUD for Schedule of deployment.
*
* @throws \Behat\Mink\Exception\ExpectationException
*/
public function testScheduleForDeployment(): void {
$this->runTestForObject('deployment');
}
/**
* Runs tests for object.
*
* @param string $object_type
* The object type.
*
* @throws \Behat\Mink\Exception\ExpectationException
*/
private function runTestForObject($object_type): void {
$object_type_capital = ucfirst($object_type);
$cloud_context = $this->cloudContext;
// List Schedule for K8s.
......@@ -71,19 +99,21 @@ class K8sScheduleTest extends K8sTestBase {
$this->assertNoErrorMessage();
// Add a new Schedule.
$add = $this->createPodTestFormData(self::K8S_SCHEDULE_REPEAT_COUNT, $this->namespace);
$method_name = "create${object_type_capital}TestFormData";
$add = $this->$method_name(self::K8S_SCHEDULE_REPEAT_COUNT, $this->namespace);
for ($i = 0; $i < self::K8S_SCHEDULE_REPEAT_COUNT; $i++) {
$this->reloadMockData();
$this->addPodMockData($add[$i]);
$method_name = "add${object_type_capital}MockData";
$this->$method_name($add[$i]);
$this->drupalGet("/clouds/k8s/$cloud_context/pod/add");
$this->drupalGet("/clouds/k8s/$cloud_context/$object_type/add");
$this->submitForm(
array_merge($add[$i]['post_data'], ['enable_time_scheduler' => TRUE]),
$this->t('Save')
);
$this->assertNoErrorMessage();
$t_args = ['@type' => 'Pod', '%label' => $add[$i]['name']];
$t_args = ['@type' => $object_type_capital, '%label' => $add[$i]['name']];
$this->assertSession()->pageTextContains(strip_tags($this->t('The @type %label has been created.', $t_args)));
// Make sure listing.
......@@ -142,17 +172,39 @@ class K8sScheduleTest extends K8sTestBase {
}
/**
* Tests CRUD for Schedule of template.
* Tests CRUD for Schedule of pod template.
*
* @throws \Behat\Mink\Exception\ExpectationException
*/
public function testScheduleForPodTemplate(): void {
$this->runTestForTemplate('pod');
}
/**
* Tests CRUD for Schedule of deployment template.
*
* @throws \Behat\Mink\Exception\ExpectationException
*/
public function testScheduleForTemplate(): void {
public function testScheduleForDeploymentTemplate(): void {
$this->runTestForTemplate('deployment');
}
/**
* Runs tests for template.
*
* @param string $object_type
* The object type.
*
* @throws \Behat\Mink\Exception\ExpectationException
*/
private function runTestForTemplate($object_type): void {
$cloud_context = $this->cloudContext;
$data = $this->createPodTestFormData(self::K8S_SCHEDULE_REPEAT_COUNT, $this->namespace);
$object = 'pod';
$add = $this->createServerTemplateTestFormData($data, 'yml', $object, [], self::K8S_SCHEDULE_REPEAT_COUNT);
$object_type_capital = ucfirst($object_type);
$method_name = "create${object_type_capital}TestFormData";
$data = $this->$method_name(self::K8S_SCHEDULE_REPEAT_COUNT, $this->namespace);
$add = $this->createServerTemplateTestFormData($data, 'yml', $object_type, [], self::K8S_SCHEDULE_REPEAT_COUNT);
for ($i = 0; $i < self::K8S_SCHEDULE_REPEAT_COUNT; $i++) {
// field_object is automatically calculated.
......@@ -175,8 +227,12 @@ class K8sScheduleTest extends K8sTestBase {
$this->drupalGet("/clouds/design/server_template/$cloud_context");
// Update the mock data.
$this->getMetricsPodMockData([]);
$this->addPodMockData($data[$i]);
if ($object_type === 'pod') {
$this->getMetricsPodMockData([]);
}
$method_name = "add${object_type_capital}MockData";
$this->$method_name($data[$i]);
// Navigate to the launch template, and launch it.
$this->clickLink('Launch');
......@@ -188,7 +244,7 @@ class K8sScheduleTest extends K8sTestBase {
$this->assertNoErrorMessage();
$t_args = [
'@type' => ucfirst($object),
'@type' => ucfirst($object_type),
'%label' => $add[$i]['name[0][value]'],
];
$this->assertSession()->pageTextContains(strip_tags($this->t('The @type %label has been launched.', $t_args)));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment