I am breaking my head with testing my controller.
I have the following test code that tests a simple csv upload, The file exists and the endpoint work when I try to upload from some simple rest client like postmen
I am getting: 400 unexpected end of input.
Tried everything i can think of. Thanks
val controller = application.injector.instanceOf[MyController] val file = play.api.libs.Files.TemporaryFile(FileUtils.toFile(getClass.getResource(MyCSV))) val data = new MultipartFormData(Map(), List( FilePart("file", "sample.csv", Some("application/csv"), file) ), List()) def fakeMultipartRequest: FakeRequest[AnyContentAsMultipartFormData] = FakeRequest(HttpVerbs.POST, "/upload") .withHeaders(("Content-Type", "multipart/form-data; boundary=***boundry***")) .withMultipartFormDataBody(data) val result = call(controller.upload(), fakeMultipartRequest) val str = contentAsString(result) status(result) shouldBe OK
and my controller is simple:
def upload() = Action.async(parse.multipartFormData) { implicit request => ...
Aucun commentaire:
Enregistrer un commentaire