Skip to content

Commit

Permalink
Add Google Cloud Functions integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
loicmathieu committed Aug 31, 2022
1 parent 7e0ba16 commit 232ff0e
Show file tree
Hide file tree
Showing 11 changed files with 355 additions and 8 deletions.
11 changes: 9 additions & 2 deletions integration-tests/funqy-google-cloud-functions/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,22 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-funqy-google-cloud-functions</artifactId>
</dependency>

<!-- test dependencies -->
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5-internal</artifactId>
<groupId>com.google.cloud.functions.invoker</groupId>
<artifactId>java-function-invoker</artifactId>
<version>${gcf-invoker.version}</version>
<scope>test</scope>
</dependency>

Expand Down
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
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";
}
}
}
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";
}
}
}
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();
}
}
12 changes: 12 additions & 0 deletions integration-tests/google-cloud-functions/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,24 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-google-cloud-functions</artifactId>
</dependency>

<!-- test dependencies -->
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.cloud.functions.invoker</groupId>
<artifactId>java-function-invoker</artifactId>
<version>${gcf-invoker.version}</version>
<scope>test</scope>
</dependency>

<!-- Minimal test dependencies to *-deployment artifacts for consistent build order -->
<dependency>
Expand Down
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
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";
}
}
}
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";
}
}
}
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();
}
}
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";
}
}
}

0 comments on commit 232ff0e

Please sign in to comment.