سؤال

My application will upload file to S3, but I want it to upload to another bucket when running in test mode (play test). Is there any workaround for this? I saw in play 1.x has a feature called application ids. But I couldn't find it under 2.0 documentations.

when running test mode, play will use 'test.s3.bucket' instead of 's3.bucket'.

application.conf

s3.bucket=prodbucket
test.s3.bucket=testbucket

EDIT: Besides #kheraud answer, Application provides isProd(), isTest(), and isDev().

String bucketName = (Play.application().isProd())
                ? Play.application().configuration().getString("s3.bucket")
                : Play.application().configuration().getString("dev.s3.bucket");
هل كانت مفيدة؟

المحلول

You can have access to the running mode with (not tested):

import play.api.Play.current

val targetBukkett = if(play.api.Play.application.mode == "Dev") {
    test.s3.bucket
} else {
    s3.bucket
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top