-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Refactor testTxMulti function to use MultiCommandTestCase
The `testTxMulti` function in the `test_txn_11.go` file has been refactored to use the `MultiCommandTestCase` struct for executing multiple transactions. This change improves code readability and maintainability by encapsulating the commands and assertions within a single test case object.
- Loading branch information
Showing
3 changed files
with
67 additions
and
35 deletions.
There are no files selected for viewing
This file contains 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,35 @@ | ||
package test_cases | ||
|
||
import ( | ||
"fmt" | ||
|
||
resp_client "github.com/codecrafters-io/redis-tester/internal/resp/connection" | ||
"github.com/codecrafters-io/redis-tester/internal/resp_assertions" | ||
"github.com/codecrafters-io/tester-utils/logger" | ||
) | ||
|
||
// MultiCommandTestCase is a concise & easier way to define & run multiple SendCommandTestCase | ||
type MultiCommandTestCase struct { | ||
Commands [][]string | ||
Assertions []resp_assertions.RESPAssertion | ||
} | ||
|
||
func (t *MultiCommandTestCase) RunAll(client *resp_client.RespConnection, logger *logger.Logger) error { | ||
if len(t.Assertions) != len(t.Commands) { | ||
return fmt.Errorf("Number of commands and assertions should be equal") | ||
} | ||
|
||
for i, command := range t.Commands { | ||
setCommandTestCase := SendCommandTestCase{ | ||
Command: command[0], | ||
Args: command[1:], | ||
Assertion: t.Assertions[i], | ||
} | ||
|
||
if err := setCommandTestCase.Run(client, logger); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} |
This file contains 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 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