Skip to content

Commit

Permalink
Updated mocking.
Browse files Browse the repository at this point in the history
  • Loading branch information
evrii committed Feb 7, 2024
1 parent 79735ab commit e033e38
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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"
)
)
)
}
}

0 comments on commit e033e38

Please sign in to comment.