Skip to content

Commit

Permalink
test: add test case for setting instance status in progress after update
Browse files Browse the repository at this point in the history
  • Loading branch information
JohannesRudolph committed Jun 21, 2024
1 parent 969158a commit e724359
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,23 @@ class ServiceInstanceRepository(private val yamlHandler: YamlHandler, private va
}

// TODO Check if an update request is allowed. See https://github.com/meshcloud/unipipe-service-broker/pull/35/files#r651527916
// Right now we don't apply any validation and trust the marketplace to know what it's doing.
//
// There are several actions that can be [triggered via an update request](https://github.com/openservicebrokerapi/servicebroker/blob/master/spec.md#updating-a-service-instance):
//- updating the plan a service instance is using, if `plan_updateable` is true
//- updating the context object of a service instance, if `allow_context_updates` is true
//- applying a maintenance update, if the service broker previously provided `maintenance_info` to the platform.
fun updateServiceInstance(serviceInstance: ServiceInstance) {
fun updateServiceInstance(serviceInstance: ServiceInstance): Status {
val serviceInstanceId = serviceInstance.serviceInstanceId

val instanceYml = serviceInstanceYmlFile(serviceInstanceId)

yamlHandler.writeObject(
objectToWrite = serviceInstance,
file = instanceYml
)

val statusYml = serviceInstanceStatusYmlFile(serviceInstanceId)
val status = Status("in progress", "service update")
val status = Status("in progress", "updating service")
yamlHandler.writeObject(
objectToWrite = status,
file = statusYml
Expand All @@ -55,6 +55,8 @@ class ServiceInstanceRepository(private val yamlHandler: YamlHandler, private va
gitHandler.commitAllChanges(
commitMessage = "Updated Service instance $serviceInstanceId"
)

return status
}

fun deleteServiceInstance(serviceInstance: ServiceInstance) {
Expand Down Expand Up @@ -87,7 +89,6 @@ class ServiceInstanceRepository(private val yamlHandler: YamlHandler, private va
return yamlHandler.readObject(instanceYml, ServiceInstance::class.java)
}


fun tryGetServiceInstanceGaugeMetrics(serviceInstanceId: String, from: Instant, to: Instant): List<ServiceInstanceDatapoints<GaugeMetricModel>> {
val instanceMetricsYmlFiles = serviceInstanceMetricsYmlFiles(serviceInstanceId, MetricType.GAUGE)
val serviceInstanceDatapointsList: MutableList<ServiceInstanceDatapoints<GaugeMetricModel>> = mutableListOf()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ class GenericServiceInstanceService(
?: throw ServiceInstanceDoesNotExistException(request.serviceInstanceId)

val updatedInstance = existingInstance.update(request)
repository.updateServiceInstance(updatedInstance)
val status = repository.updateServiceInstance(updatedInstance)

return Mono.just(
UpdateServiceInstanceResponse.builder()
.async(true)
.operation("updating service")
.operation(status.description)
.build()
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,30 @@ class UpdateServiceInstanceScenario : DockerOsbApplicationTests() {
val instance = repository.tryGetServiceInstance(instanceId)
instance!!.planId
}

assertEquals(createdPlanId, updatedPlanId)
}

@Test
fun `update request sets status to in progress`() {
val instanceId = "e4bd6a78-7e05-4d5a-97b8-f8c5d1c710db"
val createRequest = fixture.builder.createServiceInstanceRequest(instanceId)
serviceInstanceService.createServiceInstance(createRequest)

val updateRequest = fixture.builder.updateServiceInstanceRequest(instanceId) {
parameters("foo", "bar")
}

val response = serviceInstanceService.updateServiceInstance(updateRequest)

response.subscribe {
assertEquals("updating service", it.operation)
}

useServiceInstanceRepository { repository ->
val instance = repository.getServiceInstanceStatus(instanceId)
assertEquals("in progress", instance.status)
assertEquals("updating service", instance.description)
}
}
}

0 comments on commit e724359

Please sign in to comment.