Skip to content

Commit 5b0633b

Browse files
Feat/cdh 115/remove unset schema version dev config (#54)
* feat(CDH-115): support hard delete in DeleteAllSchemasCommand * feat(CDH-115): cs-fixes
1 parent ded98bd commit 5b0633b

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

src/Command/DeleteAllSchemasCommand.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Jobcloud\SchemaConsole\Command;
66

77
use Symfony\Component\Console\Input\InputInterface;
8+
use Symfony\Component\Console\Input\InputOption;
89
use Symfony\Component\Console\Output\OutputInterface;
910

1011
class DeleteAllSchemasCommand extends AbstractSchemaCommand
@@ -17,7 +18,13 @@ protected function configure(): void
1718
$this
1819
->setName('kafka-schema-registry:delete:all')
1920
->setDescription('Delete all schemas')
20-
->setHelp('Delete all schemas');
21+
->setHelp('Delete all schemas')
22+
->addOption(
23+
'hard',
24+
null,
25+
InputOption::VALUE_NONE,
26+
'Hard delete of a schema (removes all metadata, including schema ID)'
27+
);
2128
}
2229

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

39+
$hardDelete = (bool) $input->getOption('hard');
40+
3241
foreach ($schemas as $schemaName) {
3342
$this->schemaRegistryApi->deleteSubject($schemaName);
43+
44+
if ($hardDelete) {
45+
$this->schemaRegistryApi->deleteSubject(
46+
sprintf('%s%s', $schemaName, '?permanent=true')
47+
);
48+
}
3449
}
3550

3651
$output->writeln('All schemas deleted.');

tests/Command/DeleteAllSchemasCommandTest.php

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*/
1818
class DeleteAllSchemasCommandTest extends TestCase
1919
{
20-
public function testCommand(): void
20+
public function testCommandSoftDelete(): void
2121
{
2222
/** @var MockObject|KafkaSchemaRegistryApiClient $schemaRegistryApi */
2323
$schemaRegistryApi = $this->getMockBuilder(KafkaSchemaRegistryApiClient::class)
@@ -41,4 +41,41 @@ public function testCommand(): void
4141
self::assertEquals('All schemas deleted.', $commandOutput);
4242
self::assertEquals(0, $commandTester->getStatusCode());
4343
}
44+
45+
public function testCommandHardDelete(): void
46+
{
47+
/** @var MockObject|KafkaSchemaRegistryApiClient $schemaRegistryApi */
48+
$schemaRegistryApi = $this->getMockBuilder(KafkaSchemaRegistryApiClient::class)
49+
->disableOriginalConstructor()
50+
->onlyMethods(['getSubjects', 'deleteSubject'])
51+
->getMock();
52+
53+
$schemaRegistryApi->expects(self::once())
54+
->method('getSubjects')
55+
->willReturn(['schema1']);
56+
57+
$schemaRegistryApi->expects(self::exactly(2))
58+
->method('deleteSubject')
59+
->with(self::callback(function ($inputArgument) {
60+
static $input = 'schema1';
61+
if ($inputArgument === $input) {
62+
$input = $input . '?permanent=true';
63+
return true;
64+
}
65+
return false;
66+
}))
67+
->willReturn([]);
68+
69+
$application = new Application();
70+
$application->add(new DeleteAllSchemasCommand($schemaRegistryApi));
71+
$command = $application->find('kafka-schema-registry:delete:all');
72+
$commandTester = new CommandTester($command);
73+
74+
$commandTester->execute(['--hard' => true]);
75+
76+
$commandOutput = trim($commandTester->getDisplay());
77+
78+
self::assertEquals('All schemas deleted.', $commandOutput);
79+
self::assertEquals(0, $commandTester->getStatusCode());
80+
}
4481
}

0 commit comments

Comments
 (0)