Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cherry-pick #12085 #12115 (add binary mode to in-cluster eventing test) #12113

Merged
merged 3 commits into from
Sep 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/fast-integration/test/2-commerce-mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe("CommerceMock tests", function () {
});
});

it("in-cluster event should be delivered", async function () {
it("in-cluster event should be delivered (structured and binary mode)", async function () {
await checkInClusterEventDelivery(testNamespace);
});

Expand Down
12 changes: 8 additions & 4 deletions tests/fast-integration/test/fixtures/commerce-mock/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,6 @@ function cleanMockTestFixture(mockNamespace, targetNamespace, wait = true) {
}

async function deleteMockTestFixture(targetNamespace) {

const serviceBindingUsage = {
apiVersion: "servicecatalog.kyma-project.io/v1alpha1",
kind: "ServiceBindingUsage",
Expand All @@ -480,13 +479,18 @@ async function deleteMockTestFixture(targetNamespace) {
await k8sDelete(applicationObjs)
}

async function checkInClusterEventDelivery(targetNamespace){
const eventId = "event-"+genRandom(5);
async function checkInClusterEventDelivery(targetNamespace) {
await checkInClusterEventDeliveryHelper(targetNamespace, 'structured');
await checkInClusterEventDeliveryHelper(targetNamespace, 'binary');
}

async function checkInClusterEventDeliveryHelper(targetNamespace, encoding) {
const eventId = "event-" + genRandom(5);
const vs = await waitForVirtualService(targetNamespace, "lastorder");
const mockHost = vs.spec.hosts[0];

// send event using function query parameter send=true
await retryPromise(() => axios.post(`https://${mockHost}`, { id: eventId }, {params:{send:true}}), 10, 1000)
await retryPromise(() => axios.post(`https://${mockHost}`, { id: eventId }, { params: { send: true, encoding: encoding } }), 10, 1000)
// verify if event was received using function query parameter inappevent=eventId
await retryPromise(async () => {
debug("Waiting for event: ",eventId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,41 @@ spec:
let lastEvent = {};
let inAppEvent = {};
const axios = require('axios');
function sendEvent(type, data) {
const payload = {
source: "kyma",
function sendEvent(type, data, encoding) {
const event = getEventPayloadAndHeaders(type, data, encoding)
console.log("Headers:", event.headers)
console.log("Payload:", event.payload)
return axios.post("http://eventing-event-publisher-proxy.kyma-system/publish",event.payload,{headers:event.headers})
}
function getEventPayloadAndHeaders(type, data, encoding) {
if(encoding==='binary') {
return {
payload: data,
headers: {
"ce-source": "/default/sap.kyma/tunas-prow",
"ce-specversion": "1.0",
"ce-eventtypeversion": "v1",
"ce-id": (data.id || "dummyId"),
"ce-type": type,
"Content-Type": "application/json"
}
}
}
// structured encoding
return {
payload: {
source: "/default/sap.kyma/tunas-prow",
specversion: "1.0",
eventtypeversion: "v1",
datacontenttype: "application/json",
id: (data.id || "dummyId"),
type,
data
},
headers: {
"Content-Type": "application/cloudevents+json"
}
console.log("Payload:", payload)
return axios.post("http://eventing-event-publisher-proxy.kyma-system/publish",payload,{headers:{"Content-Type": "application/cloudevents+json"}})
}
}
async function getOrder(code) {
let url = %%URL%%;
Expand Down Expand Up @@ -59,7 +82,8 @@ spec:
main: async function (event, context) {
if (event.extensions.request.query.send) {
try {
const response = await sendEvent("sap.kyma.custom.inapp.order.received.v1", event.data);
const encoding = event.extensions.request.query.encoding
const response = await sendEvent("sap.kyma.custom.inapp.order.received.v1", event.data, encoding);
console.log("In-app message sent");
} catch (e) {
console.dir(e)
Expand Down