-
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: Add testTxEmpty function to internal package
This commit adds the testTxEmpty function to the internal package. The function tests an empty transaction by running a Redis executable and executing various test cases. It includes assertions for error handling and ensures that the EXEC command without MULTI returns an error.
- Loading branch information
Showing
1 changed file
with
44 additions
and
0 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,44 @@ | ||
package internal | ||
|
||
import ( | ||
"github.com/codecrafters-io/redis-tester/internal/redis_executable" | ||
resp_value "github.com/codecrafters-io/redis-tester/internal/resp/value" | ||
"github.com/codecrafters-io/redis-tester/internal/resp_assertions" | ||
|
||
"github.com/codecrafters-io/redis-tester/internal/instrumented_resp_connection" | ||
"github.com/codecrafters-io/redis-tester/internal/test_cases" | ||
"github.com/codecrafters-io/tester-utils/test_case_harness" | ||
) | ||
|
||
func testTxEmpty(stageHarness *test_case_harness.TestCaseHarness) error { | ||
b := redis_executable.NewRedisExecutable(stageHarness) | ||
if err := b.Run(); err != nil { | ||
return err | ||
} | ||
|
||
logger := stageHarness.Logger | ||
|
||
client, err := instrumented_resp_connection.NewFromAddr(stageHarness, "localhost:6379", "client1") | ||
if err != nil { | ||
logFriendlyError(logger, err) | ||
return err | ||
} | ||
defer client.Close() | ||
|
||
emptyTransactionTestCase := test_cases.TransactionTestCase{ | ||
CommandQueue: [][]string{}, | ||
ResultArray: []resp_value.Value{}, | ||
} | ||
|
||
if err := emptyTransactionTestCase.RunAll(client, logger); err != nil { | ||
return err | ||
} | ||
|
||
bareExecCommandTestCase := test_cases.SendCommandTestCase{ | ||
Command: "EXEC", | ||
Args: []string{}, | ||
Assertion: resp_assertions.NewErrorAssertion("ERR EXEC without MULTI"), | ||
} | ||
|
||
return bareExecCommandTestCase.Run(client, logger) | ||
} |