Skip to content

Commit

Permalink
added unit test for file upload
Browse files Browse the repository at this point in the history
  • Loading branch information
pvighi committed Dec 3, 2018
1 parent e909cdf commit f84b5f6
Showing 1 changed file with 32 additions and 0 deletions.
@@ -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
}

}

0 comments on commit f84b5f6

Please sign in to comment.