Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rennokki committed Mar 7, 2022
1 parent 6ad211e commit 61e9712
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/Kinds/K8sPod.php
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ public function getInitContainerStatuses(bool $asInstance = true): array
*
* @param string $containerName
* @param bool $asInstance
* @return array|null
* @return \RenokiCo\PhpK8s\Instances\Container|array|null
*/
public function getContainer(string $containerName, bool $asInstance = true)
{
Expand Down
24 changes: 12 additions & 12 deletions tests/ClusterRoleBindingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function test_cluster_role_binding_build()
->addVerbs(['get', 'list', 'watch']);

$cr = $this->cluster->clusterRole()
->setName('admin-cr')
->setName('admin-cr-for-binding')
->setLabels(['tier' => 'backend'])
->addRules([$rule]);

Expand All @@ -39,7 +39,7 @@ public function test_cluster_role_binding_build()
$this->assertEquals('user-binding', $crb->getName());
$this->assertEquals(['tier' => 'backend'], $crb->getLabels());
$this->assertEquals([$subject], $crb->getSubjects());
$this->assertEquals(['apiGroup' => 'rbac.authorization.k8s.io', 'kind' => 'ClusterRole', 'name' => 'admin-cr'], $crb->getRole());
$this->assertEquals(['apiGroup' => 'rbac.authorization.k8s.io', 'kind' => 'ClusterRole', 'name' => 'admin-cr-for-binding'], $crb->getRole());
}

public function test_cluster_role_binding_from_yaml()
Expand All @@ -51,7 +51,7 @@ public function test_cluster_role_binding_from_yaml()
->addVerbs(['get', 'list', 'watch']);

$cr = $this->cluster->clusterRole()
->setName('admin-cr')
->setName('admin-cr-for-binding')
->setLabels(['tier' => 'backend'])
->addRules([$rule]);

Expand All @@ -66,7 +66,7 @@ public function test_cluster_role_binding_from_yaml()
$this->assertEquals('user-binding', $crb->getName());
$this->assertEquals(['tier' => 'backend'], $crb->getLabels());
$this->assertEquals([$subject], $crb->getSubjects());
$this->assertEquals(['apiGroup' => 'rbac.authorization.k8s.io', 'kind' => 'ClusterRole', 'name' => 'admin-cr'], $crb->getRole());
$this->assertEquals(['apiGroup' => 'rbac.authorization.k8s.io', 'kind' => 'ClusterRole', 'name' => 'admin-cr-for-binding'], $crb->getRole());
}

public function test_cluster_role_binding_api_interaction()
Expand All @@ -89,7 +89,7 @@ public function runCreationTests()
->addVerbs(['get', 'list', 'watch']);

$cr = $this->cluster->clusterRole()
->setName('admin-cr')
->setName('admin-cr-for-binding')
->setLabels(['tier' => 'backend'])
->addRules([$rule]);

Expand Down Expand Up @@ -120,7 +120,7 @@ public function runCreationTests()
$this->assertEquals('user-binding', $crb->getName());
$this->assertEquals(['tier' => 'backend'], $crb->getLabels());
$this->assertEquals([$subject], $crb->getSubjects());
$this->assertEquals(['apiGroup' => 'rbac.authorization.k8s.io', 'kind' => 'ClusterRole', 'name' => 'admin-cr'], $crb->getRole());
$this->assertEquals(['apiGroup' => 'rbac.authorization.k8s.io', 'kind' => 'ClusterRole', 'name' => 'admin-cr-for-binding'], $crb->getRole());
}

public function runGetAllTests()
Expand All @@ -143,7 +143,7 @@ public function runGetTests()
->setKind('User')
->setName('user-1');

$cr = $this->cluster->getClusterRoleByName('admin-cr');
$cr = $this->cluster->getClusterRoleByName('admin-cr-for-binding');
$crb = $this->cluster->getClusterRoleBindingByName('user-binding');

$this->assertInstanceOf(K8sClusterRoleBinding::class, $crb);
Expand All @@ -154,12 +154,12 @@ public function runGetTests()
$this->assertEquals('user-binding', $crb->getName());
$this->assertEquals(['tier' => 'backend'], $crb->getLabels());
$this->assertEquals([$subject], $crb->getSubjects());
$this->assertEquals(['apiGroup' => 'rbac.authorization.k8s.io', 'kind' => 'ClusterRole', 'name' => 'admin-cr'], $crb->getRole());
$this->assertEquals(['apiGroup' => 'rbac.authorization.k8s.io', 'kind' => 'ClusterRole', 'name' => 'admin-cr-for-binding'], $crb->getRole());
}

public function runUpdateTests()
{
$cr = $this->cluster->getClusterRoleByName('admin-cr');
$cr = $this->cluster->getClusterRoleByName('admin-cr-for-binding');
$crb = $this->cluster->getClusterRoleBindingByName('user-binding');

$subject = K8s::subject()
Expand All @@ -179,12 +179,12 @@ public function runUpdateTests()
$this->assertEquals('user-binding', $crb->getName());
$this->assertEquals(['tier' => 'backend'], $crb->getLabels());
$this->assertEquals([$subject], $crb->getSubjects());
$this->assertEquals(['apiGroup' => 'rbac.authorization.k8s.io', 'kind' => 'ClusterRole', 'name' => 'admin-cr'], $crb->getRole());
$this->assertEquals(['apiGroup' => 'rbac.authorization.k8s.io', 'kind' => 'ClusterRole', 'name' => 'admin-cr-for-binding'], $crb->getRole());
}

public function runDeletionTests()
{
$cr = $this->cluster->getClusterRoleByName('admin-cr');
$cr = $this->cluster->getClusterRoleByName('admin-cr-for-binding');
$crb = $this->cluster->getClusterRoleBindingByName('user-binding');

$this->assertTrue($cr->delete());
Expand All @@ -200,7 +200,7 @@ public function runDeletionTests()

$this->expectException(KubernetesAPIException::class);

$this->cluster->getClusterRoleByName('admin-cr');
$this->cluster->getClusterRoleByName('admin-cr-for-binding');
$this->cluster->getClusterRoleBindingByName('user-binding');
}

Expand Down
8 changes: 4 additions & 4 deletions tests/PodTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function test_pod_api_interaction()
public function test_pod_exec()
{
$busybox = K8s::container()
->setName('busybox')
->setName('busybox-exec')
->setImage('busybox')
->setCommand(['/bin/sh', '-c', 'sleep 7200']);

Expand All @@ -126,7 +126,7 @@ public function test_pod_exec()
$pod->refresh();
}

$messages = $pod->exec(['/bin/sh', '-c', 'echo 1 && echo 2 && echo 3'], 'busybox');
$messages = $pod->exec(['/bin/sh', '-c', 'echo 1 && echo 2 && echo 3'], 'busybox-exec');

$hasDesiredOutput = collect($messages)->where('channel', 'stdout')->filter(function ($message) {
return Str::contains($message['output'], '1')
Expand All @@ -142,15 +142,15 @@ public function test_pod_exec()
public function test_pod_attach()
{
$mysql = K8s::container()
->setName('mysql')
->setName('mysql-attach')
->setImage('mysql', '5.7')
->setPorts([
['name' => 'mysql', 'protocol' => 'TCP', 'containerPort' => 3306],
])
->setEnv(['MYSQL_ROOT_PASSWORD' => 'test']);

$pod = $this->cluster->pod()
->setName('mysql-exec')
->setName('mysql-attach')
->setContainers([$mysql])
->createOrUpdate();

Expand Down

0 comments on commit 61e9712

Please sign in to comment.