cloud-8.x-2.0-beta1/modules/cloud_service_providers/k8s/tests/src/Functional/K8sPodTest.php
modules/cloud_service_providers/k8s/tests/src/Functional/K8sPodTest.php
<?php
namespace Drupal\Tests\k8s\Functional;
/**
* Tests K8s pod.
*
* @group k8s
*/
class K8sPodTest extends K8sTestCase {
const K8S_POD_REPEAT_COUNT = 3;
/**
* {@inheritdoc}
*/
protected function getPermissions() {
$namespaces = $this->createNamespacesRandomTestFormData();
$this->createNamespaceTestEntity($namespaces[0]);
$this->namespace = $namespaces[0]['name'];
return [
'list k8s pod',
'add k8s pod',
'view any k8s pod',
'edit any k8s pod',
'delete any k8s pod',
'view k8s namespace ' . $this->namespace,
];
}
/**
* Tests CRUD for Pod.
*/
public function testPod() {
$cloud_context = $this->cloudContext;
// List Pod for K8s.
$this->drupalGet("/clouds/k8s/$cloud_context/pod");
$this->assertResponse(200);
// Add a new Pod.
$add = $this->createPodTestFormData(self::K8S_POD_REPEAT_COUNT, $this->namespace);
for ($i = 0; $i < self::K8S_POD_REPEAT_COUNT; $i++) {
$this->reloadMockData();
$this->addPodMockData($add[$i]);
$num = $i + 1;
$this->drupalPostForm(
"/clouds/k8s/$cloud_context/pod/add",
$add[$i]['post_data'],
t('Save')
);
$this->assertResponse(200);
$this->assertText(t('The Kubernetes Pod "@name" has been created.', ['@name' => $add[$i]['name']]));
// Make sure listing.
$this->drupalGet("/clouds/k8s/$cloud_context/pod");
$this->assertResponse(200);
$this->assertText($add[$i]['name']);
// Assert logs.
$logs = $this->random->name(128, TRUE);
$this->getPodLogsMockData($logs);
$this->drupalGet("/clouds/k8s/$cloud_context/pod/$num/log");
$this->assertResponse(200);
$this->assertText($logs);
}
// Edit a Pod.
$edit = $this->createPodTestFormData(self::K8S_POD_REPEAT_COUNT, $this->namespace);
for ($i = 0; $i < self::K8S_POD_REPEAT_COUNT; $i++) {
$num = $i + 1;
$this->updatePodMockData($edit[$i]);
unset($edit[$i]['post_data']['namespace']);
$this->drupalPostForm(
"/clouds/k8s/$cloud_context/pod/$num/edit",
$edit[$i]['post_data'],
t('Save')
);
$this->assertResponse(200);
$this->assertText(t(
'The Kubernetes Pod "@name" has been saved.',
['@name' => $add[$i]['name']]
));
}
// Delete Pod.
for ($i = 0; $i < self::K8S_POD_REPEAT_COUNT; $i++) {
$num = $i + 1;
$this->deletePodMockData($add[$i]);
$this->drupalPostForm(
"/clouds/k8s/$cloud_context/pod/$num/delete",
[],
t('Delete')
);
$this->assertResponse(200);
$this->assertText(t(
'The Kubernetes Pod "@name" has been deleted.',
['@name' => $add[$i]['name']]
));
// Make sure listing.
$this->drupalGet("/clouds/k8s/$cloud_context/pod");
$this->assertResponse(200);
$this->assertNoText($add[$i]['name']);
}
}
/**
* Tests deleting pods with bulk operation.
*/
public function testPodBulk() {
$cloud_context = $this->cloudContext;
for ($i = 0; $i < self::K8S_POD_REPEAT_COUNT; $i++) {
// Create Pods.
$pods = $this->createPodsRandomTestFormData($this->namespace);
$entities = [];
foreach ($pods as $pod) {
$entities[] = $this->createPodTestEntity($pod);
}
$this->deletePodMockData($pods[0]);
$this->doTestEntityBulk('pod', $entities);
}
}
}
