You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was trying to provider-side verify a customer pact file, when noticing that my current local testing setup must fail, because it does not include meta attributes in contrast to the actual pub-sub resources. But it did not fail, it just did not verify them.
The verification is important, as faning out by SNS->multiple SQS is often realized by using filters on meta attributes.
To reproduce my error I adopted your examples provided in this repo (a big thank you at this point for providing examples!).
Steps to reproduce
(1) consumer test:
"""pact test for a message consumer"""importloggingimporttimefromosimportremovefromos.pathimportisfileimportpytestfrompactimportMessageConsumerfrompactimportProviderlog=logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)
PACT_DIR="pacts"CONSUMER_NAME="DetectContentLambda"PROVIDER_NAME="ContentProvider"PACT_FILE= (
f"{PACT_DIR}/{CONSUMER_NAME.lower().replace(' ', '_')}-"+f"{PROVIDER_NAME.lower().replace(' ', '_')}.json"
)
@pytest.fixture(scope="session")defpact(request):
pact=MessageConsumer(CONSUMER_NAME).has_pact_with(
Provider(PROVIDER_NAME),
publish_to_broker=False,
pact_dir=PACT_DIR,
)
yieldpactdefcleanup_json(file):
""" Remove existing json file before test if any """ifisfile(f"{file}"):
remove(f"{file}")
defprogressive_delay(file, time_to_wait=10, second_interval=0.5, verbose=False):
""" progressive delay defaults to wait up to 5 seconds with 0.5 second intervals """time_counter=0whilenotisfile(file):
time.sleep(second_interval)
time_counter+=1ifverbose:
print(f"Trying for {time_counter*second_interval} seconds")
iftime_counter>time_to_wait:
ifverbose:
print(f"Already waited {time_counter*second_interval} seconds")
breakdeftest_put_file(pact):
cleanup_json(PACT_FILE)
expected_event= {
"event": "ObjectCreated:Put",
"documentName": "document.doc",
"creator": "TP",
"documentType": "microsoft-word",
}
(
pact.given("A document created successfully")
.expects_to_receive("Description")
.with_content(expected_event)
.with_metadata(
{"Content-Type": "application/json", "Additional-Key": "to test with"}
)
)
withpact:
print("\nRunning test.")
progressive_delay(f"{PACT_FILE}")
assertisfile(f"{PACT_FILE}") ==1
test_msg_provider.py::test_verify_success PASSED
[100%]pact WARN: Please note: we are tracking events anonymously to gather important usage statistics like Pact-Ruby version and operating system. To disable tracking, set the 'PACT_DO_NOT_TRACK' environment variable to 'true'.
INFO: Reading pact at pacts/detectcontentlambda-contentprovider.json
Verifying a pact between DetectContentLambda and ContentProvider
Given A document created successfully
Description
WARN: Skipping set up for provider state 'A document created successfully' for consumer 'DetectContentLambda' as there is no --provider-states-setup-url specified.
has matching content
1 interaction, 0 failures
Expected behavior
A failure is expected in the form of:
Verifying a pact between DetectContentLambda and ContentProvider
Given A document created successfully
has matching metadata
Expected message metada "Additional-Key" to have value "to test with" but was ""
There were 1 pact failures
Actual behavior
The test succeeds without verifying the metadata attributes.
Description
I was trying to provider-side verify a customer pact file, when noticing that my current local testing setup must fail, because it does not include meta attributes in contrast to the actual pub-sub resources. But it did not fail, it just did not verify them.
The verification is important, as faning out by SNS->multiple SQS is often realized by using filters on meta attributes.
To reproduce my error I adopted your examples provided in this repo (a big thank you at this point for providing examples!).
Steps to reproduce
(1) consumer test:
(2) subsequently provider test:
results in:
Expected behavior
A failure is expected in the form of:
Actual behavior
The test succeeds without verifying the metadata attributes.
Your environment
Adapted the examples from examples/message/tests.
Self-service
The text was updated successfully, but these errors were encountered: