-
Notifications
You must be signed in to change notification settings - Fork 328
feat(bdd): add shared stream operations scenario for Go SDK #3245
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
600719f
a1065dc
f19b436
c6636eb
2fe260f
ec76582
0342d86
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -272,3 +272,43 @@ def verify_last_message_match(context): | |
| last_polled_payload = last_polled.payload().decode("utf-8") | ||
|
|
||
| assert last_polled_payload == context.last_sent_message | ||
|
|
||
|
|
||
| @when(parsers.parse('I update the stream name to "{new_name}"')) | ||
| def update_stream_name(context, new_name): | ||
| """Update the stream name""" | ||
|
|
||
| async def _update(): | ||
| await context.client.update_stream(context.last_stream_id, new_name) | ||
| context.last_stream_name = new_name | ||
|
|
||
| asyncio.run(_update()) | ||
|
|
||
|
|
||
| @then(parsers.parse('the stream name should be updated to "{expected_name}"')) | ||
| def verify_stream_name_updated(context, expected_name): | ||
| """Verify stream name was updated""" | ||
|
|
||
| async def _verify(): | ||
| stream = await context.client.get_stream(context.last_stream_id) | ||
| assert stream is not None | ||
| assert stream.name == expected_name | ||
|
|
||
| asyncio.run(_verify()) | ||
|
|
||
|
|
||
| @when(parsers.parse('I delete the stream with name "{name}"')) | ||
| def delete_stream(context, name): | ||
| """Delete the stream by name""" | ||
|
|
||
| async def _delete(): | ||
| await context.client.delete_stream(name) | ||
| context.last_stream_id = None | ||
|
|
||
| asyncio.run(_delete()) | ||
|
|
||
|
|
||
| @then("the stream should be deleted successfully") | ||
| def verify_stream_deleted(context): | ||
| """Verify stream was deleted""" | ||
| assert context.last_stream_id is None | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tautological - the when-step three lines above nulled |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,7 +18,7 @@ | |
|
|
||
| use crate::common::global_context::GlobalContext; | ||
| use cucumber::{given, then, when}; | ||
| use iggy::prelude::StreamClient; | ||
| use iggy::prelude::{Identifier, StreamClient}; | ||
|
|
||
| #[given("I have no streams in the system")] | ||
| pub async fn given_no_streams(world: &mut GlobalContext) { | ||
|
|
@@ -64,3 +64,47 @@ pub async fn then_stream_has_name(world: &mut GlobalContext, expected_name: Stri | |
| "Stream should have expected name" | ||
| ); | ||
| } | ||
|
|
||
| #[when(regex = r#"^I update the stream name to "([^"]*)"$"#)] | ||
| pub async fn when_update_stream_name(world: &mut GlobalContext, new_name: String) { | ||
| let client = world.client.as_ref().expect("Client should be available"); | ||
| let stream_id = world.last_stream_id.expect("Stream should exist"); | ||
| let identifier = Identifier::numeric(stream_id).unwrap(); | ||
| client | ||
| .update_stream(&identifier, &new_name) | ||
| .await | ||
| .expect("Should be able to update stream"); | ||
| world.last_stream_name = Some(new_name); | ||
| } | ||
|
|
||
| #[then(regex = r#"^the stream name should be updated to "([^"]*)"$"#)] | ||
| pub async fn then_stream_name_updated(world: &mut GlobalContext, expected_name: String) { | ||
| let client = world.client.as_ref().expect("Client should be available"); | ||
| let stream_id = world.last_stream_id.expect("Stream should exist"); | ||
| let identifier = Identifier::numeric(stream_id).unwrap(); | ||
| let stream = client | ||
| .get_stream(&identifier) | ||
| .await | ||
| .expect("Should be able to get stream") | ||
| .expect("Stream should exist"); | ||
| assert_eq!(stream.name, expected_name, "Stream name should be updated"); | ||
| } | ||
|
|
||
| #[when(regex = r#"^I delete the stream with name "([^"]*)"$"#)] | ||
| pub async fn when_delete_stream(world: &mut GlobalContext, name: String) { | ||
| let client = world.client.as_ref().expect("Client should be available"); | ||
| let identifier = Identifier::named(&name).expect("Stream name should be valid"); | ||
| client | ||
| .delete_stream(&identifier) | ||
| .await | ||
| .expect("Should be able to delete stream"); | ||
| world.last_stream_id = None; | ||
| } | ||
|
|
||
| #[then("the stream should be deleted successfully")] | ||
| pub async fn then_stream_deleted_successfully(world: &mut GlobalContext) { | ||
| assert!( | ||
| world.last_stream_id.is_none(), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this only checks |
||
| "Stream should have been deleted" | ||
| ); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,3 +43,9 @@ Feature: Basic Messaging Operations | |
| And the messages should have sequential offsets from 0 to 9 | ||
| And each message should have the expected payload content | ||
| And the last polled message should match the last sent message | ||
|
|
||
| When I update the stream name to "test-stream-updated" | ||
| Then the stream name should be updated to "test-stream-updated" | ||
|
|
||
| When I delete the stream with name "test-stream-updated" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. delete-step uses the new name |
||
| Then the stream should be deleted successfully | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -196,6 +196,36 @@ public void ThenTheLastPolledMessageShouldMatchTheLastSentMessage() | |
| lastPolled.Header.Id.ShouldBe(_context.LastSendMessage.Header.Id); | ||
| lastPolled.Payload.ShouldBe(_context.LastSendMessage.Payload); | ||
| } | ||
|
|
||
| [When("I update the stream name to {string}")] | ||
| public async Task WhenIUpdateTheStreamNameTo(string newName) | ||
| { | ||
| _context.CreatedStream.ShouldNotBeNull(); | ||
| await _context.IggyClient.UpdateStreamAsync( | ||
| Identifier.Numeric(_context.CreatedStream!.Id), newName); | ||
| _context.CreatedStream = await _context.IggyClient.GetStreamByIdAsync( | ||
| Identifier.Numeric(_context.CreatedStream.Id)); | ||
| } | ||
|
|
||
| [Then("the stream name should be updated to {string}")] | ||
| public void ThenTheStreamNameShouldBeUpdatedTo(string expectedName) | ||
| { | ||
| _context.CreatedStream.ShouldNotBeNull(); | ||
| _context.CreatedStream!.Name.ShouldBe(expectedName); | ||
| } | ||
|
|
||
| [When(@"I delete the stream with name ""(.*)""")] | ||
| public async Task WhenIDeleteTheStream(string name) | ||
| { | ||
| await _context.IggyClient.DeleteStreamAsync(Identifier.String(name)); | ||
| _context.CreatedStream = null; | ||
| } | ||
|
|
||
| [Then(@"the stream should be deleted successfully")] | ||
| public void ThenTheStreamShouldBeDeletedSuccessfully() | ||
| { | ||
| _context.CreatedStream.ShouldBeNull(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the when-step at line 221 already nulled |
||
| } | ||
| } | ||
|
|
||
| // Test context for sharing data between steps | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,6 +45,41 @@ Then( | |
| } | ||
| ); | ||
|
|
||
| When( | ||
| 'I update the stream name to {string}', | ||
| async function (this: TestWorld, newName: string) { | ||
| assert.ok(await this.client.stream.update({ | ||
| streamId: this.stream.id, | ||
| name: newName | ||
| })); | ||
| this.stream = { ...this.stream, name: newName }; | ||
| } | ||
| ); | ||
|
|
||
| Then( | ||
| 'the stream name should be updated to {string}', | ||
| async function (this: TestWorld, expectedName: string) { | ||
| const stream = await this.client.stream.get({ streamId: this.stream.id }); | ||
| assert.ok(stream, 'Stream should exist after update'); | ||
| assert.equal(stream!.name, expectedName); | ||
| } | ||
| ); | ||
|
|
||
| When( | ||
| 'I delete the stream with name {string}', | ||
| async function (this: TestWorld, name: string) { | ||
| assert.ok(await this.client.stream.delete({ streamId: name })); | ||
| } | ||
| ); | ||
|
|
||
| Then( | ||
| 'the stream should be deleted successfully', | ||
| async function (this: TestWorld) { | ||
| // If we reached here without error, the stream was deleted successfully | ||
| assert.ok(true); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
| ); | ||
|
|
||
| // Cleanup: delete stream after test | ||
| Then( | ||
| 'I can delete stream with ID {int}', | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -259,6 +259,22 @@ class IggyClient: | |
|
|
||
| Returns Option of stream details or a PyRuntimeError on failure. | ||
| """ | ||
| def update_stream( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| self, stream_id: builtins.str | builtins.int, name: builtins.str | ||
| ) -> collections.abc.Awaitable[None]: | ||
| r""" | ||
| Updates a stream's name. | ||
|
|
||
| Returns Ok(()) on successful stream update or a PyRuntimeError on failure. | ||
| """ | ||
| def delete_stream( | ||
| self, stream_id: builtins.str | builtins.int | ||
| ) -> collections.abc.Awaitable[None]: | ||
| r""" | ||
| Deletes a stream by id. | ||
|
|
||
| Returns Ok(()) on successful stream deletion or a PyRuntimeError on failure. | ||
| """ | ||
| def create_topic( | ||
| self, | ||
| stream: builtins.str | builtins.int, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assertNull(context.lastStreamId)re-checks a local field the when-step at line 230 just nulled, so it can't fail. mirrorbdd/go/tests/basic_messaging.go:250-261: callgetClient().streams().getStream(...)against the deleted id and assert emptyOptional.