clrghouz/tests/Feature/RoutingTest.php

95 lines
1.7 KiB
PHP

<?php
namespace Tests\Feature;
use Illuminate\Database\Eloquent\Collection;
use Tests\TestCase;
use App\Models\Domain;
class RoutingTest extends TestCase
{
private function zone(): Collection
{
$do = Domain::where('name','Domain A')->singleOrFail();
$zo = $do->zones->where('zone_id',100)->pop();
return $zo->addresses;
}
/**
* Test the ZC address.
*
* @return void
*/
public function test_zc()
{
$nodes = $this->zone();
$this->assertEquals(51,$nodes->count());
/*
* ZCs addresses are not in the address table, so we cannot workout children
$zc = $nodes->where('role',DomainController::NODE_ZC);
$this->assertEquals(1,$zc->count());
$zc = $zc->pop();
// ZC has 2 Region and 3 nodes as children
$this->assertEquals(5,$zc->children());
*/
}
/**
* Test the RC address.
*
* @return void
*/
public function test_rc()
{
$nodes = $this->zone();
$rc = $nodes->where('role','Region');
$this->assertEquals(2,$rc->count());
// First RC
$rc = $rc->pop();
// RC has 3 nodes and 2 hosts as children
$this->assertEquals(5,$rc->children->count());
}
/**
* Test the NC address.
*
* @return void
*/
public function test_nc()
{
$nodes = $this->zone();
$nc = $nodes->where('role','Host');
$this->assertEquals(4,$nc->count());
// First NC
$nc = $nc->pop();
// NC has 3 nodes and 2 hubs as children
$this->assertEquals(5,$nc->children->count());
}
/**
* Test the HC address.
*
* @return void
*/
public function test_hc()
{
$nodes = $this->zone();
$hc = $nodes->where('role','Hub');
//dd($hc->pluck('ftn'));
$this->assertEquals(8,$hc->count());
// First HC
$hc = $hc->pop();
// HC has 2 children
$this->assertEquals(2,$hc->children->count());
}
}