mirror of
https://github.com/coollabsio/coolify.git
synced 2026-11-06 21:18:11 -04:00
fix(clone): replace the clone suffix instead of adding one for each clone
Cloning a clone added another "-clone-<id>" to the name, so after about seven clones the name was longer than 255 characters and the insert failed. Closes #9976
This commit is contained in:
@@ -179,3 +179,18 @@ test('cloning a service without volume data dispatches no volume copy', function
|
||||
Bus::assertNotDispatched(VolumeCloneJob::class);
|
||||
expect(serviceVolumeNames($clone))->toHaveCount(2);
|
||||
});
|
||||
|
||||
test('cloning a cloned service replaces the clone suffix instead of adding another one', function () {
|
||||
$this->service->update(['name' => 'Gitea Runner']);
|
||||
|
||||
$source = $this->service;
|
||||
foreach (range(1, 10) as $ignored) {
|
||||
Livewire::test(ResourceOperations::class, ['resource' => $source])
|
||||
->call('cloneTo', $this->destination->uuid)
|
||||
->assertHasNoErrors();
|
||||
|
||||
$source = Service::query()->latest('id')->firstOrFail();
|
||||
}
|
||||
|
||||
expect($source->name)->toBe("Gitea Runner-clone-{$source->uuid}");
|
||||
});
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
it('adds a clone suffix to the source name', function () {
|
||||
expect(clone_resource_name('Gitea Runner', 'abc123def456ghi789jkl012'))
|
||||
->toBe('Gitea Runner-clone-abc123def456ghi789jkl012');
|
||||
});
|
||||
|
||||
it('replaces the clone suffixes of earlier clones', function () {
|
||||
$name = 'Gitea Runner-clone-sy2cojnseswr8szrpj1omsgw-clone-yvj9kdc2xuff8td0f0mps7eq-clone-ab12cd3';
|
||||
|
||||
expect(clone_resource_name($name, 'newid000000000000000000a'))
|
||||
->toBe('Gitea Runner-clone-newid000000000000000000a');
|
||||
});
|
||||
|
||||
it('keeps a name that only contains the word clone', function () {
|
||||
expect(clone_resource_name('my-clone-db', 'abc123def456ghi789jkl012'))
|
||||
->toBe('my-clone-db-clone-abc123def456ghi789jkl012');
|
||||
});
|
||||
|
||||
it('keeps the clone name within the 255 characters of the name column', function () {
|
||||
$name = clone_resource_name(str_repeat('a', 255), 'abc123def456ghi789jkl012');
|
||||
|
||||
expect($name)->toHaveLength(255)
|
||||
->toEndWith('-clone-abc123def456ghi789jkl012');
|
||||
});
|
||||
Reference in New Issue
Block a user