Skip to content

Commit

Permalink
mock
Browse files Browse the repository at this point in the history
  • Loading branch information
THWiseman committed Nov 7, 2023
1 parent 510aa31 commit b5e3c37
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -426,10 +426,12 @@ trait StandardAsyncExecutionActor
|find . -type d -exec sh -c '[ -z "$$(ls -A '"'"'{}'"'"')" ] && touch '"'"'{}'"'"'/.file' \\;
|)""".stripMargin)

val errorOrPreamble: ErrorOr[String] = scriptPreamble

// The `tee` trickery below is to be able to redirect to known filenames for CWL while also streaming
// stdout and stderr for PAPI to periodically upload to cloud storage.
// https://stackoverflow.com/questions/692000/how-do-i-write-stderr-to-a-file-while-using-tee-with-a-pipe
(errorOrDirectoryOutputs, errorOrGlobFiles, scriptPreamble).mapN((directoryOutputs, globFiles, preamble) =>
(errorOrDirectoryOutputs, errorOrGlobFiles, errorOrPreamble).mapN((directoryOutputs, globFiles, preamble) =>
s"""|#!$jobShell
|DOCKER_OUTPUT_DIR_LINK
|cd ${cwd.pathAsString}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ package cromwell.backend.impl.tes

import common.mock.MockSugar
import cromwell.core.logging.JobLogger
import cromwell.core.path
import cromwell.filesystems.blob.{BlobFileSystemManager, BlobPath, WSMBlobSasTokenGenerator}
import org.mockito.ArgumentMatchers.any
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers

import java.nio.file.Path
import java.time.Duration
import java.time.temporal.ChronoUnit
import scala.util.{Failure, Try}
Expand Down Expand Up @@ -65,30 +63,28 @@ class TesAsyncBackendJobExecutionActorSpec extends AnyFlatSpec with Matchers wit
val testWorkspaceId = "e58ed763-928c-4155-0000-fdbaaadc15f3"
val testContainerResourceId = "e58ed763-928c-4155-1111-fdbaaadc15f3"

def generateMockWsmTokenGenerator: WSMBlobSasTokenGenerator = {
val mockTokenGenerator = mock[WSMBlobSasTokenGenerator]
val expectedTokenDuration: Duration = Duration.of(24, ChronoUnit.HOURS)
mockTokenGenerator.getWSMSasFetchEndpoint(any[BlobPath], any[Option[Duration]]) returns Try(s"$testWsmEndpoint/api/workspaces/v1/$testWorkspaceId/resources/controlled/azure/storageContainer/$testContainerResourceId/getSasToken?sasExpirationDuration=${expectedTokenDuration.getSeconds.toInt}")
mockTokenGenerator
}
def generateMockFsm: BlobFileSystemManager = {
val mockFsm: BlobFileSystemManager = mock[BlobFileSystemManager]
val mockGenerator: WSMBlobSasTokenGenerator = generateMockWsmTokenGenerator
mockFsm.blobTokenGenerator returns mockGenerator
mockFsm
}
//path to a blob file
def generateMockBlobPath: BlobPath = {
val mockCromwellPath: cromwell.core.path.Path = mock[cromwell.core.path.Path]
mockCromwellPath.normalize() returns mockCromwellPath
val mockNioPath: path.NioPath = mock[path.NioPath]
val mockJavaPath: Path = mock[java.nio.file.Path]
mockNioPath.toAbsolutePath returns mockJavaPath
mockNioPath.normalize() returns mockNioPath

val mockBlobPath = mock[BlobPath]
mockBlobPath.nioPath returns mockNioPath
mockBlobPath.toAbsolutePath returns mockCromwellPath
mockBlobPath.md5 returns "BLOB_MD5"

val mockTokenGenerator: WSMBlobSasTokenGenerator = mock[WSMBlobSasTokenGenerator]
val mockFsm: BlobFileSystemManager = mock[BlobFileSystemManager]
val expectedTokenDuration: Duration = Duration.of(24, ChronoUnit.HOURS)
mockTokenGenerator.getWSMSasFetchEndpoint(mockBlobPath, Some(expectedTokenDuration)) returns Try(s"$testWsmEndpoint/api/workspaces/v1/$testWorkspaceId/resources/controlled/azure/storageContainer/$testContainerResourceId/getSasToken?sasExpirationDuration=${expectedTokenDuration.getSeconds.toInt}")
mockFsm.blobTokenGenerator returns mockTokenGenerator
val mockFsm = generateMockFsm
mockBlobPath.getFilesystemManager returns mockFsm

mockBlobPath
}


//Path to a file that isn't a blob file
def generateMockDefaultPath: cromwell.core.path.Path = {
val mockDefaultPath: cromwell.core.path.Path = mock[cromwell.core.path.Path]
Expand Down

0 comments on commit b5e3c37

Please sign in to comment.