Skip to content
This repository has been archived by the owner on Apr 12, 2023. It is now read-only.

Commit

Permalink
feat: allow specific schema version to be deleted (#197)
Browse files Browse the repository at this point in the history
* feat: allow specific schema version to be deleted

* Should be name here

* Fix linting

Co-authored-by: Rob.Turner <[email protected]>
  • Loading branch information
r0bturner and robturner-kaluza authored Jun 29, 2021
1 parent 7bf33a9 commit 72e033e
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@ class SchemaViewModel @Inject constructor(
}

fun delete() = schemaRegistry?.deleteSubject(nameProperty.value)

fun deleteSchemaVersion() = schemaRegistry?.deleteSchemaVersion(nameProperty.value, selectedVersionProperty.value?.version!!)
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class SchemaView @Inject constructor(
hbox(alignment = Pos.CENTER_LEFT) {
fieldName("Schema")
schemaComboBox()
deleteSchemaVersionButton()
}
jsonView(viewModel.schemaProperty, formatter)
}
Expand All @@ -51,4 +52,10 @@ class SchemaView @Inject constructor(
viewModel.delete()
closeTab()
}.hideOnReadonly()

private fun EventTarget.deleteSchemaVersionButton() =
confirmationButton("Delete", "The schema \"${viewModel.nameProperty.value}\" version ${viewModel.selectedVersionProperty.value.version} will be removed.") {
viewModel.deleteSchemaVersion()
closeTab()
}.hideOnReadonly()
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@ class SchemaViewModelTest : StringSpec({
sut.error.value shouldBe null
}
}

"happy path delete schema version" {
SchemaViewModelTestFixture().use {
// arrange
val subject = Subject(name = it.targetSubject, schemas = listOf(Schema("{}", 1, 4)))
val sut = SchemaViewModel(it.cluster, subject, it.mockSchemaRegistry)
// act
sut.deleteSchemaVersion()
// assert
verify(exactly = 1) { it.mockSchemaRegistry.deleteSchemaVersion(it.targetSubject, subject.schemas[0].version) }
sut.error.value shouldBe null
}
}
})

private class SchemaViewModelTestFixture : FxContext() {
Expand Down
3 changes: 3 additions & 0 deletions lib/kafka/src/main/kotlin/insulator/kafka/SchemaRegistry.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ class SchemaRegistry(private val client: SchemaRegistryClient) {
fun deleteSubject(subject: String) =
client.runCatchingE { deleteSubject(subject) }.map { Unit }

fun deleteSchemaVersion(subject: String, version: Int) =
client.runCatchingE { deleteSchemaVersion(subject, version.toString()) }.map { Unit }

fun getAllSubjects(): Either<Throwable, Collection<String>> =
client.runCatchingE { allSubjects.sorted() }

Expand Down
12 changes: 12 additions & 0 deletions lib/kafka/src/test/kotlin/insulator/kafka/SchemaRegistryTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,18 @@ class SchemaRegistryTest : StringSpec({
res shouldBeRight { }
}

"happy path deleteSchemaVersion" {
// arrange
val mockSchema = mockk<SchemaRegistryClient> {
every { deleteSchemaVersion(any(), any()) } returns 1
}
val sut = SchemaRegistry(mockSchema)
// act
val res = sut.deleteSchemaVersion("subject1", 1)
// assert
res shouldBeRight { }
}

"register an invalid schema return left" {
// arrange
val mockSchema = mockk<SchemaRegistryClient>()
Expand Down

0 comments on commit 72e033e

Please sign in to comment.