Skip to content

Commit

Permalink
Feat/cdh 115/remove unset schema version dev config (#54)
Browse files Browse the repository at this point in the history
* feat(CDH-115): support hard delete in DeleteAllSchemasCommand

* feat(CDH-115): cs-fixes
  • Loading branch information
nikolatrajkovic994 authored Sep 19, 2023
1 parent ded98bd commit 5b0633b
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
17 changes: 16 additions & 1 deletion src/Command/DeleteAllSchemasCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Jobcloud\SchemaConsole\Command;

use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class DeleteAllSchemasCommand extends AbstractSchemaCommand
Expand All @@ -17,7 +18,13 @@ protected function configure(): void
$this
->setName('kafka-schema-registry:delete:all')
->setDescription('Delete all schemas')
->setHelp('Delete all schemas');
->setHelp('Delete all schemas')
->addOption(
'hard',
null,
InputOption::VALUE_NONE,
'Hard delete of a schema (removes all metadata, including schema ID)'
);
}

/**
Expand All @@ -29,8 +36,16 @@ public function execute(InputInterface $input, OutputInterface $output): int
{
$schemas = $this->schemaRegistryApi->getSubjects();

$hardDelete = (bool) $input->getOption('hard');

foreach ($schemas as $schemaName) {
$this->schemaRegistryApi->deleteSubject($schemaName);

if ($hardDelete) {
$this->schemaRegistryApi->deleteSubject(
sprintf('%s%s', $schemaName, '?permanent=true')
);
}
}

$output->writeln('All schemas deleted.');
Expand Down
39 changes: 38 additions & 1 deletion tests/Command/DeleteAllSchemasCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
class DeleteAllSchemasCommandTest extends TestCase
{
public function testCommand(): void
public function testCommandSoftDelete(): void
{
/** @var MockObject|KafkaSchemaRegistryApiClient $schemaRegistryApi */
$schemaRegistryApi = $this->getMockBuilder(KafkaSchemaRegistryApiClient::class)
Expand All @@ -41,4 +41,41 @@ public function testCommand(): void
self::assertEquals('All schemas deleted.', $commandOutput);
self::assertEquals(0, $commandTester->getStatusCode());
}

public function testCommandHardDelete(): void
{
/** @var MockObject|KafkaSchemaRegistryApiClient $schemaRegistryApi */
$schemaRegistryApi = $this->getMockBuilder(KafkaSchemaRegistryApiClient::class)
->disableOriginalConstructor()
->onlyMethods(['getSubjects', 'deleteSubject'])
->getMock();

$schemaRegistryApi->expects(self::once())
->method('getSubjects')
->willReturn(['schema1']);

$schemaRegistryApi->expects(self::exactly(2))
->method('deleteSubject')
->with(self::callback(function ($inputArgument) {
static $input = 'schema1';
if ($inputArgument === $input) {
$input = $input . '?permanent=true';
return true;
}
return false;
}))
->willReturn([]);

$application = new Application();
$application->add(new DeleteAllSchemasCommand($schemaRegistryApi));
$command = $application->find('kafka-schema-registry:delete:all');
$commandTester = new CommandTester($command);

$commandTester->execute(['--hard' => true]);

$commandOutput = trim($commandTester->getDisplay());

self::assertEquals('All schemas deleted.', $commandOutput);
self::assertEquals(0, $commandTester->getStatusCode());
}
}

0 comments on commit 5b0633b

Please sign in to comment.