-
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
970278f
commit 4ec316c
Showing
8 changed files
with
338 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
tests/Feature/Controllers/Admin/LocationControllerTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
use Convoy\Models\Location; | ||
use Convoy\Models\User; | ||
|
||
it('can fetch locations', function () { | ||
$user = User::factory()->create([ | ||
'root_admin' => true, | ||
]); | ||
|
||
$response = $this->actingAs($user)->getJson('/api/admin/locations'); | ||
|
||
$response->assertOk(); | ||
}); | ||
|
||
it('can create a location', function () { | ||
$user = User::factory()->create([ | ||
'root_admin' => true, | ||
]); | ||
|
||
$response = $this->actingAs($user)->postJson('/api/admin/locations', [ | ||
'name' => 'Test Location', | ||
'short_code' => 'test', | ||
'description' => 'This is a test location.', | ||
]); | ||
|
||
$response->assertOk(); | ||
}); | ||
|
||
it('can update a location', function () { | ||
$user = User::factory()->create([ | ||
'root_admin' => true, | ||
]); | ||
|
||
$location = Location::factory()->create(); | ||
|
||
$response = $this->actingAs($user)->putJson("/api/admin/locations/{$location->id}", [ | ||
'name' => 'Test Location', | ||
'short_code' => 'test', | ||
'description' => 'This is a test location.', | ||
]); | ||
|
||
$response->assertOk(); | ||
}); | ||
|
||
it('can delete a location', function () { | ||
$user = User::factory()->create([ | ||
'root_admin' => true, | ||
]); | ||
|
||
$location = Location::factory()->create(); | ||
|
||
$response = $this->actingAs($user)->deleteJson("/api/admin/locations/{$location->id}"); | ||
|
||
$response->assertNoContent(); | ||
}); |
149 changes: 149 additions & 0 deletions
149
tests/Feature/Controllers/Admin/Nodes/NodeControllerTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
<?php | ||
|
||
|
||
use Convoy\Models\Location; | ||
use Convoy\Models\Node; | ||
use Convoy\Models\Server; | ||
use Convoy\Models\User; | ||
|
||
beforeEach(function () { | ||
$this->user = User::factory()->create([ | ||
'root_admin' => true, | ||
]); | ||
$this->location = Location::factory()->create(); | ||
$this->node = Node::factory()->for($this->location)->create(); | ||
}); | ||
|
||
it('can fetch nodes', function () { | ||
$response = $this->actingAs($this->user)->getJson('/api/admin/nodes'); | ||
|
||
$response->assertOk(); | ||
}); | ||
|
||
it('can fetch a node', function () { | ||
$response = $this->actingAs($this->user)->getJson("/api/admin/nodes/{$this->node->id}"); | ||
|
||
$response->assertOk(); | ||
}); | ||
|
||
it('can create a node', function () { | ||
$response = $this->actingAs($this->user)->postJson('/api/admin/nodes', [ | ||
'location_id' => $this->location->id, | ||
'name' => 'Test Node', | ||
'cluster' => 'proxmox', | ||
'fqdn' => 'example.com', | ||
'token_id' => 'test-token', | ||
'secret' => 'test-secret', | ||
'port' => 8006, | ||
'memory' => 64 * 1024 * 1024 * 1024, // 64GB, | ||
'memory_overallocate' => 0, | ||
'disk' => 512 * 1024 * 1024 * 1024, // 512GB, | ||
'disk_overallocate' => 0, | ||
'vm_storage' => 'local-lvm', | ||
'backup_storage' => 'local-lvm', | ||
'iso_storage' => 'local-lvm', | ||
'network' => 'vmbr0', | ||
]); | ||
|
||
$response->assertOk(); | ||
}); | ||
|
||
it('can update a node', function () { | ||
$response = $this->actingAs($this->user)->putJson("/api/admin/nodes/{$this->node->id}", [ | ||
'location_id' => $this->location->id, | ||
'name' => 'Test Node', | ||
'cluster' => 'proxmox', | ||
'fqdn' => 'example.com', | ||
'token_id' => 'test-token', | ||
'secret' => 'test-secret', | ||
'port' => 8006, | ||
'memory' => 64 * 1024 * 1024 * 1024, // 64GB, | ||
'memory_overallocate' => 0, | ||
'disk' => 512 * 1024 * 1024 * 1024, // 512GB, | ||
'disk_overallocate' => 0, | ||
'vm_storage' => 'local-lvm', | ||
'backup_storage' => 'local-lvm', | ||
'iso_storage' => 'local-lvm', | ||
'network' => 'vmbr0', | ||
]); | ||
|
||
$response->assertOk(); | ||
}); | ||
|
||
it("can't downsize without over-allocating", function () { | ||
$node = Node::factory()->for($this->location)->create([ | ||
'memory' => 64 * 1024 * 1024 * 1024, // 64GB, | ||
'disk' => 512 * 1024 * 1024 * 1024, // 512GB, | ||
]); | ||
|
||
Server::factory()->for($node)->for($this->user)->create([ | ||
'memory' => 32 * 1024 * 1024 * 1024, // 32GB, | ||
'disk' => 256 * 1024 * 1024 * 1024, // 256GB, | ||
]); | ||
|
||
$response = $this->actingAs($this->user)->putJson("/api/admin/nodes/{$node->id}", [ | ||
'location_id' => $this->location->id, | ||
'name' => 'Test Node', | ||
'cluster' => 'proxmox', | ||
'fqdn' => 'example.com', | ||
'token_id' => 'test-token', | ||
'secret' => 'test-secret', | ||
'port' => 8006, | ||
'memory' => 16 * 1024 * 1024 * 1024, // 16GB, | ||
'memory_overallocate' => 0, | ||
'disk' => 128 * 1024 * 1024 * 1024, // 128GB, | ||
'disk_overallocate' => 0, | ||
'vm_storage' => 'local-lvm', | ||
'backup_storage' => 'local-lvm', | ||
'iso_storage' => 'local-lvm', | ||
'network' => 'vmbr0', | ||
]); | ||
|
||
$response->assertStatus(422); | ||
}); | ||
|
||
it('can update node without false positive overallocation', function () { | ||
$node = Node::factory()->for($this->location)->create([ | ||
'memory' => 64 * 1024 * 1024 * 1024, // 64GB, | ||
'disk' => 512 * 1024 * 1024 * 1024, // 512GB, | ||
]); | ||
|
||
Server::factory()->for($node)->for($this->user)->create([ | ||
'memory' => 64 * 1024 * 1024 * 1024, // 64GB, | ||
'disk' => 256 * 1024 * 1024 * 1024, // 256GB, | ||
]); | ||
|
||
$response = $this->actingAs($this->user)->putJson("/api/admin/nodes/{$node->id}", [ | ||
'location_id' => $this->location->id, | ||
'name' => 'New name', | ||
'cluster' => 'proxmox', | ||
'fqdn' => 'example.com', | ||
'token_id' => 'test-token', | ||
'secret' => 'test-secret', | ||
'port' => 8006, | ||
'memory' => 64 * 1024 * 1024 * 1024, // 64GB, | ||
'memory_overallocate' => 0, | ||
'disk' => 512 * 1024 * 1024 * 1024, // 512GB, | ||
'disk_overallocate' => 0, | ||
'vm_storage' => 'local-lvm', | ||
'backup_storage' => 'local-lvm', | ||
'iso_storage' => 'local-lvm', | ||
'network' => 'vmbr0', | ||
]); | ||
|
||
$response->assertOk(); | ||
}); | ||
|
||
it('can delete a node', function () { | ||
$response = $this->actingAs($this->user)->deleteJson("/api/admin/nodes/{$this->node->id}"); | ||
|
||
$response->assertNoContent(); | ||
}); | ||
|
||
it("can't delete a node with servers", function () { | ||
Server::factory()->for($this->node)->for($this->user)->create(); | ||
|
||
$response = $this->actingAs($this->user)->deleteJson("/api/admin/nodes/{$this->node->id}"); | ||
|
||
$response->assertForbidden(); | ||
}); |
Oops, something went wrong.