Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
...t/src/test/scala/com/com/gu/sf_datalake_export/salesforce_bulk_api/S3UploadFileTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.com.gu.sf_datalake_export.salesforce_bulk_api | ||
|
||
import com.amazonaws.services.s3.model.{CannedAccessControlList, PutObjectRequest, PutObjectResult} | ||
import com.gu.effects.{BucketName, S3Path} | ||
import com.gu.sf_datalake_export.salesforce_bulk_api.S3UploadFile | ||
import com.gu.sf_datalake_export.salesforce_bulk_api.S3UploadFile.{File, FileContent, FileName} | ||
import org.scalatest.{FlatSpec, Matchers} | ||
|
||
import scala.util.{Success, Try} | ||
|
||
class S3UploadFileTest extends FlatSpec with Matchers{ | ||
val testPath = S3Path(BucketName("someBucket"), None) | ||
val testFile = File(FileName("someName"), FileContent("these are the file contents")) | ||
val successS3Result = Success(new PutObjectResult()) | ||
var s3WriteCalled = false | ||
|
||
def fakeS3Write(putRequest: PutObjectRequest): Try[PutObjectResult] = { | ||
s3WriteCalled = true | ||
putRequest.getBucketName shouldBe testPath.bucketName.value | ||
putRequest.getCannedAcl shouldBe CannedAccessControlList.BucketOwnerRead | ||
val fileContent = scala.io.Source.fromInputStream(putRequest.getInputStream).mkString | ||
fileContent shouldBe testFile.content.value | ||
successS3Result | ||
|
||
} | ||
|
||
it should "upload file" in { | ||
S3UploadFile(fakeS3Write)(testPath, testFile) shouldBe successS3Result | ||
s3WriteCalled shouldBe true | ||
} | ||
|
||
} |