Skip to content

Commit

Permalink
feat: Add testTxEmpty function to internal package
Browse files Browse the repository at this point in the history
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
ryan-gang committed Jun 13, 2024
1 parent fb6e805 commit 11c4a5c
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions internal/test_txn_empty.go
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)
}

0 comments on commit 11c4a5c

Please sign in to comment.