Skip to content

Commit

Permalink
feat: ping scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
metacoma committed Sep 19, 2024
1 parent 08c6ceb commit 9370cbe
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 1 deletion.
53 changes: 53 additions & 0 deletions tests/mindwm_bdd/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,15 @@
from messages import DataTable
from kubetest import utils as kubetest_utils
from kubetest import condition
import json
import requests

@pytest.fixture
def ctx():
return {}
@pytest.fixture
def cloudevent():
return {}

@scenario('lifecycle.feature','Validate Mindwm custom resource definitions')
def test_scenario():
Expand Down Expand Up @@ -301,6 +306,54 @@ def nats_stream_exists(kube, nats_stream_name, namespace):
pass
assert(is_ready == 'True')

@when("God creates a new cloudevent")
def cloudevent_new(cloudevent):
cloudevent = {}

@when("sets cloudevent \"{key}\" to \"{value}\"")
def cloudevent_header_set(cloudevent, key, value):
cloudevent[key] = value


@when("sends cloudevent to \"{broker_name}\" in \"{namespace}\" namespace")
def event_send_ping(kube, cloudevent, broker_name, namespace):
def get_lb():
services = kube.get_services("istio-system")
lb_service = services.get("istio-ingressgateway")
assert lb_service is not None
lb_ip = lb_service.status().load_balancer.ingress[0].ip
assert lb_ip is not None
return lb_ip

ingress_host = get_lb()
url = f"http://{ingress_host}/{namespace}/{broker_name}"

headers = {
"Host": "broker-ingress.knative-eventing.svc.cluster.local",
"Content-Type": "application/json",
"traceparent": cloudevent['traceparent'],
"Ce-specversion": "1.0",
"Ce-id": cloudevent['ce-id'],
"ce-source": cloudevent['ce-source'],
"ce-subject": cloudevent['ce-subject'],
"ce-type": cloudevent['ce-type']
}
payload = {
"input": cloudevent["ce-source"],
"output": "",
"ps1": "❯",
"type": cloudevent['ce-type']
}
response = requests.post(url, headers=headers, data=json.dumps(payload))
assert response.status_code == 202, f"Unexpected status code: {response.status_code}"

pass

@then("the trace with \"{cloudevent_id}\" should appear in TraceQL")
def tracesql_get_trace(kube, cloudevent_id):
pass



def pytest_collection_modifyitems(config: pytest.Config, items: List[pytest.Item]):
# XXX workaround
Expand Down
47 changes: 47 additions & 0 deletions tests/mindwm_bdd/features/3_mindwm_ping_pong.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
@e2e
Feature: MindWM Ping-pong EDA test
Background:
Given A MindWM environment
Then all nodes in Kubernetes are ready

Scenario: Ping <context>

When God creates a MindWM context with the name "<context>"
Then the context should be ready and operable
Then following knative service is in ready state in "context-<context>" namespace
| Knative service name |
| pong |

When God creates a MindWM user resource with the name "<username>" and connects it to the context "<context>"
Then the user resource should be ready and operable

When God creates a MindWM host resource with the name "<host>" and connects it to the user "<username>"
Then the host resource should be ready and operable

When God creates a new cloudevent
And sets cloudevent "ce-id" to "<cloudevent_id>"
And sets cloudevent "traceparent" to "<traceparent>"
And sets cloudevent "ce-subject" to "#ping"
And sets cloudevent "ce-source" to "org.mindwmv1.<username>.<host>.L3RtcC90bXV4LTEwMDAvZGVmYXVsdA==.09fb195c-c419-6d62-15e0-51b6ee990922.23.36"
And sets cloudevent "ce-type" to "org.mindwm.v1.iodocument"
And sends cloudevent to "context-broker" in "context-<context>" namespace
Then the trace with "<traceparent>" should appear in TraceQL

Examples:
| context | username | host | cloudevent_id | traceparent |
| green4 | amanda4 | pi6-host | 442af213-c860-4535-b639-355f13b2d442 | 00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-00 |



Scenario: Cleanup <username>@<host> in <context>
When God deletes the MindWM host resource "<host>"
Then the host "<host>" should be deleted

When God deletes the MindWM user resource "<username>"

When God deletes the MindWM context resource "<context>"

Examples:
| context | username | host |
| green4 | amanda4 | pi6-host |

2 changes: 1 addition & 1 deletion tests/mindwm_bdd/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ ARTIFACT_DIR=artifact_dir
source .venv/bin/activate
. .venv/bin/activate
#pytest -s --md-report --md-report-tee --md-report-verbose=7 --md-report-tee --md-report-output=${ARTIFACT_DIR}/report.md --kube-config=${HOME}/.kube/config --alluredir ${ARTIFACT_DIR}/allure-results . --order-dependencies
pytest -s -x -m crd --disable-warnings --no-header -vv --gherkin-terminal-reporter --kube-config=${HOME}/.kube/config --alluredir=${ARTIFACT_DIR}/allure-results
pytest -s -x -m e2e --disable-warnings --no-header -vv --gherkin-terminal-reporter --kube-config=${HOME}/.kube/config --alluredir=${ARTIFACT_DIR}/allure-results

0 comments on commit 9370cbe

Please sign in to comment.