Integration-Tests für die gesamte API #28
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Ziel
Schreibe Integration-Tests, die den Axum-Router mit einer Test-Datenbank starten und alle Endpunkte via HTTP-Requests testen.
Beschreibung
Integration-Tests testen das Zusammenspiel aller Komponenten: Router, Handler, DB, Auth, Cache. Sie nutzen
axum_testoder direktreqwestgegen einen Test-Router.Akzeptanzkriterien
tests/integration_test.rstest_client()→reqwest::Clientoderaxum_test::TestServerAuth Tests
test_unauthenticated_write_returns_401— POST ohne X-API-Key → 401test_invalid_api_key_returns_401— POST mit falschem Key → 401test_revoked_key_returns_401— Revokter Key → 401test_write_only_key_cannot_read_private— Key ohnecan_read_private→ 403Feed CRUD Tests
test_create_feed— POST /api/v1/feeds → 201 + Responsetest_create_duplicate_feed_slug→ 409 Conflicttest_create_feed_invalid_slug— "Bitcoin News!" → 400test_list_feeds— GET /api/v1/feeds → 200 + Arraytest_get_feed_by_slug— GET /api/v1/feeds/bitcoin → 200test_get_nonexistent_feed→ 404test_update_feed— PATCH /api/v1/feeds/bitcoin → 200test_delete_feed— DELETE /api/v1/feeds/bitcoin → 204Post Tests
test_create_post— POST /api/v1/posts → 201 + UUIDtest_create_post_multi_feed— Post in 3 Feeds → 201, Response hatfeeds: [3 slugs]test_create_post_nonexistent_feed→ 400 "Feed not found"test_create_post_empty_feeds→ 400 "At least one feed"test_get_post_by_uuid→ 200test_get_nonexistent_post_uuid→ 404test_list_posts→ 200 + Arraytest_list_posts_by_feed→ 200 + nur Posts dieses FeedsFeed-XML Tests
test_get_rss_feed— GET /feeds/bitcoin/rss.xml → 200, Content-Type: application/rss+xmltest_get_atom_feed— GET /feeds/bitcoin/atom.xml → 200, Content-Type: application/atom+xmltest_private_feed_without_token_returns_403→ 403test_private_feed_with_valid_token_returns_200→ 200test_private_feed_with_invalid_token_returns_403→ 403test_xml_cache_hit— Zweiter Request hat X-Cache: HITAdmin Tests
test_create_api_key→ 201 mit Klartext-Keytest_list_api_keys→ 200, KEINE Klartext-Keystest_revoke_api_key→ 200, danach Auth → 401test_delete_api_key→ 204Technische Hinweise
axum_testCrate (falls erwünscht) oderreqwestmittokio::testsqlite::memory:), keine Datei — Tests sind isoliert#[tokio::test]annotierencargo test --test integration_testzum gezielten Ausführen