1
1
mirror of https://github.com/pterodactyl/panel.git synced 2024-11-25 10:32:31 +01:00

Add more location tests, more travis CI fix attempts

This commit is contained in:
Dane Everitt 2017-06-16 00:29:19 -05:00
parent 579cc86910
commit a527949939
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53
5 changed files with 77 additions and 14 deletions

View File

@ -1,10 +1,11 @@
APP_ENV=testing
APP_DEBUG=true
APP_KEY=SomeRandomString32SomeRandomString32
APP_KEY=aaaaabbbbbcccccdddddeeeeefffff12
DB_CONNECTION=tests
DB_TEST_USERNAME=root
DB_TEST_PASSWORD=
TEST_DB_CONNECTION=tests
TEST_DB_TEST_USERNAME=root
TEST_DB_TEST_PASSWORD=
TEST_DB_HOST=127.0.0.1
CACHE_DRIVER=array
SESSION_DRIVER=array

View File

@ -3,8 +3,7 @@ dist: trusty
php:
- '7.0'
- '7.1'
- nightly
sudo: required
sudo: false
cache:
directories:
- $HOME/.composer/cache
@ -15,9 +14,9 @@ before_install:
before_script:
- phpenv config-rm xdebug.ini
- cp .env.travis .env
- composer install --no-interaction --no-scripts --prefer-dist --no-suggest
- php artisan migrate --force -v
- php artisan db:seed --force -v
- composer install --no-interaction --prefer-dist --no-suggest --verbose
- php artisan migrate -v
- php artisan db:seed -v
script:
- vendor/bin/phpunit --coverage-clover=coverage.xml
notifications:

View File

@ -47,11 +47,11 @@ return [
'tests' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'travis'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', ''),
'host' => env('TEST_DB_HOST', 'localhost'),
'port' => env('TEST_DB_PORT', '3306'),
'database' => env('TEST_DB_DATABASE', 'travis'),
'username' => env('TEST_DB_USERNAME', 'root'),
'password' => env('TEST_DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',

View File

@ -38,3 +38,22 @@ $factory->define(Pterodactyl\Models\Location::class, function (Faker\Generator $
'long' => $faker->catchPhrase,
];
});
$factory->define(Pterodactyl\Models\Node::class, function (Faker\Generator $faker) {
return [
'public' => true,
'name' => $faker->firstName,
'fqdn' => $faker->ipv4,
'scheme' => 'http',
'behind_proxy' => false,
'memory' => 1024,
'memory_overallocate' => 0,
'disk' => 10240,
'disk_overallocate' => 0,
'upload_size' => 100,
'daemonSecret' => $faker->uuid,
'daemonListen' => 8080,
'daemonSFTP' => 2022,
'daemonBase' => '/srv/daemon',
];
});

View File

@ -25,6 +25,8 @@
namespace Tests\Feature\Services;
use Illuminate\Validation\ValidationException;
use Pterodactyl\Exceptions\DisplayException;
use Pterodactyl\Models\Node;
use Tests\TestCase;
use Pterodactyl\Models\Location;
use Pterodactyl\Services\LocationService;
@ -201,4 +203,46 @@ class LocationServiceTest extends TestCase
{
$this->service->update(0, []);
}
/**
* Test that a location can be deleted normally when no nodes are attached.
*/
public function testShouldDeleteExistingLocation()
{
$location = factory(Location::class)->create();
$this->assertDatabaseHas('locations', [
'id' => $location->id,
]);
$model = $this->service->delete($location);
$this->assertTrue($model);
$this->assertDatabaseMissing('locations', [
'id' => $location->id,
]);
}
/**
* Test that a location cannot be deleted if a node is attached to it.
*
* @expectedException \Pterodactyl\Exceptions\DisplayException
*/
public function testShouldFailToDeleteExistingLocationWithAttachedNodes()
{
$location = factory(Location::class)->create();
$node = factory(Node::class)->create(['location_id' => $location->id]);
$this->assertDatabaseHas('locations', ['id' => $location->id]);
$this->assertDatabaseHas('nodes', ['id' => $node->id]);
try {
$this->service->delete($location->id);
} catch (\Exception $ex) {
$this->assertInstanceOf(DisplayException::class, $ex);
$this->assertNotEmpty($ex->getMessage());
throw $ex;
}
}
}