Repository navigation
feat(ruby): add DELIFEQ command support #382
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4d93d24
chore(deps): Bump valkey-io/valkey-glide/.github/workflows/git-secret…
dependabot[bot] ec680e0
feat(ruby): add DELIFEQ command support
Aryex 733828b
docs(ruby): link DELIFEQ changelog entry
Aryex ebaf044
test(ruby): use guard-style version checks for DELIFEQ
Aryex d4132eb
test(ruby): consolidate DELIFEQ unit cases
Aryex 51aecc1
test(ruby): streamline DELIFEQ coverage
Aryex dada2f5
test(ruby): cover transaction boolean coercion
Aryex 498ea6f
docs(ruby): add testing guidelines
Aryex aed2995
added rules on negative test cases
Aryex File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| # Testing guidelines | ||
|
|
||
| This document is the authoritative testing reference for the Valkey GLIDE Ruby client. Follow these guidelines when developing new tests to keep them consistent, maintainable, and resilient to unrelated changes. | ||
|
|
||
| ## Overall guidelines | ||
|
|
||
| - Avoid magic numbers. Use named variables, especially when a number has a unit. | ||
|
|
||
| ## Test naming and organization | ||
|
|
||
| - Group tests by the feature they test. | ||
| - Within each group, order positive tests first, followed by negative tests and edge cases. | ||
| - Start with `test_<command_or_feature>`, which contains the basic positive-case assertions. Follow it with separate negative and edge-case tests. | ||
| - Use the format `test_<command_or_feature>_<condition_or_context>`. | ||
|
|
||
| Example: | ||
|
|
||
| ```ruby | ||
| def test_get | ||
| # Assert the basic positive case. | ||
| end | ||
|
|
||
| def test_get_not_found | ||
| # Assert a simple negative case. | ||
| end | ||
|
|
||
| def test_get_nil | ||
| # Assert an edge case. | ||
| end | ||
|
|
||
| def test_delifeq | ||
| end | ||
|
|
||
| def test_delifeq_not_matching | ||
| end | ||
|
|
||
| def test_delifeq_binary_value | ||
| end | ||
| ``` | ||
|
|
||
| ## Test coverage | ||
|
|
||
| - Unit and integration tests have different purposes and cover different parts of the client. | ||
| - Each assertion must verify behavior owned by the layer under test. | ||
|
|
||
| ### Unit tests | ||
|
|
||
| - Unit tests cover Ruby-owned behavior, including request construction and data conversion before values reach Core. | ||
| - Each new component or API should have its own unit tests. | ||
| - Tests must assert only the component's properties and behavior. | ||
| - Tests should not cover Core or server behavior. | ||
| - Mocking and stubbing are allowed but should remain simple. If a test requires extensive mocking, consider skipping it and flagging the gap for human review. | ||
|
|
||
| ### Integration tests | ||
|
|
||
| - Integration tests exercise the Ruby client from a user's point of view and verify public API contracts against a server. | ||
| - Negative tests must cover documented errors that are specific for that API; Generic errors like ACL and connections are not needed. | ||
| - Tests should assert return values and publicly observable state. | ||
| - They should not assert the Ruby client's private state. Unit tests own that behavior. | ||
| - Integration tests should use the Ruby client as an application would. | ||
| - Assertions must follow the public API documentation. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require "minitest/autorun" | ||
| require "valkey/errors" | ||
| require "valkey/request_type" | ||
| require "valkey/commands/string_commands" | ||
|
|
||
| # Unit tests for string command request construction. | ||
| class TestStringCommandsUnit < Minitest::Test | ||
|
currantw marked this conversation as resolved.
Resolved
|
||
| # Minimal command receiver that records dispatched requests. | ||
| class FakeClient | ||
| include Valkey::Commands::StringCommands | ||
|
|
||
| attr_reader :captured_command, :captured_arguments | ||
|
|
||
| def initialize(reply: nil, error: nil) | ||
| @reply = reply | ||
| @error = error | ||
| end | ||
|
|
||
| def send_command(request_type, command_arguments = []) | ||
| @captured_command = request_type | ||
| @captured_arguments = command_arguments | ||
| raise @error if @error | ||
|
|
||
| @reply | ||
| end | ||
| end | ||
|
|
||
| def test_delifeq | ||
| assert_delifeq(key: "key", value: "value", expected_sent_value: "value") | ||
| end | ||
|
|
||
| def test_delifeq_non_string_value | ||
| # non-string values are stringified | ||
| assert_delifeq(key: "key", value: %w[a b], expected_sent_value: "[\"a\", \"b\"]") | ||
| end | ||
|
|
||
| def test_delifeq_stringifies_nil_value | ||
|
currantw marked this conversation as resolved.
Resolved
|
||
| assert_delifeq(key: "key", value: nil, expected_sent_value: "") | ||
| end | ||
|
|
||
| def test_delifeq_propagates_client_error | ||
|
currantw marked this conversation as resolved.
Resolved
|
||
| error = Valkey::CommandError.new("error") | ||
| client = FakeClient.new(error: error) | ||
|
|
||
| raised_error = assert_raises(Valkey::CommandError) { client.delifeq("key", "value") } | ||
|
|
||
| assert_same error, raised_error | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def assert_delifeq(key:, value:, expected_sent_value:) | ||
| client = FakeClient.new(reply: 0) | ||
|
|
||
| assert_equal 0, client.delifeq(key, value) | ||
| assert_equal Valkey::RequestType::DEL_IF_EQ, client.captured_command | ||
| assert_equal [key, expected_sent_value], client.captured_arguments | ||
|
|
||
| client | ||
| end | ||
| end | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.