From e033e380bf55df7581495ac7213b185340a535a7 Mon Sep 17 00:00:00 2001 From: Eric Rollins Date: Wed, 7 Feb 2024 11:03:26 -0500 Subject: [PATCH] Updated mocking. --- .../leonardo/http/api/RuntimeRoutes.scala | 8 -- .../provider/RuntimeStateManager.scala | 80 +++++++++++-------- 2 files changed, 46 insertions(+), 42 deletions(-) diff --git a/http/src/main/scala/org/broadinstitute/dsde/workbench/leonardo/http/api/RuntimeRoutes.scala b/http/src/main/scala/org/broadinstitute/dsde/workbench/leonardo/http/api/RuntimeRoutes.scala index 4e35dec9690..7ec2b0f99f0 100644 --- a/http/src/main/scala/org/broadinstitute/dsde/workbench/leonardo/http/api/RuntimeRoutes.scala +++ b/http/src/main/scala/org/broadinstitute/dsde/workbench/leonardo/http/api/RuntimeRoutes.scala @@ -266,20 +266,12 @@ class RuntimeRoutes(saturnIframeExtensionHostConfig: RefererConfig, ): IO[ToResponseMarshallable] = for { ctx <- ev.ask[AppContext] - _ = println("Log!") apiCall = runtimeService.updateRuntime(userInfo, googleProject, runtimeName, req) - _ = println("Double Log! ") - _ = println("Triple Log!: "+ apiCall) - _ = println("userInfo Log!: "+ userInfo) - _ = println("googleProject Log!: "+ googleProject) - _ = println("runtimeName Log!: "+ runtimeName) - _ = println("req Log!: "+ req) _ <- metrics.incrementCounter("updateRuntime") _ <- ctx.span.fold(apiCall)(span => spanResource[IO](span, "updateRuntime") .use(_ => apiCall) ) - _ = println("Do we get here?") } yield StatusCodes.Accepted: ToResponseMarshallable } diff --git a/pact4s/src/test/scala/org/broadinstitute/dsde/workbench/leonardo/provider/RuntimeStateManager.scala b/pact4s/src/test/scala/org/broadinstitute/dsde/workbench/leonardo/provider/RuntimeStateManager.scala index 2f2763f5df5..580d2b487c1 100644 --- a/pact4s/src/test/scala/org/broadinstitute/dsde/workbench/leonardo/provider/RuntimeStateManager.scala +++ b/pact4s/src/test/scala/org/broadinstitute/dsde/workbench/leonardo/provider/RuntimeStateManager.scala @@ -5,9 +5,9 @@ import cats.effect.unsafe.implicits.global import cats.mtl.Ask import org.broadinstitute.dsde.workbench.leonardo._ import org.broadinstitute.dsde.workbench.leonardo.http.service._ -import org.broadinstitute.dsde.workbench.leonardo.http.{CreateRuntimeRequest, UpdateRuntimeRequest} +import org.broadinstitute.dsde.workbench.leonardo.http.{CreateRuntimeRequest, CreateRuntimeResponse, UpdateRuntimeRequest} import org.broadinstitute.dsde.workbench.leonardo.model.{RuntimeAlreadyExistsException, RuntimeNotFoundException} -import org.broadinstitute.dsde.workbench.model.UserInfo +import org.broadinstitute.dsde.workbench.model.{TraceId, UserInfo} import org.broadinstitute.dsde.workbench.model.google.GoogleProject import org.mockito.ArgumentMatchers.{any, anyString} import org.mockito.Mockito.when @@ -37,27 +37,24 @@ object RuntimeStateManager { ) } yield () - private def mockUpdateNonexistentRuntime(mockRuntimeService: RuntimeService[IO]): IO[Unit] = for { - _ <- IO( - when { - mockRuntimeService.updateRuntime( - any[UserInfo], - eqTo(GoogleProject("googleProject")), - eqTo(RuntimeName("runtimename")), - any[UpdateRuntimeRequest] - )( - any[Ask[IO, AppContext]] - ) - } thenReturn { - IO.raiseError( - RuntimeNotFoundException(CloudContext.Gcp(GoogleProject("123")), - RuntimeName("nonexistentruntimename"), - "OOOPS" - ) - ) - } - ) - } yield () +// private def mockUpdateNonexistentRuntime(mockRuntimeService: RuntimeService[IO]): IO[Unit] = +// +// when(mockRuntimeService.updateRuntime( +// any[UserInfo], +// eqTo(GoogleProject("googleProject")), +// eqTo(RuntimeName("runtimename")), +// any[UpdateRuntimeRequest] +// )( +// any[Ask[IO, AppContext]] +// ) +// ).thenReturn { +// IO.raiseError( +// RuntimeNotFoundException(CloudContext.Gcp(GoogleProject("123")), +// RuntimeName("nonexistentruntimename"), +// "OOOPS" +// ) +// ) +// } private def mockRuntimeConflict(mockRuntimeService: RuntimeService[IO]): IO[Unit] = for { _ <- IO( @@ -137,17 +134,32 @@ object RuntimeStateManager { //// )(any[Ask[IO, AppContext]]) //// ).thenReturn(IO.unit) case ProviderState(States.RuntimeDoesNotExist, _) => -// when( -// mockRuntimeService.createRuntime(any[UserInfo], -// any[CloudContext.Gcp], -// RuntimeName(anyString()), -// any[CreateRuntimeRequest] -// )( -// any[Ask[IO, AppContext]] -// ) -// ).thenReturn(IO(CreateRuntimeResponse(TraceId("test")))) + when( + mockRuntimeService.createRuntime(any[UserInfo], + any[CloudContext.Gcp], + RuntimeName(anyString()), + any[CreateRuntimeRequest] + )( + any[Ask[IO, AppContext]] + ) + ).thenReturn(IO(CreateRuntimeResponse(TraceId("test")))) // mockGetNonexistentRuntime(mockRuntimeService).unsafeRunSync() - mockUpdateNonexistentRuntime(mockRuntimeService).unsafeRunSync() - + //mockUpdateNonexistentRuntime(mockRuntimeService).unsafeRunSync() + when(mockRuntimeService.updateRuntime( + any[UserInfo], + any[GoogleProject], + RuntimeName(anyString()), + any[UpdateRuntimeRequest] + )( + any[Ask[IO, AppContext]] + ) + ).thenReturn( + IO.raiseError( + RuntimeNotFoundException(CloudContext.Gcp(GoogleProject("123")), + RuntimeName("nonexistentruntimename"), + "Unable to find the runtime that you are trying to update" + ) + ) + ) } }