Skip to content

Commit da30f52

Browse files
committed
fix(model-client): implement tests for the deleteRepository method of ModelClientV2
1 parent 81d8615 commit da30f52

File tree

2 files changed

+38
-6
lines changed

2 files changed

+38
-6
lines changed

model-client/src/commonMain/kotlin/org/modelix/model/client2/ModelClientV2.kt

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,17 @@ class ModelClientV2(
141141
}
142142

143143
override suspend fun deleteRepository(repository: RepositoryId): Boolean {
144-
return httpClient.post {
145-
url {
146-
takeFrom(baseUrl)
147-
appendPathSegmentsEncodingSlash("repositories", repository.id, "delete")
148-
}
149-
}.status == HttpStatusCode.NoContent
144+
try {
145+
return httpClient.post {
146+
url {
147+
takeFrom(baseUrl)
148+
appendPathSegmentsEncodingSlash("repositories", repository.id, "delete")
149+
}
150+
}.status == HttpStatusCode.NoContent
151+
} catch (ex: Exception) {
152+
LOG.error(ex) { ex.message }
153+
return false
154+
}
150155
}
151156

152157
override suspend fun listBranches(repository: RepositoryId): List<BranchReference> {

model-server/src/test/kotlin/org/modelix/model/server/ModelClientV2Test.kt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import org.modelix.model.server.handlers.ModelReplicationServer
3636
import org.modelix.model.server.store.InMemoryStoreClient
3737
import org.modelix.modelql.core.count
3838
import org.modelix.modelql.untyped.allChildren
39+
import java.util.UUID
3940
import kotlin.test.Test
4041
import kotlin.test.assertEquals
4142

@@ -154,4 +155,30 @@ class ModelClientV2Test {
154155

155156
assertEquals("localhost", modelClient.getUserId())
156157
}
158+
159+
@Test
160+
fun `newly created repository can be removed`() = runTest {
161+
val url = "http://localhost/v2"
162+
val client = ModelClientV2.builder().url(url).client(client).build().also { it.init() }
163+
val repositoryId = RepositoryId(UUID.randomUUID().toString())
164+
client.initRepository(repositoryId)
165+
166+
val success = client.deleteRepository(repositoryId)
167+
168+
assertEquals(true, success)
169+
}
170+
171+
@Test
172+
fun `non-existing repository cannot be removed`() = runTest {
173+
val url = "http://localhost/v2"
174+
val client = ModelClientV2.builder().url(url).client(client).build().also { it.init() }
175+
val repositoryId = RepositoryId(UUID.randomUUID().toString())
176+
client.initRepository(repositoryId)
177+
178+
client.deleteRepository(repositoryId)
179+
// repository should not exist here
180+
val success = client.deleteRepository(repositoryId)
181+
182+
assertEquals(false, success)
183+
}
157184
}

0 commit comments

Comments
 (0)