kubeshop / kusk-gateway

Kusk-gateway is an OpenAPI-driven API Gateway for Kubernetes
https://kubeshop.github.io/kusk-gateway/
MIT License
253 stars 21 forks source link

Mocking from schema Gateway #1003

Closed mbana closed 1 year ago

mbana commented 1 year ago

Summary

curl -v -H 'Accept: application/json' 192.168.49.2/todos should work.

Changes

examples/mocking/gateway/**

Example of Gateway mocking taken from [2] and added a deployment manifest.

skaffold.yaml, skaffold.sh, Makefile and .vscode/launch.json

Tidy up skaffold.yaml, skaffold.sh and Makefile.

Add .vscode/launch.json that contains debugger configuration for attaching to the manager from within VS Code.

References

1: https://github.com/kubeshop/kusk-gateway/issues/298. 2: https://pastebin.com/raw/avYFtZpX.


Test

$ curl -v -H 'Accept: application/json' 192.168.49.2/todos
*   Trying 192.168.49.2:80...
* Connected to 192.168.49.2 (192.168.49.2) port 80 (#0)
> GET /todos HTTP/1.1
> Host: 192.168.49.2
> User-Agent: curl/7.85.0
> Accept: application/json
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< access-control-allow-origin: *
< access-control-max-age: 86200
< access-control-allow-credentials: true
< x-kusk-mocked: true
< content-type: application/json
< content-length: 86
< date: Tue, 06 Dec 2022 14:06:53 GMT
< server: envoy
< 
* Connection #0 to host 192.168.49.2 left intact
{"completed":true,"order":13,"title":"Mocked JSON title","url":"http://mockedURL.com"}%

$ curl -v -H 'Accept: application/xml' 192.168.49.2/todos                                                        
*   Trying 192.168.49.2:80...
* Connected to 192.168.49.2 (192.168.49.2) port 80 (#0)
> GET /todos HTTP/1.1
> Host: 192.168.49.2
> User-Agent: curl/7.85.0
> Accept: application/xml
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< access-control-allow-origin: *
< access-control-max-age: 86200
< access-control-allow-credentials: true
< x-kusk-mocked: true
< content-type: application/xml
< content-length: 117
< date: Tue, 06 Dec 2022 14:06:58 GMT
< server: envoy
< 
* Connection #0 to host 192.168.49.2 left intact
<doc><completed>true</completed><order>13</order><title>Mocked XML title</title><url>http://mockedURL.com</url></doc>%

$ curl -v -H 'Accept: text/plain' 192.168.49.2/todos      
*   Trying 192.168.49.2:80...
* Connected to 192.168.49.2 (192.168.49.2) port 80 (#0)
> GET /todos HTTP/1.1
> Host: 192.168.49.2
> User-Agent: curl/7.85.0
> Accept: text/plain
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< access-control-allow-origin: *
< access-control-max-age: 86200
< access-control-allow-credentials: true
< x-kusk-mocked: true
< content-type: text/plain
< content-length: 81
< date: Tue, 06 Dec 2022 14:07:04 GMT
< server: envoy
< 
title: "Mocked Text title"
completed: true
order: 13
url: "http://mockedURL.com"
* Connection #0 to host 192.168.49.2 left intact

Signed-off-by: Mohamed Bana mohamed@bana.io

netlify[bot] commented 1 year ago

Deploy Preview for kusk-docs-preview canceled.

Name Link
Latest commit b6116a3545250ec1243cf2dc8e18543c090182c2
Latest deploy log https://app.netlify.com/sites/kusk-docs-preview/deploys/638f4ca6d09d3500088fd8d8