-
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.
implement new transaction stages Added test functions, `testTxSuccess` and `testTxErr`, which use the `OrderedArrayAssertion` to test transaction success and error scenarios.
- Loading branch information
Showing
2 changed files
with
179 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,90 @@ | ||
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/instrumented_resp_connection" | ||
"github.com/codecrafters-io/redis-tester/internal/resp_assertions" | ||
"github.com/codecrafters-io/redis-tester/internal/test_cases" | ||
"github.com/codecrafters-io/tester-utils/test_case_harness" | ||
) | ||
|
||
func testTxErr(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() | ||
|
||
setCommandTestCase := test_cases.SendCommandTestCase{ | ||
Command: "SET", | ||
Args: []string{"foo", "abc"}, | ||
Assertion: resp_assertions.NewStringAssertion("OK"), | ||
} | ||
|
||
if err := setCommandTestCase.Run(client, logger); err != nil { | ||
return err | ||
} | ||
|
||
setCommandTestCase = test_cases.SendCommandTestCase{ | ||
Command: "SET", | ||
Args: []string{"bar", "7"}, | ||
Assertion: resp_assertions.NewStringAssertion("OK"), | ||
} | ||
|
||
if err := setCommandTestCase.Run(client, logger); err != nil { | ||
return err | ||
} | ||
|
||
setCommandTestCase = test_cases.SendCommandTestCase{ | ||
Command: "MULTI", | ||
Args: []string{}, | ||
Assertion: resp_assertions.NewStringAssertion("OK"), | ||
} | ||
|
||
if err := setCommandTestCase.Run(client, logger); err != nil { | ||
return err | ||
} | ||
|
||
setCommandTestCase = test_cases.SendCommandTestCase{ | ||
Command: "INCR", | ||
Args: []string{"foo"}, | ||
Assertion: resp_assertions.NewStringAssertion("QUEUED"), | ||
} | ||
|
||
if err := setCommandTestCase.Run(client, logger); err != nil { | ||
return err | ||
} | ||
|
||
setCommandTestCase = test_cases.SendCommandTestCase{ | ||
Command: "INCR", | ||
Args: []string{"bar"}, | ||
Assertion: resp_assertions.NewStringAssertion("QUEUED"), | ||
} | ||
|
||
if err := setCommandTestCase.Run(client, logger); err != nil { | ||
return err | ||
} | ||
|
||
setCommandTestCase = test_cases.SendCommandTestCase{ | ||
Command: "EXEC", | ||
Args: []string{}, | ||
Assertion: resp_assertions.NewOrderedArrayAssertion([]resp_value.Value{ | ||
resp_value.NewErrorValue("ERR value is not an integer or out of range"), resp_value.NewIntegerValue(8)}), | ||
} | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
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/instrumented_resp_connection" | ||
"github.com/codecrafters-io/redis-tester/internal/resp_assertions" | ||
"github.com/codecrafters-io/redis-tester/internal/test_cases" | ||
"github.com/codecrafters-io/tester-utils/test_case_harness" | ||
) | ||
|
||
func testTxSuccess(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() | ||
|
||
setCommandTestCase := test_cases.SendCommandTestCase{ | ||
Command: "MULTI", | ||
Args: []string{}, | ||
Assertion: resp_assertions.NewStringAssertion("OK"), | ||
} | ||
|
||
if err := setCommandTestCase.Run(client, logger); err != nil { | ||
return err | ||
} | ||
|
||
setCommandTestCase = test_cases.SendCommandTestCase{ | ||
Command: "SET", | ||
Args: []string{"foo", "6"}, | ||
Assertion: resp_assertions.NewStringAssertion("QUEUED"), | ||
} | ||
|
||
if err := setCommandTestCase.Run(client, logger); err != nil { | ||
return err | ||
} | ||
|
||
setCommandTestCase = test_cases.SendCommandTestCase{ | ||
Command: "INCR", | ||
Args: []string{"foo"}, | ||
Assertion: resp_assertions.NewStringAssertion("QUEUED"), | ||
} | ||
|
||
if err := setCommandTestCase.Run(client, logger); err != nil { | ||
return err | ||
} | ||
|
||
setCommandTestCase = test_cases.SendCommandTestCase{ | ||
Command: "INCR", | ||
Args: []string{"bar"}, | ||
Assertion: resp_assertions.NewStringAssertion("QUEUED"), | ||
} | ||
|
||
if err := setCommandTestCase.Run(client, logger); err != nil { | ||
return err | ||
} | ||
|
||
setCommandTestCase = test_cases.SendCommandTestCase{ | ||
Command: "GET", | ||
Args: []string{"bar"}, | ||
Assertion: resp_assertions.NewStringAssertion("QUEUED"), | ||
} | ||
|
||
if err := setCommandTestCase.Run(client, logger); err != nil { | ||
return err | ||
} | ||
|
||
setCommandTestCase = test_cases.SendCommandTestCase{ | ||
Command: "EXEC", | ||
Args: []string{}, | ||
Assertion: resp_assertions.NewOrderedArrayAssertion([]resp_value.Value{resp_value.NewSimpleStringValue("OK"), resp_value.NewIntegerValue(7), resp_value.NewIntegerValue(1), resp_value.NewBulkStringValue("1")}), | ||
} | ||
|
||
if err := setCommandTestCase.Run(client, logger); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |