File tree Expand file tree Collapse file tree
functions/helloworld/kotlin-hello-pubsub/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -42,6 +42,17 @@ export FUNCTIONS_GCS_FN_NAME="gcs-${SUFFIX}"
4242# Set identity token (required for functions without --allow-unauthenticated)
4343export FUNCTIONS_IDENTITY_TOKEN=$( gcloud auth print-identity-token)
4444
45+ # Identify function language
46+ # (Currently only applicable for Pub/Sub functions)
47+ export LANGUAGE=" " # Java = empty string
48+ if [[ " $file " == * " scala" * ]]; then
49+ export LANGUAGE=" Scala"
50+ elif [[ " $file " == * " groovy" * ]]; then
51+ export LANGUAGE=" Groovy"
52+ elif [[ " $file " == * " kotlin" * ]]; then
53+ export LANGUAGE=" Kotlin"
54+ fi
55+
4556# Deploy functions
4657set -x
4758
@@ -57,7 +68,7 @@ elif [[ "$file" == *"hello-pubsub"* ]]; then
5768 gcloud functions deploy $FUNCTIONS_PUBSUB_FN_NAME \
5869 --region $FUNCTIONS_REGION \
5970 --runtime $FUNCTIONS_JAVA_RUNTIME \
60- --entry-point " functions.HelloPubSub" \
71+ --entry-point " functions.${LANGUAGE} HelloPubSub" \
6172 --trigger-topic $FUNCTIONS_SYSTEM_TEST_TOPIC
6273elif [[ " $file " == * " hello-gcs" * ]]; then
6374 echo " Deploying function HelloGcs to: ${FUNCTIONS_GCS_FN_NAME} "
Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ import java.util.Base64
2424import java.util.logging.Logger
2525
2626
27- class HelloPubSub : BackgroundFunction <Message > {
27+ class KotlinHelloPubSub : BackgroundFunction <Message > {
2828 override fun accept (message : Message , context : Context ) {
2929 // name's default value is "world"
3030 var name = " world"
@@ -38,7 +38,7 @@ class HelloPubSub : BackgroundFunction<Message> {
3838 }
3939
4040 companion object {
41- private val LOGGER = Logger .getLogger(HelloPubSub ::class .java.name)
41+ private val LOGGER = Logger .getLogger(KotlinHelloPubSub ::class .java.name)
4242 }
4343}
4444// [END functions_helloworld_pubsub]
Original file line number Diff line number Diff line change 3333@ RunWith (JUnit4 .class )
3434public class KotlinHelloPubSubTest {
3535 private static final Logger logger = Logger .getLogger (
36- HelloPubSub .class .getName ());
36+ KotlinHelloPubSub .class .getName ());
3737 private static final TestLogHandler LOG_HANDLER = new TestLogHandler ();
3838
3939 @ BeforeClass
@@ -52,15 +52,15 @@ public void functionsHelloworldPubSubKotlin_shouldPrintName() throws Exception {
5252 pubSubMessage .setData (Base64 .getEncoder ().encodeToString (
5353 "John" .getBytes (StandardCharsets .UTF_8 )));
5454
55- new HelloPubSub ().accept (pubSubMessage , new MockContext ());
55+ new KotlinHelloPubSub ().accept (pubSubMessage , new MockContext ());
5656
5757 String message = LOG_HANDLER .getStoredLogRecords ().get (0 ).getMessage ();
5858 assertThat ("Hello John!" ).isEqualTo (message );
5959 }
6060
6161 @ Test
6262 public void functionsHelloworldPubSubKotlin_shouldPrintHelloWorld () throws Exception {
63- new HelloPubSub ().accept (new Message (), new MockContext ());
63+ new KotlinHelloPubSub ().accept (new Message (), new MockContext ());
6464
6565 String message = LOG_HANDLER .getStoredLogRecords ().get (0 ).getMessage ();
6666 assertThat ("Hello world!" ).isEqualTo (message );
You can’t perform that action at this time.
0 commit comments