From f514d86b0a7fc027e94dc80767e091780d7326ef Mon Sep 17 00:00:00 2001 From: Asish Kumar Date: Thu, 26 Mar 2026 13:04:14 +0000 Subject: [PATCH] feat: add test sets for SSE port, protocol config, and port mapping - Add /ping endpoint on HTTP mux and new ping server on :8050 - SKIP_PING_SERVER env var to disable ping server for port mapping CI tests - Record port-config-test: mixed HTTP (:8000) + SSE (:8047) requests - Record port-mapping-test: requests to :8050 for port mapping validation - Update keploy.yml with ssePort, protocol config, and per-test-set port mapping --- http-sse/keploy.yml | 13 ++- .../keploy/port-config-test/tests/test-1.yaml | 41 +++++++ .../keploy/port-config-test/tests/test-2.yaml | 41 +++++++ .../keploy/port-config-test/tests/test-3.yaml | 41 +++++++ .../keploy/port-config-test/tests/test-4.yaml | 43 +++++++ .../keploy/port-config-test/tests/test-5.yaml | 44 +++++++ .../keploy/port-config-test/tests/test-6.yaml | 41 +++++++ .../keploy/port-config-test/tests/test-7.yaml | 108 ++++++++++++++++++ .../keploy/port-config-test/tests/test-8.yaml | 108 ++++++++++++++++++ .../port-mapping-test/tests/test-1.yaml | 41 +++++++ .../port-mapping-test/tests/test-2.yaml | 41 +++++++ .../port-mapping-test/tests/test-3.yaml | 41 +++++++ .../port-mapping-test/tests/test-4.yaml | 41 +++++++ .../port-mapping-test/tests/test-5.yaml | 41 +++++++ http-sse/main.go | 48 ++++++++ 15 files changed, 731 insertions(+), 2 deletions(-) create mode 100755 http-sse/keploy/port-config-test/tests/test-1.yaml create mode 100755 http-sse/keploy/port-config-test/tests/test-2.yaml create mode 100755 http-sse/keploy/port-config-test/tests/test-3.yaml create mode 100755 http-sse/keploy/port-config-test/tests/test-4.yaml create mode 100755 http-sse/keploy/port-config-test/tests/test-5.yaml create mode 100755 http-sse/keploy/port-config-test/tests/test-6.yaml create mode 100755 http-sse/keploy/port-config-test/tests/test-7.yaml create mode 100755 http-sse/keploy/port-config-test/tests/test-8.yaml create mode 100755 http-sse/keploy/port-mapping-test/tests/test-1.yaml create mode 100755 http-sse/keploy/port-mapping-test/tests/test-2.yaml create mode 100755 http-sse/keploy/port-mapping-test/tests/test-3.yaml create mode 100755 http-sse/keploy/port-mapping-test/tests/test-4.yaml create mode 100755 http-sse/keploy/port-mapping-test/tests/test-5.yaml diff --git a/http-sse/keploy.yml b/http-sse/keploy.yml index 2c593d26..cdd6b968 100755 --- a/http-sse/keploy.yml +++ b/http-sse/keploy.yml @@ -33,13 +33,22 @@ test: url: "localhost:8003": "localhost:8000" "localhost:8004": "localhost:8000" - sse: - url: + sse: + url: "doubt.local": "localhost:8047" + port-mapping-test: + port: + 8050: 8000 delay: 5 host: "" port: 0 grpcPort: 0 + ssePort: 8047 + protocol: + http: + port: 8000 + sse: + port: 8047 apiTimeout: 5 skipCoverage: false coverageReportPath: "" diff --git a/http-sse/keploy/port-config-test/tests/test-1.yaml b/http-sse/keploy/port-config-test/tests/test-1.yaml new file mode 100755 index 00000000..7aa99cb8 --- /dev/null +++ b/http-sse/keploy/port-config-test/tests/test-1.yaml @@ -0,0 +1,41 @@ +# Generated by Keploy (3-dev) +version: api.keploy.io/v1beta1 +kind: Http +name: test-1 +spec: + metadata: {} + req: + method: GET + proto_major: 1 + proto_minor: 1 + url: http://localhost:8000/health + header: + Accept: '*/*' + Host: localhost:8000 + User-Agent: curl/8.5.0 + body: "" + timestamp: 2026-03-26T12:50:44.335119622Z + resp: + status_code: 200 + header: + Content-Length: "24" + Content-Type: application/json + Date: Thu, 26 Mar 2026 12:50:44 GMT + body: | + {"ok":true,"port":8000} + status_message: OK + proto_major: 0 + proto_minor: 0 + timestamp: 2026-03-26T12:50:44.335453935Z + objects: [] + assertions: + noise: + header.Date: [] + created: 1774529444 + app_port: 8000 +curl: | + curl --request GET \ + --url http://localhost:8000/health \ + --header 'Accept: */*' \ + --header 'Host: localhost:8000' \ + --header 'User-Agent: curl/8.5.0' \ diff --git a/http-sse/keploy/port-config-test/tests/test-2.yaml b/http-sse/keploy/port-config-test/tests/test-2.yaml new file mode 100755 index 00000000..c4fd039e --- /dev/null +++ b/http-sse/keploy/port-config-test/tests/test-2.yaml @@ -0,0 +1,41 @@ +# Generated by Keploy (3-dev) +version: api.keploy.io/v1beta1 +kind: Http +name: test-2 +spec: + metadata: {} + req: + method: GET + proto_major: 1 + proto_minor: 1 + url: http://localhost:8000/health + header: + Accept: '*/*' + Host: localhost:8000 + User-Agent: curl/8.5.0 + body: "" + timestamp: 2026-03-26T12:50:47.341688677Z + resp: + status_code: 200 + header: + Content-Length: "24" + Content-Type: application/json + Date: Thu, 26 Mar 2026 12:50:47 GMT + body: | + {"ok":true,"port":8000} + status_message: OK + proto_major: 0 + proto_minor: 0 + timestamp: 2026-03-26T12:50:47.341870089Z + objects: [] + assertions: + noise: + header.Date: [] + created: 1774529447 + app_port: 8000 +curl: | + curl --request GET \ + --url http://localhost:8000/health \ + --header 'User-Agent: curl/8.5.0' \ + --header 'Accept: */*' \ + --header 'Host: localhost:8000' \ diff --git a/http-sse/keploy/port-config-test/tests/test-3.yaml b/http-sse/keploy/port-config-test/tests/test-3.yaml new file mode 100755 index 00000000..c0003d74 --- /dev/null +++ b/http-sse/keploy/port-config-test/tests/test-3.yaml @@ -0,0 +1,41 @@ +# Generated by Keploy (3-dev) +version: api.keploy.io/v1beta1 +kind: Http +name: test-3 +spec: + metadata: {} + req: + method: GET + proto_major: 1 + proto_minor: 1 + url: http://localhost:8000/api/hello + header: + Accept: '*/*' + Host: localhost:8000 + User-Agent: curl/8.5.0 + body: "" + timestamp: 2026-03-26T12:50:48.346822466Z + resp: + status_code: 200 + header: + Content-Length: "38" + Content-Type: application/json + Date: Thu, 26 Mar 2026 12:50:48 GMT + body: | + {"msg":"hello from http","port":8000} + status_message: OK + proto_major: 0 + proto_minor: 0 + timestamp: 2026-03-26T12:50:48.347062708Z + objects: [] + assertions: + noise: + header.Date: [] + created: 1774529448 + app_port: 8000 +curl: | + curl --request GET \ + --url http://localhost:8000/api/hello \ + --header 'Host: localhost:8000' \ + --header 'User-Agent: curl/8.5.0' \ + --header 'Accept: */*' \ diff --git a/http-sse/keploy/port-config-test/tests/test-4.yaml b/http-sse/keploy/port-config-test/tests/test-4.yaml new file mode 100755 index 00000000..51b664f4 --- /dev/null +++ b/http-sse/keploy/port-config-test/tests/test-4.yaml @@ -0,0 +1,43 @@ +# Generated by Keploy (3-dev) +version: api.keploy.io/v1beta1 +kind: Http +name: test-4 +spec: + metadata: {} + req: + method: GET + proto_major: 1 + proto_minor: 1 + url: http://localhost:8000/api/echo?msg=porttest + url_params: + msg: porttest + header: + Accept: '*/*' + Host: localhost:8000 + User-Agent: curl/8.5.0 + body: "" + timestamp: 2026-03-26T12:50:49.352282873Z + resp: + status_code: 200 + header: + Content-Length: "32" + Content-Type: application/json + Date: Thu, 26 Mar 2026 12:50:49 GMT + body: | + {"echo":"porttest","port":8000} + status_message: OK + proto_major: 0 + proto_minor: 0 + timestamp: 2026-03-26T12:50:49.352454614Z + objects: [] + assertions: + noise: + header.Date: [] + created: 1774529449 + app_port: 8000 +curl: | + curl --request GET \ + --url http://localhost:8000/api/echo?msg=porttest \ + --header 'User-Agent: curl/8.5.0' \ + --header 'Accept: */*' \ + --header 'Host: localhost:8000' \ diff --git a/http-sse/keploy/port-config-test/tests/test-5.yaml b/http-sse/keploy/port-config-test/tests/test-5.yaml new file mode 100755 index 00000000..36ff6f70 --- /dev/null +++ b/http-sse/keploy/port-config-test/tests/test-5.yaml @@ -0,0 +1,44 @@ +# Generated by Keploy (3-dev) +version: api.keploy.io/v1beta1 +kind: Http +name: test-5 +spec: + metadata: {} + req: + method: GET + proto_major: 1 + proto_minor: 1 + url: http://localhost:8000/api/add?a=10&b=20 + url_params: + a: "10" + b: "20" + header: + Accept: '*/*' + Host: localhost:8000 + User-Agent: curl/8.5.0 + body: "" + timestamp: 2026-03-26T12:50:50.358125729Z + resp: + status_code: 200 + header: + Content-Length: "37" + Content-Type: application/json + Date: Thu, 26 Mar 2026 12:50:50 GMT + body: | + {"a":10,"b":20,"port":8000,"sum":30} + status_message: OK + proto_major: 0 + proto_minor: 0 + timestamp: 2026-03-26T12:50:50.358338811Z + objects: [] + assertions: + noise: + header.Date: [] + created: 1774529450 + app_port: 8000 +curl: | + curl --request GET \ + --url http://localhost:8000/api/add?a=10&b=20 \ + --header 'Accept: */*' \ + --header 'Host: localhost:8000' \ + --header 'User-Agent: curl/8.5.0' \ diff --git a/http-sse/keploy/port-config-test/tests/test-6.yaml b/http-sse/keploy/port-config-test/tests/test-6.yaml new file mode 100755 index 00000000..9c1b6fd8 --- /dev/null +++ b/http-sse/keploy/port-config-test/tests/test-6.yaml @@ -0,0 +1,41 @@ +# Generated by Keploy (3-dev) +version: api.keploy.io/v1beta1 +kind: Http +name: test-6 +spec: + metadata: {} + req: + method: GET + proto_major: 1 + proto_minor: 1 + url: http://localhost:8000/api/resource/99 + header: + Accept: '*/*' + Host: localhost:8000 + User-Agent: curl/8.5.0 + body: "" + timestamp: 2026-03-26T12:50:51.363736261Z + resp: + status_code: 200 + header: + Content-Length: "51" + Content-Type: application/json + Date: Thu, 26 Mar 2026 12:50:51 GMT + body: | + {"fixed":true,"id":"99","port":8000,"type":"demo"} + status_message: OK + proto_major: 0 + proto_minor: 0 + timestamp: 2026-03-26T12:50:51.363948263Z + objects: [] + assertions: + noise: + header.Date: [] + created: 1774529451 + app_port: 8000 +curl: | + curl --request GET \ + --url http://localhost:8000/api/resource/99 \ + --header 'Accept: */*' \ + --header 'Host: localhost:8000' \ + --header 'User-Agent: curl/8.5.0' \ diff --git a/http-sse/keploy/port-config-test/tests/test-7.yaml b/http-sse/keploy/port-config-test/tests/test-7.yaml new file mode 100755 index 00000000..a104a39f --- /dev/null +++ b/http-sse/keploy/port-config-test/tests/test-7.yaml @@ -0,0 +1,108 @@ +# Generated by Keploy (3-dev) +version: api.keploy.io/v1beta1 +kind: Http +name: test-7 +spec: + metadata: {} + req: + method: GET + proto_major: 1 + proto_minor: 1 + url: http://localhost:8047/subscribe/student/events?doubtId=port-test-1 + url_params: + doubtId: port-test-1 + header: + Accept: text/event-stream + Host: localhost:8047 + User-Agent: curl/8.5.0 + body: "" + timestamp: 2026-03-26T12:50:52.371652738Z + resp: + status_code: 200 + header: + Access-Control-Allow-Origin: '*' + Cache-Control: no-cache + Connection: keep-alive + Content-Type: text/event-stream; charset=utf-8 + Date: Thu, 26 Mar 2026 12:50:52 GMT + body: + - ts: "2026-03-26T12:50:52.371930021Z" + data: + event: TICKER + data: '[{"message_id":"ticker-1","message_type":"TICKER","message":{"id":"port-test-1","kind":"student","timestamp":1774529452371}}]' + - ts: "2026-03-26T12:50:52.371930021Z" + data: + event: message + data: '[{"message_id":"msg-1","message_type":"SYSTEM","message":{"timestamp":1774529453375,"title":"student stream message 1"}}]' + - ts: "2026-03-26T12:50:52.371930021Z" + data: + event: message + data: '[{"message_id":"msg-2","message_type":"SYSTEM","message":{"timestamp":1774529454379,"title":"student stream message 2"}}]' + - ts: "2026-03-26T12:50:52.371930021Z" + data: + event: message + data: '[{"message_id":"msg-3","message_type":"SYSTEM","message":{"timestamp":1774529455383,"title":"student stream message 3"}}]' + - ts: "2026-03-26T12:50:52.371930021Z" + data: + event: message + data: '[{"message_id":"msg-4","message_type":"SYSTEM","message":{"timestamp":1774529456385,"title":"student stream message 4"}}]' + - ts: "2026-03-26T12:50:52.371930021Z" + data: + event: message + data: '[{"message_id":"msg-5","message_type":"SYSTEM","message":{"timestamp":1774529457388,"title":"student stream message 5"}}]' + - ts: "2026-03-26T12:50:52.371930021Z" + data: + event: message + data: '[{"message_id":"msg-6","message_type":"SYSTEM","message":{"timestamp":1774529458394,"title":"student stream message 6"}}]' + - ts: "2026-03-26T12:50:52.371930021Z" + data: + event: message + data: '[{"message_id":"msg-7","message_type":"SYSTEM","message":{"timestamp":1774529459397,"title":"student stream message 7"}}]' + - ts: "2026-03-26T12:50:52.371930021Z" + data: + event: message + data: '[{"message_id":"msg-8","message_type":"SYSTEM","message":{"timestamp":1774529460401,"title":"student stream message 8"}}]' + - ts: "2026-03-26T12:50:52.371930021Z" + data: + event: message + data: '[{"message_id":"msg-9","message_type":"SYSTEM","message":{"timestamp":1774529461405,"title":"student stream message 9"}}]' + - ts: "2026-03-26T12:50:52.371930021Z" + data: + event: message + data: '[{"message_id":"msg-10","message_type":"SYSTEM","message":{"timestamp":1774529462406,"title":"student stream message 10"}}]' + - ts: "2026-03-26T12:50:52.371930021Z" + data: + event: message + data: '[{"message_id":"msg-11","message_type":"SYSTEM","message":{"timestamp":1774529463406,"title":"student stream message 11"}}]' + - ts: "2026-03-26T12:50:52.371930021Z" + data: + event: message + data: '[{"message_id":"msg-12","message_type":"SYSTEM","message":{"timestamp":1774529464407,"title":"student stream message 12"}}]' + - ts: "2026-03-26T12:50:52.371930021Z" + data: + event: message + data: '[{"message_id":"msg-13","message_type":"SYSTEM","message":{"timestamp":1774529465410,"title":"student stream message 13"}}]' + - ts: "2026-03-26T12:50:52.371930021Z" + data: + event: message + data: '[{"message_id":"msg-14","message_type":"SYSTEM","message":{"timestamp":1774529466414,"title":"student stream message 14"}}]' + - ts: "2026-03-26T12:50:52.371930021Z" + data: + event: message + data: '[{"message_id":"msg-15","message_type":"SYSTEM","message":{"timestamp":1774529467417,"title":"student stream message 15"}}]' + status_message: OK + proto_major: 0 + proto_minor: 0 + timestamp: 2026-03-26T12:50:52.371930021Z + objects: [] + assertions: + noise: + header.Date: [] + created: 1774529467 + app_port: 8047 +curl: | + curl --request GET \ + --url http://localhost:8047/subscribe/student/events?doubtId=port-test-1 \ + --header 'Accept: text/event-stream' \ + --header 'Host: localhost:8047' \ + --header 'User-Agent: curl/8.5.0' \ diff --git a/http-sse/keploy/port-config-test/tests/test-8.yaml b/http-sse/keploy/port-config-test/tests/test-8.yaml new file mode 100755 index 00000000..df668edd --- /dev/null +++ b/http-sse/keploy/port-config-test/tests/test-8.yaml @@ -0,0 +1,108 @@ +# Generated by Keploy (3-dev) +version: api.keploy.io/v1beta1 +kind: Http +name: test-8 +spec: + metadata: {} + req: + method: GET + proto_major: 1 + proto_minor: 1 + url: http://localhost:8047/subscribe/teacher/events?teacherId=port-teacher-1 + url_params: + teacherId: port-teacher-1 + header: + Accept: text/event-stream + Host: localhost:8047 + User-Agent: curl/8.5.0 + body: "" + timestamp: 2026-03-26T12:51:07.42420322Z + resp: + status_code: 200 + header: + Access-Control-Allow-Origin: '*' + Cache-Control: no-cache + Connection: keep-alive + Content-Type: text/event-stream; charset=utf-8 + Date: Thu, 26 Mar 2026 12:51:07 GMT + body: + - ts: "2026-03-26T12:51:07.424526182Z" + data: + event: TICKER + data: '[{"message_id":"ticker-1","message_type":"TICKER","message":{"id":"port-teacher-1","kind":"teacher","timestamp":1774529467424}}]' + - ts: "2026-03-26T12:51:07.424526182Z" + data: + event: message + data: '[{"message_id":"msg-1","message_type":"SYSTEM","message":{"timestamp":1774529468428,"title":"teacher stream message 1"}}]' + - ts: "2026-03-26T12:51:07.424526182Z" + data: + event: message + data: '[{"message_id":"msg-2","message_type":"SYSTEM","message":{"timestamp":1774529469432,"title":"teacher stream message 2"}}]' + - ts: "2026-03-26T12:51:07.424526182Z" + data: + event: message + data: '[{"message_id":"msg-3","message_type":"SYSTEM","message":{"timestamp":1774529470435,"title":"teacher stream message 3"}}]' + - ts: "2026-03-26T12:51:07.424526182Z" + data: + event: message + data: '[{"message_id":"msg-4","message_type":"SYSTEM","message":{"timestamp":1774529471438,"title":"teacher stream message 4"}}]' + - ts: "2026-03-26T12:51:07.424526182Z" + data: + event: message + data: '[{"message_id":"msg-5","message_type":"SYSTEM","message":{"timestamp":1774529472440,"title":"teacher stream message 5"}}]' + - ts: "2026-03-26T12:51:07.424526182Z" + data: + event: message + data: '[{"message_id":"msg-6","message_type":"SYSTEM","message":{"timestamp":1774529473441,"title":"teacher stream message 6"}}]' + - ts: "2026-03-26T12:51:07.424526182Z" + data: + event: message + data: '[{"message_id":"msg-7","message_type":"SYSTEM","message":{"timestamp":1774529474442,"title":"teacher stream message 7"}}]' + - ts: "2026-03-26T12:51:07.424526182Z" + data: + event: message + data: '[{"message_id":"msg-8","message_type":"SYSTEM","message":{"timestamp":1774529475446,"title":"teacher stream message 8"}}]' + - ts: "2026-03-26T12:51:07.424526182Z" + data: + event: message + data: '[{"message_id":"msg-9","message_type":"SYSTEM","message":{"timestamp":1774529476448,"title":"teacher stream message 9"}}]' + - ts: "2026-03-26T12:51:07.424526182Z" + data: + event: message + data: '[{"message_id":"msg-10","message_type":"SYSTEM","message":{"timestamp":1774529477451,"title":"teacher stream message 10"}}]' + - ts: "2026-03-26T12:51:07.424526182Z" + data: + event: message + data: '[{"message_id":"msg-11","message_type":"SYSTEM","message":{"timestamp":1774529478455,"title":"teacher stream message 11"}}]' + - ts: "2026-03-26T12:51:07.424526182Z" + data: + event: message + data: '[{"message_id":"msg-12","message_type":"SYSTEM","message":{"timestamp":1774529479459,"title":"teacher stream message 12"}}]' + - ts: "2026-03-26T12:51:07.424526182Z" + data: + event: message + data: '[{"message_id":"msg-13","message_type":"SYSTEM","message":{"timestamp":1774529480463,"title":"teacher stream message 13"}}]' + - ts: "2026-03-26T12:51:07.424526182Z" + data: + event: message + data: '[{"message_id":"msg-14","message_type":"SYSTEM","message":{"timestamp":1774529481467,"title":"teacher stream message 14"}}]' + - ts: "2026-03-26T12:51:07.424526182Z" + data: + event: message + data: '[{"message_id":"msg-15","message_type":"SYSTEM","message":{"timestamp":1774529482468,"title":"teacher stream message 15"}}]' + status_message: OK + proto_major: 0 + proto_minor: 0 + timestamp: 2026-03-26T12:51:07.424526182Z + objects: [] + assertions: + noise: + header.Date: [] + created: 1774529482 + app_port: 8047 +curl: | + curl --request GET \ + --url http://localhost:8047/subscribe/teacher/events?teacherId=port-teacher-1 \ + --header 'Accept: text/event-stream' \ + --header 'Host: localhost:8047' \ + --header 'User-Agent: curl/8.5.0' \ diff --git a/http-sse/keploy/port-mapping-test/tests/test-1.yaml b/http-sse/keploy/port-mapping-test/tests/test-1.yaml new file mode 100755 index 00000000..c0b4d968 --- /dev/null +++ b/http-sse/keploy/port-mapping-test/tests/test-1.yaml @@ -0,0 +1,41 @@ +# Generated by Keploy (3-dev) +version: api.keploy.io/v1beta1 +kind: Http +name: test-1 +spec: + metadata: {} + req: + method: GET + proto_major: 1 + proto_minor: 1 + url: http://localhost:8000/health + header: + Accept: '*/*' + Host: localhost:8000 + User-Agent: curl/8.5.0 + body: "" + timestamp: 2026-03-26T12:53:26.646172861Z + resp: + status_code: 200 + header: + Content-Length: "24" + Content-Type: application/json + Date: Thu, 26 Mar 2026 12:53:26 GMT + body: | + {"ok":true,"port":8000} + status_message: OK + proto_major: 0 + proto_minor: 0 + timestamp: 2026-03-26T12:53:26.646392743Z + objects: [] + assertions: + noise: + header.Date: [] + created: 1774529606 + app_port: 8000 +curl: | + curl --request GET \ + --url http://localhost:8000/health \ + --header 'Host: localhost:8000' \ + --header 'User-Agent: curl/8.5.0' \ + --header 'Accept: */*' \ diff --git a/http-sse/keploy/port-mapping-test/tests/test-2.yaml b/http-sse/keploy/port-mapping-test/tests/test-2.yaml new file mode 100755 index 00000000..49bf41f9 --- /dev/null +++ b/http-sse/keploy/port-mapping-test/tests/test-2.yaml @@ -0,0 +1,41 @@ +# Generated by Keploy (3-dev) +version: api.keploy.io/v1beta1 +kind: Http +name: test-2 +spec: + metadata: {} + req: + method: GET + proto_major: 1 + proto_minor: 1 + url: http://localhost:8050/ping + header: + Accept: '*/*' + Host: localhost:8050 + User-Agent: curl/8.5.0 + body: "" + timestamp: 2026-03-26T12:53:29.656869203Z + resp: + status_code: 200 + header: + Content-Length: "28" + Content-Type: application/json + Date: Thu, 26 Mar 2026 12:53:29 GMT + body: | + {"from":"http","pong":true} + status_message: OK + proto_major: 0 + proto_minor: 0 + timestamp: 2026-03-26T12:53:29.657073965Z + objects: [] + assertions: + noise: + header.Date: [] + created: 1774529609 + app_port: 8050 +curl: | + curl --request GET \ + --url http://localhost:8050/ping \ + --header 'Accept: */*' \ + --header 'Host: localhost:8050' \ + --header 'User-Agent: curl/8.5.0' \ diff --git a/http-sse/keploy/port-mapping-test/tests/test-3.yaml b/http-sse/keploy/port-mapping-test/tests/test-3.yaml new file mode 100755 index 00000000..9e52e528 --- /dev/null +++ b/http-sse/keploy/port-mapping-test/tests/test-3.yaml @@ -0,0 +1,41 @@ +# Generated by Keploy (3-dev) +version: api.keploy.io/v1beta1 +kind: Http +name: test-3 +spec: + metadata: {} + req: + method: GET + proto_major: 1 + proto_minor: 1 + url: http://localhost:8050/ping + header: + Accept: '*/*' + Host: localhost:8050 + User-Agent: curl/8.5.0 + body: "" + timestamp: 2026-03-26T12:53:30.663336338Z + resp: + status_code: 200 + header: + Content-Length: "28" + Content-Type: application/json + Date: Thu, 26 Mar 2026 12:53:30 GMT + body: | + {"from":"http","pong":true} + status_message: OK + proto_major: 0 + proto_minor: 0 + timestamp: 2026-03-26T12:53:30.6635649Z + objects: [] + assertions: + noise: + header.Date: [] + created: 1774529610 + app_port: 8050 +curl: | + curl --request GET \ + --url http://localhost:8050/ping \ + --header 'User-Agent: curl/8.5.0' \ + --header 'Accept: */*' \ + --header 'Host: localhost:8050' \ diff --git a/http-sse/keploy/port-mapping-test/tests/test-4.yaml b/http-sse/keploy/port-mapping-test/tests/test-4.yaml new file mode 100755 index 00000000..b56c5e76 --- /dev/null +++ b/http-sse/keploy/port-mapping-test/tests/test-4.yaml @@ -0,0 +1,41 @@ +# Generated by Keploy (3-dev) +version: api.keploy.io/v1beta1 +kind: Http +name: test-4 +spec: + metadata: {} + req: + method: GET + proto_major: 1 + proto_minor: 1 + url: http://localhost:8000/health + header: + Accept: '*/*' + Host: localhost:8000 + User-Agent: curl/8.5.0 + body: "" + timestamp: 2026-03-26T12:53:31.670048681Z + resp: + status_code: 200 + header: + Content-Length: "24" + Content-Type: application/json + Date: Thu, 26 Mar 2026 12:53:31 GMT + body: | + {"ok":true,"port":8000} + status_message: OK + proto_major: 0 + proto_minor: 0 + timestamp: 2026-03-26T12:53:31.670310583Z + objects: [] + assertions: + noise: + header.Date: [] + created: 1774529611 + app_port: 8000 +curl: | + curl --request GET \ + --url http://localhost:8000/health \ + --header 'Accept: */*' \ + --header 'Host: localhost:8000' \ + --header 'User-Agent: curl/8.5.0' \ diff --git a/http-sse/keploy/port-mapping-test/tests/test-5.yaml b/http-sse/keploy/port-mapping-test/tests/test-5.yaml new file mode 100755 index 00000000..3ed97159 --- /dev/null +++ b/http-sse/keploy/port-mapping-test/tests/test-5.yaml @@ -0,0 +1,41 @@ +# Generated by Keploy (3-dev) +version: api.keploy.io/v1beta1 +kind: Http +name: test-5 +spec: + metadata: {} + req: + method: GET + proto_major: 1 + proto_minor: 1 + url: http://localhost:8000/api/hello + header: + Accept: '*/*' + Host: localhost:8000 + User-Agent: curl/8.5.0 + body: "" + timestamp: 2026-03-26T12:53:32.676362338Z + resp: + status_code: 200 + header: + Content-Length: "38" + Content-Type: application/json + Date: Thu, 26 Mar 2026 12:53:32 GMT + body: | + {"msg":"hello from http","port":8000} + status_message: OK + proto_major: 0 + proto_minor: 0 + timestamp: 2026-03-26T12:53:32.676509899Z + objects: [] + assertions: + noise: + header.Date: [] + created: 1774529612 + app_port: 8000 +curl: | + curl --request GET \ + --url http://localhost:8000/api/hello \ + --header 'Host: localhost:8000' \ + --header 'User-Agent: curl/8.5.0' \ + --header 'Accept: */*' \ diff --git a/http-sse/main.go b/http-sse/main.go index ad0c5419..6765fb27 100644 --- a/http-sse/main.go +++ b/http-sse/main.go @@ -29,6 +29,18 @@ func main() { var wg sync.WaitGroup wg.Add(2) + // Optional ping server on :8050; disabled via SKIP_PING_SERVER=1 so that + // CI can validate replaceWith port-mapping (8050→8000) actually works. + var pingSrv *http.Server + if os.Getenv("SKIP_PING_SERVER") == "" { + pingSrv = &http.Server{ + Addr: "0.0.0.0:8050", + Handler: pingMux(), + ReadHeaderTimeout: 50 * time.Second, + } + wg.Add(1) + } + go func() { defer wg.Done() log.Printf("[HTTP] listening on %s\n", httpSrv.Addr) @@ -45,6 +57,16 @@ func main() { } }() + if pingSrv != nil { + go func() { + defer wg.Done() + log.Printf("[PING] listening on %s\n", pingSrv.Addr) + if err := pingSrv.ListenAndServe(); err != nil && err != http.ErrServerClosed { + log.Fatalf("[PING] ListenAndServe: %v", err) + } + }() + } + stop := make(chan os.Signal, 1) signal.Notify(stop, os.Interrupt) <-stop @@ -54,6 +76,9 @@ func main() { _ = httpSrv.Shutdown(ctx) _ = sseSrv.Shutdown(ctx) + if pingSrv != nil { + _ = pingSrv.Shutdown(ctx) + } wg.Wait() log.Println("bye") @@ -130,6 +155,14 @@ func httpMux() http.Handler { }) }) + // 7) ping — also served on :8050 to test port mapping + mux.HandleFunc("/ping", func(w http.ResponseWriter, r *http.Request) { + writeJSON(w, http.StatusOK, map[string]any{ + "pong": true, + "from": "http", + }) + }) + // IMPORTANT: SSE routes MUST NOT be served on HTTP port. // If replay routes SSE traffic to HTTP :8000 => deterministic 404. mux.HandleFunc("/subscribe/student/events", func(w http.ResponseWriter, r *http.Request) { @@ -157,6 +190,21 @@ func httpMux() http.Handler { return mux } +/* ----------------------------- PING :8050 ----------------------------- */ + +func pingMux() http.Handler { + mux := http.NewServeMux() + + mux.HandleFunc("/ping", func(w http.ResponseWriter, r *http.Request) { + writeJSON(w, http.StatusOK, map[string]any{ + "pong": true, + "from": "http", + }) + }) + + return mux +} + /* ----------------------------- SSE :8047 ------------------------------ */ func sseMux() http.Handler {