Skip to content

Commit

Permalink
rework example project to use the Kreya example API
Browse files Browse the repository at this point in the history
  • Loading branch information
CommonGuy committed Aug 11, 2023
1 parent 304f0e8 commit f87a9ad
Show file tree
Hide file tree
Showing 52 changed files with 193 additions and 201 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- uses: actions/checkout@v3
- run: kreyac info
- run: kreyac environment list
- run: kreyac environment set-active production
- run: kreyac operation invoke "REST/wttr.in/London.krop" # invoke a single REST operation
- run: kreyac operation invoke "gRPC/Unary call.krop" # invoke a single gRPC operation
- run: kreyac environment set-active Production
- run: kreyac operation invoke "REST/Get books.krop" # invoke a single REST operation
- run: kreyac operation invoke "gRPC/Say hello (unary call).krop" # invoke a single gRPC operation
- run: kreyac operation invoke "Kreya features/Scripting/**" # invoke all scripting operations
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
// A configured authentication can be selected in the "Auth" tab.
// It is also accessible via templating.
// Send the operation and take a look at the "Trace" tab to see the sent authentication value.
"greeting": "{{ auth.configs.myauth.name }}"
// Change the active environment and send the operation again to see the updated value.
"name": "{{ auth.configs.myauth.name }}"
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"details": {
"methodFqn": "hello.HelloService.SayHello"
"methodFqn": "kreya.ExampleService.SayHello"
},
"requests": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"message": "{{ vars.messages ? vars.messages[0] : 'no messages set' }}"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"message": "{{ vars.messages ? vars.messages[1] : 'no messages set' }}"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"message": "{{ vars.messages ? vars.messages[2] : 'no messages set' }}"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { expect } from 'chai';

// Code here runs before the request is sent
const messages = ['first message', 'second message', 'third message'];

// store the messages as a "user variable", which is persisted
kreya.variables.set('messages', messages);

kreyaGrpc.onResponse(msg => {
kreya.test('Should equal the sent message', () => expect(msg.content.message).to.eql(messages[msg.index]));
});

kreyaGrpc.onCallCompleted(call => {
kreya.test('Status should be ok', () => expect(call.status.code).to.equal(0));

kreya.trace(`Got ${call.responseCount} responses`);
kreya.test('Response count should match sent messages', () => expect(call.responseCount).to.eql(messages.length));
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"details": {
"methodFqn": "kreya.ExampleService.Echo"
},
"script": {
"src": "Advanced scripting example.js"
},
"requests": [
{
"location": "Advanced scripting example-request-0.json"
},
{
"location": "Advanced scripting example-request-1.json"
},
{
"location": "Advanced scripting example-request-2.json"
}
],
"operationType": "duplexStreaming",
"invokerName": "grpc",
"importStreamId": "463869a1-4cf8-470d-871d-c873192881c7"
}
7 changes: 2 additions & 5 deletions example-project/Kreya features/Scripting/Scripting REST.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ kreyaRest.onCallCompleted(call => {

kreya.test('Content type', () => expect(call.response.contentType).to.eq('application/json'));

const curlyBraceCharCode = '{'.charCodeAt(0);
kreya.test('Byte content first entry should be a curly brace', () => expect(call.response.rawContentBytes[0]).to.eq(curlyBraceCharCode));
kreya.test('Text content first char should be a curly brace', () => expect(call.response.rawContentText[0]).to.eq('{'));

kreya.test('Deserialized method should equal', () => expect(call.response.content.method).to.eq('GET'));
const books = call.response.content;
kreya.test('First book should have ID 1', () => expect(books[0].id).to.eq(1));
});
6 changes: 4 additions & 2 deletions example-project/Kreya features/Scripting/Scripting REST.krop
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"details": {
"path": "/anything",
"method": "GET"
"path": "/v1/books",
"method": "GET",
"headers": [],
"pathParams": []
},
"script": {
"src": "Scripting REST.js"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"greeting": "fooBar"
"name": "fooBar"
}
13 changes: 1 addition & 12 deletions example-project/Kreya features/Scripting/Scripting gRPC.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
import { expect } from 'chai';

let names = [];

kreyaGrpc.onResponse(msg => {
kreya.test('Size should be ok', () => expect(msg.size).to.be.gt(10));
kreya.test('Greeting should start with hello', () => expect(msg.content.reply.startsWith('hello')).to.be.true);

// Store all received names to use them when the gRPC call completes
names.push(msg.content.reply.substr('Hello '.length));
});

kreyaGrpc.onCallCompleted(call => {
kreya.test('Status should be ok', () => expect(call.status.code).to.equal(0));

kreya.trace(`Got ${call.responseCount} names: ${names.join(', ')}`);
kreya.test('Message should start with Hello', () => expect(msg.content.message.startsWith('Hello')).to.be.true);
});
5 changes: 3 additions & 2 deletions example-project/Kreya features/Scripting/Scripting gRPC.krop
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"details": {
"methodFqn": "hello.HelloService.SayHello"
"methodFqn": "kreya.ExampleService.SayHello"
},
"script": {
"src": "Scripting gRPC.js"
Expand All @@ -11,5 +11,6 @@
}
],
"operationType": "unary",
"invokerName": "grpc"
"invokerName": "grpc",
"importStreamId": "463869a1-4cf8-470d-871d-c873192881c7"
}
3 changes: 3 additions & 0 deletions example-project/REST/Create book-request.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "{{ faker.commerce.product_name }}"
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"details": {
"path": "/anything",
"path": "/v1/books",
"method": "POST",
"importedOperationId": "POST /v1/books",
"headers": [
{
"key": "Content-Type",
Expand All @@ -12,11 +13,12 @@
},
"requests": [
{
"location": "POST-request.json",
"location": "Create book-request.json",
"contentType": "json"
}
],
"operationType": "unary",
"invokerName": "rest",
"typeHint": "POST"
"typeHint": "POST",
"importStreamId": "3173a966-56b1-435f-9a60-937058ec6c80"
}
15 changes: 0 additions & 15 deletions example-project/REST/DELETE.krop

This file was deleted.

23 changes: 23 additions & 0 deletions example-project/REST/Delete book.krop
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"details": {
"path": "/v1/books/{id}",
"method": "DELETE",
"importedOperationId": "DELETE /v1/books/{id}",
"headers": [],
"pathParams": [
{
"key": "id",
"value": "1"
}
]
},
"requests": [
{
"contentType": "none"
}
],
"operationType": "unary",
"invokerName": "rest",
"typeHint": "DELETE",
"importStreamId": "3173a966-56b1-435f-9a60-937058ec6c80"
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"details": {
"path": "/status/{code}",
"path": "/v1/books/{id}",
"method": "GET",
"importedOperationId": "GET /v1/books/{id}",
"headers": [],
"pathParams": [
{
"key": "code",
"value": "418"
"key": "id",
"value": "1"
}
]
},
Expand All @@ -17,5 +18,6 @@
],
"operationType": "unary",
"invokerName": "rest",
"typeHint": "GET"
"typeHint": "GET",
"importStreamId": "3173a966-56b1-435f-9a60-937058ec6c80"
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{
"details": {
"path": "/anything",
"path": "/v1/books",
"method": "GET",
"importedOperationId": "GET /anything (cfe3f74c-0483-41e5-85d3-36c85f25e8bb)",
"headers": []
"importedOperationId": "GET /v1/books"
},
"requests": [
{
Expand All @@ -12,5 +11,6 @@
],
"operationType": "unary",
"invokerName": "rest",
"typeHint": "GET"
"typeHint": "GET",
"importStreamId": "3173a966-56b1-435f-9a60-937058ec6c80"
}
24 changes: 0 additions & 24 deletions example-project/REST/PATCH.krop

This file was deleted.

3 changes: 0 additions & 3 deletions example-project/REST/POST-request.json

This file was deleted.

3 changes: 0 additions & 3 deletions example-project/REST/PUT-request.json

This file was deleted.

3 changes: 3 additions & 0 deletions example-project/REST/Update book-request.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "{{ faker.commerce.product_name }}"
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
{
"details": {
"path": "/anything",
"path": "/v1/books/{id}",
"method": "PUT",
"importedOperationId": "PUT /anything",
"importedOperationId": "PUT /v1/books/{id}",
"headers": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"pathParams": []
"pathParams": [
{
"key": "id",
"value": "3"
}
]
},
"requests": [
{
"location": "PUT-request.json",
"location": "Update book-request.json",
"contentType": "json"
}
],
"operationType": "unary",
"invokerName": "rest",
"typeHint": "PUT",
"importStreamId": "cfe3f74c-0483-41e5-85d3-36c85f25e8bb"
"importStreamId": "3173a966-56b1-435f-9a60-937058ec6c80"
}
14 changes: 0 additions & 14 deletions example-project/REST/wttr.in/London.krop

This file was deleted.

14 changes: 0 additions & 14 deletions example-project/REST/wttr.in/Moon.krop

This file was deleted.

11 changes: 0 additions & 11 deletions example-project/REST/wttr.in/directory.krpref

This file was deleted.

Loading

0 comments on commit f87a9ad

Please sign in to comment.