You've already forked Traefik-Redis-Api
that coulda been bad
This commit is contained in:
113
tests/Traefik/RedisClientRoutersTest.php
Normal file
113
tests/Traefik/RedisClientRoutersTest.php
Normal file
@@ -0,0 +1,113 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Siteworxpro\Tests\Traefik;
|
||||||
|
|
||||||
|
use Mockery;
|
||||||
|
use Predis\Command\FactoryInterface;
|
||||||
|
use Siteworxpro\App\Facades\Redis;
|
||||||
|
use Siteworxpro\App\Traefik\EntityEnum;
|
||||||
|
use Siteworxpro\App\Traefik\ProtocolEnum;
|
||||||
|
use Siteworxpro\App\Traefik\RedisClient;
|
||||||
|
use Siteworxpro\Tests\Unit;
|
||||||
|
|
||||||
|
class RedisClientRoutersTest extends Unit
|
||||||
|
{
|
||||||
|
protected function tearDown(): void
|
||||||
|
{
|
||||||
|
parent::tearDown();
|
||||||
|
Mockery::close();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createTest(ProtocolEnum $protocol): void
|
||||||
|
{
|
||||||
|
$commandFactory = Mockery::mock(FactoryInterface::class)
|
||||||
|
->expects('supports')
|
||||||
|
->andReturn(true)
|
||||||
|
->getMock();
|
||||||
|
|
||||||
|
Redis::expects('getCommandFactory')
|
||||||
|
->andReturn($commandFactory);
|
||||||
|
|
||||||
|
Redis::expects('scan')
|
||||||
|
->with(0, ['MATCH' => 'traefik/' . $protocol->getValue() . '/routers/foo/*'])
|
||||||
|
->andReturn([0, []]);
|
||||||
|
|
||||||
|
Redis::expects('set')
|
||||||
|
->with('traefik/' . $protocol->getValue() . '/routers/foo/rule', 'Host(`foo.localhost`)')
|
||||||
|
->once()
|
||||||
|
->andReturn(true);
|
||||||
|
|
||||||
|
Redis::expects('set')
|
||||||
|
->with('traefik/' . $protocol->getValue() . '/routers/foo/service', 'foo')
|
||||||
|
->once()
|
||||||
|
->andReturn(true);
|
||||||
|
|
||||||
|
RedisClient::createOrReplace('foo', [
|
||||||
|
'rule' => 'Host(`foo.localhost`)',
|
||||||
|
'service' => 'foo',
|
||||||
|
], EntityEnum::ROUTER, $protocol);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCreateRouterHttp()
|
||||||
|
{
|
||||||
|
$this->createTest(ProtocolEnum::HTTP);
|
||||||
|
$this->assertTrue(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCreateRouterTcp()
|
||||||
|
{
|
||||||
|
$this->createTest(ProtocolEnum::TCP);
|
||||||
|
$this->assertTrue(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCreateRouterUcp()
|
||||||
|
{
|
||||||
|
$this->createTest(ProtocolEnum::UDP);
|
||||||
|
$this->assertTrue(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function allTest(ProtocolEnum $protocol): void
|
||||||
|
{
|
||||||
|
$commandFactory = Mockery::mock(FactoryInterface::class)
|
||||||
|
->expects('supports')
|
||||||
|
->andReturn(true)
|
||||||
|
->getMock();
|
||||||
|
|
||||||
|
Redis::expects('getCommandFactory')
|
||||||
|
->andReturn($commandFactory);
|
||||||
|
|
||||||
|
Redis::expects('scan')
|
||||||
|
->with(0, ['MATCH' => 'traefik/' . $protocol->getValue() . '/routers/*'])
|
||||||
|
->andReturn([0, [
|
||||||
|
'traefik/' . $protocol->getValue() . '/routers/foo/url/0',
|
||||||
|
'traefik/' . $protocol->getValue() . '/routers/foo/healthcheck/path',
|
||||||
|
'traefik/' . $protocol->getValue() . '/routers/bar/url/0',
|
||||||
|
]]);
|
||||||
|
|
||||||
|
$routers = RedisClient::getAllRouters($protocol);
|
||||||
|
|
||||||
|
$this->assertIsArray($routers);
|
||||||
|
$this->assertCount(2, $routers);
|
||||||
|
$this->assertEquals([
|
||||||
|
'bar',
|
||||||
|
'foo'
|
||||||
|
], $routers);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testAllRoutersHttp()
|
||||||
|
{
|
||||||
|
$this->allTest(ProtocolEnum::HTTP);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testAllRoutersTcp()
|
||||||
|
{
|
||||||
|
$this->allTest(ProtocolEnum::TCP);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testAllRoutersUdp()
|
||||||
|
{
|
||||||
|
$this->allTest(ProtocolEnum::UDP);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user