Skip to content

Commit e5c1d3a

Browse files
Ace Nassriaverikitsch
andauthored
fix: fix tests using wrong Pub/Sub func name (GoogleCloudPlatform#7186)
* fix: fix tests using wrong Pub/Sub func name * Rename Kotlin sample, for consistency w/ other langs * Bash typo * Update build_cloud_functions.sh Co-authored-by: Averi Kitsch <akitsch@google.com>
1 parent 3dcab0c commit e5c1d3a

3 files changed

Lines changed: 17 additions & 6 deletions

File tree

.kokoro/tests/build_cloud_functions.sh

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,17 @@ export FUNCTIONS_GCS_FN_NAME="gcs-${SUFFIX}"
4242
# Set identity token (required for functions without --allow-unauthenticated)
4343
export 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
4657
set -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
6273
elif [[ "$file" == *"hello-gcs"* ]]; then
6374
echo "Deploying function HelloGcs to: ${FUNCTIONS_GCS_FN_NAME}"

functions/helloworld/kotlin-hello-pubsub/src/main/kotlin/functions/KotlinHelloBackground.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import java.util.Base64
2424
import 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]

functions/helloworld/kotlin-hello-pubsub/src/test/java/functions/KotlinHelloPubSubTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
@RunWith(JUnit4.class)
3434
public 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);

0 commit comments

Comments
 (0)