Skip to content
Snippets Groups Projects
Commit 758ebc96 authored by Takumaru Sekine's avatar Takumaru Sekine Committed by Yas Naoi
Browse files

Issue #3214270 by sekinet, yas: Add a test case for specify a different user...

Issue #3214270 by sekinet, yas: Add a test case for specify a different user when launching a K8s Project
parent 79eddd2d
No related branches found
No related tags found
No related merge requests found
......@@ -241,6 +241,21 @@ class K8sCloudProjectPlugin extends CloudPluginBase implements CloudProjectPlugi
$this->k8sService->updateNamespaces();
$this->k8sService->updateResourceQuotas();
$this->k8sService->updateResourceWithEntity('k8s_namespace', $cloud_context, $project_name, $params);
// Update Owner uid.
$entities = $this->entityTypeManager->getStorage('k8s_namespace')->loadByProperties(
[
'cloud_context' => $cloud_project->getCloudContext(),
'name' => $project_name,
]
);
if (!empty($entities)) {
$entity = reset($entities);
// Update owner uid.
$entity->setOwnerId($launch_uid);
$entity->save();
}
if (!empty($enable_resource_scheduler)) {
$this->k8sService->updateResourceWithEntity('k8s_resource_quota', $cloud_context, $project_name, $params_resource_quota);
}
......
......@@ -13,6 +13,20 @@ class CloudProjectTest extends K8sTestBase {
public const CLOUD_PROJECTS_REPEAT_COUNT = 3;
/**
* The generic login user.
*
* @var \Drupal\user\Entity\User
*/
protected $webUser;
/**
* The generic login user who will launch the template.
*
* @var \Drupal\user\Entity\User
*/
protected $webLaunchUser;
/**
* {@inheritdoc}
*
......@@ -42,6 +56,21 @@ class CloudProjectTest extends K8sTestBase {
];
}
/**
* Set up test.
*
* @throws \Drupal\Core\Entity\EntityStorageException
*/
protected function setUp(): void {
parent::setUp();
$this->webUser = $this->createLoginUser();
$this->webLaunchUser = $this->createLoginUser();
$this->drupalLogin($this->webUser);
}
/**
* CRUD test for k8s project test.
*
......@@ -307,8 +336,9 @@ class CloudProjectTest extends K8sTestBase {
$this->clickLink($namespace_edit['name']);
$this->clickLink('Launch');
$this->drupalGet($this->getUrl());
$launch_data['launch_user'] = $this->webLaunchUser->getAccountName();
$this->submitForm(
[],
$launch_data,
$this->t('Launch'));
$this->assertNoErrorMessage();
......@@ -363,6 +393,12 @@ class CloudProjectTest extends K8sTestBase {
$this->assertSession()->pageTextContains(strip_tags($this->t('The @type @label on @cloud_context has been @passive_operation.', $t_args)));
}
$this->drupalGet("/clouds/k8s/$cloud_context/namespace");
$this->clickLink($namespace_edit['name']);
$this->assertSession()->pageTextContains($this->webLaunchUser->getAccountName());
$this->assertSession()->pageTextNotContains($this->webUser->getAccountName());
// Delete test.
if (!empty($edit[$i]['field_enable_resource_scheduler[value]'])) {
$this->deleteResourceQuotaMockData($resource_quota_edit);
......
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