-
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.
Use MultiCommandTestCase for testTxIncr1, testTxIncr2, and testTxIncr3
- Loading branch information
Showing
3 changed files
with
124 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 ( | ||
"fmt" | ||
|
||
"github.com/codecrafters-io/redis-tester/internal/redis_executable" | ||
"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/random" | ||
"github.com/codecrafters-io/tester-utils/test_case_harness" | ||
) | ||
|
||
func testTxIncr1(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", "client") | ||
if err != nil { | ||
logFriendlyError(logger, err) | ||
return err | ||
} | ||
defer client.Close() | ||
|
||
randomValue := random.RandomInt(1, 100) | ||
|
||
multiCommandTestCase := test_cases.MultiCommandTestCase{ | ||
Commands: [][]string{ | ||
{"SET", "foo", fmt.Sprint(randomValue)}, | ||
{"INCR", "foo"}, | ||
}, | ||
Assertions: []resp_assertions.RESPAssertion{ | ||
resp_assertions.NewStringAssertion("OK"), | ||
resp_assertions.NewIntegerAssertion(randomValue + 1), | ||
}, | ||
} | ||
|
||
return multiCommandTestCase.RunAll(client, logger) | ||
} |
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,39 @@ | ||
package internal | ||
|
||
import ( | ||
"github.com/codecrafters-io/redis-tester/internal/redis_executable" | ||
"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 testTxIncr2(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", "client") | ||
if err != nil { | ||
logFriendlyError(logger, err) | ||
return err | ||
} | ||
defer client.Close() | ||
|
||
multiCommandTestCase := test_cases.MultiCommandTestCase{ | ||
Commands: [][]string{ | ||
{"INCR", "foo"}, | ||
{"INCR", "foo"}, | ||
}, | ||
Assertions: []resp_assertions.RESPAssertion{ | ||
resp_assertions.NewIntegerAssertion(1), | ||
resp_assertions.NewIntegerAssertion(2), | ||
}, | ||
} | ||
|
||
return multiCommandTestCase.RunAll(client, logger) | ||
} |
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,41 @@ | ||
package internal | ||
|
||
import ( | ||
"github.com/codecrafters-io/redis-tester/internal/redis_executable" | ||
"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 testTxIncr3(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", "client") | ||
if err != nil { | ||
logFriendlyError(logger, err) | ||
return err | ||
} | ||
defer client.Close() | ||
|
||
randomValue := "xyz" | ||
|
||
multiCommandTestCase := test_cases.MultiCommandTestCase{ | ||
Commands: [][]string{ | ||
{"SET", "foo", randomValue}, | ||
{"INCR", "foo"}, | ||
}, | ||
Assertions: []resp_assertions.RESPAssertion{ | ||
resp_assertions.NewStringAssertion("OK"), | ||
resp_assertions.NewErrorAssertion("ERR value is not an integer or out of range"), | ||
}, | ||
} | ||
|
||
return multiCommandTestCase.RunAll(client, logger) | ||
} |