Skip to content

Commit

Permalink
fix: update naming to match standards, update internal error codes
Browse files Browse the repository at this point in the history
- Refactor MultiCommandTestCase error message
- Update TransactionTestCase comment and variable names
- Modify logger debug message in RunQueueAll function
- Rename ResultArray to ExpectedResponseArray
  • Loading branch information
ryan-gang committed Jun 14, 2024
1 parent 6690867 commit 634dcce
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion internal/test_cases/multi_command_test_case.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type MultiCommandTestCase struct {

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")
return fmt.Errorf("CodeCrafters internal error. Number of commands and assertions should be equal in MultiCommandTestCase")
}

for i, command := range t.Commands {
Expand Down
10 changes: 5 additions & 5 deletions internal/test_cases/transaction_test_case.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

// TransactionTestCase is a test case where we initiate a transaction by sending "MULTI" command
// Send a series of commands to the server expected back "QUEUED" for each command
// Finally send "EXEC" command and expect the response to be the same as ResultArray
// Finally send "EXEC" command and expect the response to be the same as ExpectedResponseArray
//
// RunAll will run all the steps in the Transaction execution. Alternatively, you
// can run each step individually.
Expand All @@ -20,8 +20,8 @@ type TransactionTestCase struct {

// After queueing all the commands,
// if ShouldSkipExec is false, "EXEC" is sent
// And the response is compared with this ResultArray
ResultArray []resp_value.Value
// And the response is compared with this ExpectedResponseArray
ExpectedResponseArray []resp_value.Value
}

func (t TransactionTestCase) RunAll(client *resp_client.RespConnection, logger *logger.Logger) error {
Expand Down Expand Up @@ -64,7 +64,7 @@ func (t TransactionTestCase) RunMulti(client *resp_client.RespConnection, logger

func (t TransactionTestCase) RunQueueAll(client *resp_client.RespConnection, logger *logger.Logger) error {
for i, v := range t.CommandQueue {
logger.Debugf("Sent #%d command", i)
logger.Debugf("Sending command: #%d/#%d", i, len(t.CommandQueue))
commandTest := SendCommandTestCase{
Command: v[0],
Args: v[1:],
Expand All @@ -82,7 +82,7 @@ func (t TransactionTestCase) RunExec(client *resp_client.RespConnection, logger
setCommandTestCase := SendCommandTestCase{
Command: "EXEC",
Args: []string{},
Assertion: resp_assertions.NewOrderedArrayAssertion(t.ResultArray),
Assertion: resp_assertions.NewOrderedArrayAssertion(t.ExpectedResponseArray),
}

return setCommandTestCase.Run(client, logger)
Expand Down
2 changes: 1 addition & 1 deletion internal/test_txn_discard.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func testTxDiscard(stageHarness *test_case_harness.TestCaseHarness) error {
{"SET", key1, fmt.Sprint(randomInt1)},
{"INCR", key1},
},
ResultArray: []resp_value.Value{},
ExpectedResponseArray: []resp_value.Value{},
}

if err := transactionTestCase.RunWithoutExec(client, logger); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions internal/test_txn_empty.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ func testTxEmpty(stageHarness *test_case_harness.TestCaseHarness) error {
defer client.Close()

emptyTransactionTestCase := test_cases.TransactionTestCase{
CommandQueue: [][]string{},
ResultArray: []resp_value.Value{},
CommandQueue: [][]string{},
ExpectedResponseArray: []resp_value.Value{},
}

if err := emptyTransactionTestCase.RunAll(client, logger); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions internal/test_txn_multi.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ func testTxMulti(stageHarness *test_case_harness.TestCaseHarness) error {
defer client.Close()

transactionTestCase := test_cases.TransactionTestCase{
CommandQueue: [][]string{},
ResultArray: []resp_value.Value{},
CommandQueue: [][]string{},
ExpectedResponseArray: []resp_value.Value{},
}

return transactionTestCase.RunMulti(client, logger)
Expand Down
2 changes: 1 addition & 1 deletion internal/test_txn_multi_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func testTxMultiTx(stageHarness *test_case_harness.TestCaseHarness) error {
// Inside each transaction, we run 1x INCR key1, key2
// So it increases by 1 for each transaction
// `i` here is 0-indexed, so we add 1 to the expected value
ResultArray: []resp_value.Value{resp_value.NewIntegerValue(3 + (1 + i)), resp_value.NewIntegerValue(randomIntegerValue + (1 + i))},
ExpectedResponseArray: []resp_value.Value{resp_value.NewIntegerValue(3 + (1 + i)), resp_value.NewIntegerValue(randomIntegerValue + (1 + i))},
}
if err := transactionTestCase.RunExec(client, logger); err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion internal/test_txn_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func testTxQueue(stageHarness *test_case_harness.TestCaseHarness) error {
{"SET", key, fmt.Sprint(randomIntegerValue)},
{"INCR", key},
},
ResultArray: []resp_value.Value{},
ExpectedResponseArray: []resp_value.Value{},
}

if err := transactionTestCase.RunWithoutExec(clients[0], logger); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/test_txn_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func testTxSuccess(stageHarness *test_case_harness.TestCaseHarness) error {
{"INCR", key2},
{"GET", key2},
},
ResultArray: []resp_value.Value{resp_value.NewSimpleStringValue("OK"), resp_value.NewIntegerValue(randomIntegerValue + 1), resp_value.NewIntegerValue(1), resp_value.NewBulkStringValue("1")},
ExpectedResponseArray: []resp_value.Value{resp_value.NewSimpleStringValue("OK"), resp_value.NewIntegerValue(randomIntegerValue + 1), resp_value.NewIntegerValue(1), resp_value.NewBulkStringValue("1")},
}

if err := transactionTestCase.RunAll(clients[0], logger); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/test_txn_tx_failure.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func testTxErr(stageHarness *test_case_harness.TestCaseHarness) error {
{"INCR", key1},
{"INCR", key2},
},
ResultArray: []resp_value.Value{
ExpectedResponseArray: []resp_value.Value{
resp_value.NewErrorValue("ERR value is not an integer or out of range"), resp_value.NewIntegerValue(randomIntegerValue + 1)},
}

Expand Down

0 comments on commit 634dcce

Please sign in to comment.