forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Google Cloud Functions integration tests
- Loading branch information
1 parent
7e0ba16
commit 232ff0e
Showing
11 changed files
with
355 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
integration-tests/funqy-google-cloud-functions/src/main/resources/application.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
#quarkus.funqy.export=helloGCSWorld | ||
#quarkus.funqy.export=helloPubSubWorld | ||
quarkus.funqy.export=helloCloudEvent | ||
quarkus.funqy.export=helloGCSWorld | ||
%pubsub.quarkus.funqy.export=helloPubSubWorld | ||
%cloud-event.quarkus.funqy.export=helloCloudEvent |
63 changes: 63 additions & 0 deletions
63
...ns/src/test/java/io/quarkus/funqy/gcp/functions/test/GreetingFunctionsCloudEventTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package io.quarkus.funqy.gcp.functions.test; | ||
|
||
import static io.restassured.RestAssured.given; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import com.google.cloud.functions.invoker.runner.Invoker; | ||
|
||
import io.quarkus.test.junit.QuarkusTest; | ||
import io.quarkus.test.junit.QuarkusTestProfile; | ||
import io.quarkus.test.junit.TestProfile; | ||
|
||
@QuarkusTest | ||
@TestProfile(GreetingFunctionsCloudEventTest.CloudEventFunctionTestProfile.class) | ||
class GreetingFunctionsCloudEventTest { | ||
@Test | ||
public void test() throws Exception { | ||
// start the invoker without joining to avoid blocking the thread | ||
Invoker invoker = new Invoker( | ||
8081, | ||
"io.quarkus.funqy.gcp.functions.FunqyCloudEventsFunction", | ||
"cloudevent", | ||
Thread.currentThread().getContextClassLoader()); | ||
invoker.startTestServer(); | ||
|
||
// test the function using RestAssured | ||
given() | ||
.body("{\n" + | ||
" \"bucket\": \"MY_BUCKET\",\n" + | ||
" \"contentType\": \"text/plain\",\n" + | ||
" \"kind\": \"storage#object\",\n" + | ||
" \"md5Hash\": \"...\",\n" + | ||
" \"metageneration\": \"1\",\n" + | ||
" \"name\": \"MY_FILE.txt\",\n" + | ||
" \"size\": \"352\",\n" + | ||
" \"storageClass\": \"MULTI_REGIONAL\",\n" + | ||
" \"timeCreated\": \"2020-04-23T07:38:57.230Z\",\n" + | ||
" \"timeStorageClassUpdated\": \"2020-04-23T07:38:57.230Z\",\n" + | ||
" \"updated\": \"2020-04-23T07:38:57.230Z\"\n" + | ||
" }") | ||
.header("ce-id", "123451234512345") | ||
.header("ce-specversion", "1.0") | ||
.header("ce-time", "2020-01-02T12:34:56.789Z") | ||
.header("ce-type", "google.cloud.storage.object.v1.finalized") | ||
.header("ce-source", "//storage.googleapis.com/projects/_/buckets/MY-BUCKET-NAME") | ||
.header("ce-subject", "objects/MY_FILE.txt") | ||
.when() | ||
.post("http://localhost:8081") | ||
.then() | ||
.statusCode(200); | ||
|
||
// stop the invoker | ||
invoker.stopServer(); | ||
} | ||
|
||
public static class CloudEventFunctionTestProfile implements QuarkusTestProfile { | ||
|
||
@Override | ||
public String getConfigProfile() { | ||
return "cloud-event"; | ||
} | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...ctions/src/test/java/io/quarkus/funqy/gcp/functions/test/GreetingFunctionsPubsubTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package io.quarkus.funqy.gcp.functions.test; | ||
|
||
import static io.restassured.RestAssured.given; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import com.google.cloud.functions.invoker.runner.Invoker; | ||
|
||
import io.quarkus.test.junit.QuarkusTest; | ||
import io.quarkus.test.junit.QuarkusTestProfile; | ||
import io.quarkus.test.junit.TestProfile; | ||
|
||
@QuarkusTest | ||
@TestProfile(GreetingFunctionsPubsubTest.PubsubFunctionTestProfile.class) | ||
class GreetingFunctionsPubsubTest { | ||
@Test | ||
public void test() throws Exception { | ||
// start the invoker without joining to avoid blocking the thread | ||
Invoker invoker = new Invoker( | ||
8081, | ||
"io.quarkus.funqy.gcp.functions.FunqyBackgroundFunction", | ||
"event", | ||
Thread.currentThread().getContextClassLoader()); | ||
invoker.startTestServer(); | ||
|
||
// test the function using RestAssured | ||
given() | ||
.body("{\"data\":{\"data\":\"world\"}}") | ||
.when() | ||
.post("http://localhost:8081") | ||
.then() | ||
.statusCode(200); | ||
|
||
// stop the invoker | ||
invoker.stopServer(); | ||
} | ||
|
||
public static class PubsubFunctionTestProfile implements QuarkusTestProfile { | ||
|
||
@Override | ||
public String getConfigProfile() { | ||
return "pubsub"; | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...tions/src/test/java/io/quarkus/funqy/gcp/functions/test/GreetingFunctionsStorageTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package io.quarkus.funqy.gcp.functions.test; | ||
|
||
import static io.restassured.RestAssured.given; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import com.google.cloud.functions.invoker.runner.Invoker; | ||
|
||
import io.quarkus.test.junit.QuarkusTest; | ||
|
||
@QuarkusTest | ||
class GreetingFunctionsStorageTest { | ||
@Test | ||
public void test() throws Exception { | ||
// start the invoker without joining to avoid blocking the thread | ||
Invoker invoker = new Invoker( | ||
8081, | ||
"io.quarkus.funqy.gcp.functions.FunqyBackgroundFunction", | ||
"event", | ||
Thread.currentThread().getContextClassLoader()); | ||
invoker.startTestServer(); | ||
|
||
// test the function using RestAssured | ||
given() | ||
.body("{\"data\":{\"name\":\"hello.txt\"}}") | ||
.when() | ||
.post("http://localhost:8081") | ||
.then() | ||
.statusCode(200); | ||
|
||
// stop the invoker | ||
invoker.stopServer(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
integration-tests/google-cloud-functions/src/main/resources/application.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
quarkus.google-cloud-functions.function=httpTest | ||
#quarkus.google-cloud-functions.function=cloudEventTest | ||
#quarkus.google-cloud-functions.function=rawPubSubTest | ||
#quarkus.google-cloud-functions.function=storageTest | ||
%cloud-event.quarkus.google-cloud-functions.function=cloudEventTest | ||
%raw-background.quarkus.google-cloud-functions.function=rawPubSubTest | ||
%background.quarkus.google-cloud-functions.function=storageTest |
45 changes: 45 additions & 0 deletions
45
...nctions/src/test/java/io/quarkus/gcp/function/test/BackgroundFunctionStorageTestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package io.quarkus.gcp.function.test; | ||
|
||
import static io.restassured.RestAssured.given; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import com.google.cloud.functions.invoker.runner.Invoker; | ||
|
||
import io.quarkus.test.junit.QuarkusTest; | ||
import io.quarkus.test.junit.QuarkusTestProfile; | ||
import io.quarkus.test.junit.TestProfile; | ||
|
||
@QuarkusTest | ||
@TestProfile(BackgroundFunctionStorageTestCase.BackgroundFunctionTestProfile.class) | ||
class BackgroundFunctionStorageTestCase { | ||
@Test | ||
public void test() throws Exception { | ||
// start the invoker without joining to avoid blocking the thread | ||
Invoker invoker = new Invoker( | ||
8081, | ||
"io.quarkus.gcp.functions.QuarkusBackgroundFunction", | ||
"event", | ||
Thread.currentThread().getContextClassLoader()); | ||
invoker.startTestServer(); | ||
|
||
// test the function using RestAssured | ||
given() | ||
.body("{\"data\":{\"name\":\"hello.txt\"}}") | ||
.when() | ||
.post("http://localhost:8081") | ||
.then() | ||
.statusCode(200); | ||
|
||
// stop the invoker | ||
invoker.stopServer(); | ||
} | ||
|
||
public static class BackgroundFunctionTestProfile implements QuarkusTestProfile { | ||
|
||
@Override | ||
public String getConfigProfile() { | ||
return "background"; | ||
} | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
...cloud-functions/src/test/java/io/quarkus/gcp/function/test/CloudEventStorageTestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package io.quarkus.gcp.function.test; | ||
|
||
import static io.restassured.RestAssured.given; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import com.google.cloud.functions.invoker.runner.Invoker; | ||
|
||
import io.quarkus.test.junit.QuarkusTest; | ||
import io.quarkus.test.junit.QuarkusTestProfile; | ||
import io.quarkus.test.junit.TestProfile; | ||
|
||
@QuarkusTest | ||
@TestProfile(CloudEventStorageTestCase.CloudEventFunctionTestProfile.class) | ||
class CloudEventStorageTestCase { | ||
@Test | ||
public void test() throws Exception { | ||
// start the invoker without joining to avoid blocking the thread | ||
Invoker invoker = new Invoker( | ||
8081, | ||
"io.quarkus.gcp.functions.QuarkusCloudEventsFunction", | ||
"cloudevent", | ||
Thread.currentThread().getContextClassLoader()); | ||
invoker.startTestServer(); | ||
|
||
// test the function using RestAssured | ||
given() | ||
.header("ce-specversion", "1.0") | ||
.header("ce-id", "1234567890") | ||
.header("ce-type", "google.cloud.storage.object.v1.finalized") | ||
.header("ce-source", "//storage.googleapis.com/projects/_/buckets/MY-BUCKET-NAME") | ||
.header("ce-subject", "objects/MY_FILE.txt") | ||
.body("{\n" + | ||
" \"bucket\": \"MY_BUCKET\",\n" + | ||
" \"contentType\": \"text/plain\",\n" + | ||
" \"kind\": \"storage#object\",\n" + | ||
" \"md5Hash\": \"...\",\n" + | ||
" \"metageneration\": \"1\",\n" + | ||
" \"name\": \"MY_FILE.txt\",\n" + | ||
" \"size\": \"352\",\n" + | ||
" \"storageClass\": \"MULTI_REGIONAL\",\n" + | ||
" \"timeCreated\": \"2020-04-23T07:38:57.230Z\",\n" + | ||
" \"timeStorageClassUpdated\": \"2020-04-23T07:38:57.230Z\",\n" + | ||
" \"updated\": \"2020-04-23T07:38:57.230Z\"\n" + | ||
" }") | ||
.when() | ||
.post("http://localhost:8081") | ||
.then() | ||
.statusCode(200); | ||
|
||
// stop the invoker | ||
invoker.stopServer(); | ||
} | ||
|
||
public static class CloudEventFunctionTestProfile implements QuarkusTestProfile { | ||
|
||
@Override | ||
public String getConfigProfile() { | ||
return "cloud-event"; | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...ogle-cloud-functions/src/test/java/io/quarkus/gcp/function/test/HttpFunctionTestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package io.quarkus.gcp.function.test; | ||
|
||
import static io.restassured.RestAssured.when; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import com.google.cloud.functions.invoker.runner.Invoker; | ||
|
||
import io.quarkus.test.junit.QuarkusTest; | ||
|
||
@QuarkusTest | ||
class HttpFunctionTestCase { | ||
@Test | ||
public void test() throws Exception { | ||
// start the invoker without joining to avoid blocking the thread | ||
Invoker invoker = new Invoker( | ||
8081, | ||
"io.quarkus.gcp.functions.QuarkusHttpFunction", | ||
"http", | ||
Thread.currentThread().getContextClassLoader()); | ||
invoker.startTestServer(); | ||
|
||
// test the function using RestAssured | ||
when() | ||
.get("http://localhost:8081") | ||
.then() | ||
.statusCode(200) | ||
.body(is("Hello World!")); | ||
|
||
// stop the invoker | ||
invoker.stopServer(); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...tions/src/test/java/io/quarkus/gcp/function/test/RawBackgroundFunctionPubSubTestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package io.quarkus.gcp.function.test; | ||
|
||
import static io.restassured.RestAssured.given; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import com.google.cloud.functions.invoker.runner.Invoker; | ||
|
||
import io.quarkus.test.junit.QuarkusTest; | ||
import io.quarkus.test.junit.QuarkusTestProfile; | ||
import io.quarkus.test.junit.TestProfile; | ||
|
||
@QuarkusTest | ||
@TestProfile(RawBackgroundFunctionPubSubTestCase.RawBackgroundFunctionTestProfile.class) | ||
class RawBackgroundFunctionPubSubTestCase { | ||
@Test | ||
public void test() throws Exception { | ||
// start the invoker without joining to avoid blocking the thread | ||
Invoker invoker = new Invoker( | ||
8081, | ||
"io.quarkus.gcp.functions.QuarkusBackgroundFunction", | ||
"event", | ||
Thread.currentThread().getContextClassLoader()); | ||
invoker.startTestServer(); | ||
|
||
// test the function using RestAssured | ||
given() | ||
.body("{\"data\":{\"name\":\"hello.txt\"}}") | ||
.when() | ||
.post("http://localhost:8081") | ||
.then() | ||
.statusCode(200); | ||
|
||
// stop the invoker | ||
invoker.stopServer(); | ||
} | ||
|
||
public static class RawBackgroundFunctionTestProfile implements QuarkusTestProfile { | ||
|
||
@Override | ||
public String getConfigProfile() { | ||
return "raw-background"; | ||
} | ||
} | ||
} |