-
Notifications
You must be signed in to change notification settings - Fork 20
CC-1731: Fix Redis #xu1 #175
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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9009b4c
refactor: streamline testStreamsXreadBlockMaxID function and introduc…
andy1li 1984438
test: update fixtures
ryan-gang 9576977
refactor: replace StreamAssertion with XReadResponseAssertion for imp…
andy1li ff642ea
refactor: introduce NewXReadResponseAssertion constructor for improve…
andy1li 9b8419a
refactor: enhance XReadResponseAssertion with ToSerializable method f…
andy1li 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,82 @@ | ||
| package resp_assertions | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "fmt" | ||
|
|
||
| resp_value "github.com/codecrafters-io/redis-tester/internal/resp/value" | ||
| ) | ||
|
|
||
| type StreamEntry struct { | ||
| Id string | ||
| FieldValuePairs [][]string | ||
| } | ||
|
|
||
| type StreamResponse struct { | ||
| Key string | ||
| Entries []StreamEntry | ||
| } | ||
|
|
||
| type XReadResponseAssertion struct { | ||
| ExpectedStreamResponses []StreamResponse | ||
| } | ||
|
|
||
| func NewXReadResponseAssertion(expectedValue []StreamResponse) RESPAssertion { | ||
| return XReadResponseAssertion{ExpectedStreamResponses: expectedValue} | ||
| } | ||
|
|
||
| func (a XReadResponseAssertion) Run(value resp_value.Value) error { | ||
| if value.Type != resp_value.ARRAY { | ||
| return fmt.Errorf("Expected array, got %s", value.Type) | ||
| } | ||
|
|
||
| expected := a.buildExpected().ToSerializable() | ||
| actual := value.ToSerializable() | ||
|
|
||
| expectedJSON, err := json.MarshalIndent(expected, "", " ") | ||
| if err != nil { | ||
| return fmt.Errorf("failed to marshal expected value: %w", err) | ||
| } | ||
| actualJSON, err := json.MarshalIndent(actual, "", " ") | ||
| if err != nil { | ||
| return fmt.Errorf("failed to marshal actual value: %w", err) | ||
| } | ||
|
|
||
| if string(expectedJSON) != string(actualJSON) { | ||
| return fmt.Errorf("XREAD response mismatch:\nExpected:\n%s\nGot:\n%s", expectedJSON, actualJSON) | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| func (a XReadResponseAssertion) buildExpected() resp_value.Value { | ||
| streams := make([]resp_value.Value, len(a.ExpectedStreamResponses)) | ||
| for i, stream := range a.ExpectedStreamResponses { | ||
| streams[i] = stream.toRESPValue() | ||
| } | ||
| return resp_value.NewArrayValue(streams) | ||
| } | ||
|
|
||
| func (s StreamResponse) toRESPValue() resp_value.Value { | ||
| entries := make([]resp_value.Value, len(s.Entries)) | ||
| for i, entry := range s.Entries { | ||
| entries[i] = entry.toRESPValue() | ||
| } | ||
| return resp_value.NewArrayValue([]resp_value.Value{ | ||
| resp_value.NewBulkStringValue(s.Key), | ||
| resp_value.NewArrayValue(entries), | ||
| }) | ||
| } | ||
|
|
||
| func (e StreamEntry) toRESPValue() resp_value.Value { | ||
| var fieldValues []resp_value.Value | ||
| for _, pair := range e.FieldValuePairs { | ||
| for _, v := range pair { | ||
| fieldValues = append(fieldValues, resp_value.NewBulkStringValue(v)) | ||
| } | ||
| } | ||
| return resp_value.NewArrayValue([]resp_value.Value{ | ||
| resp_value.NewBulkStringValue(e.Id), | ||
| resp_value.NewArrayValue(fieldValues), | ||
| }) | ||
| } | ||
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.