Skip to content

Commit 6d8e757

Browse files
authored
Merge pull request #200 from codecrafters-io/andy/feat
Add NewSimpleStringAssertion for PING/PONG
2 parents 654c7c9 + f1a9095 commit 6d8e757

File tree

4 files changed

+31
-4
lines changed

4 files changed

+31
-4
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package resp_assertions
2+
3+
import (
4+
"fmt"
5+
6+
resp_value "github.com/codecrafters-io/redis-tester/internal/resp/value"
7+
)
8+
9+
type SimpleStringAssertion struct {
10+
ExpectedValue string
11+
}
12+
13+
func NewSimpleStringAssertion(expectedValue string) RESPAssertion {
14+
return SimpleStringAssertion{ExpectedValue: expectedValue}
15+
}
16+
17+
func (a SimpleStringAssertion) Run(value resp_value.Value) error {
18+
if value.Type != resp_value.SIMPLE_STRING {
19+
return fmt.Errorf("Expected simple string, got %s", value.Type)
20+
}
21+
22+
if value.String() != a.ExpectedValue {
23+
return fmt.Errorf("Expected %q, got %q", a.ExpectedValue, value.String())
24+
}
25+
26+
return nil
27+
}

internal/test_cases/send_replication_handshake_test_case.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func (t SendReplicationHandshakeTestCase) RunPingStep(client *instrumented_resp_
4141
commandTest := SendCommandTestCase{
4242
Command: "PING",
4343
Args: []string{},
44-
Assertion: resp_assertions.NewStringAssertion("PONG"),
44+
Assertion: resp_assertions.NewSimpleStringAssertion("PONG"),
4545
}
4646

4747
return commandTest.Run(client, logger)

internal/test_ping_pong.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func testPingPongOnce(stageHarness *test_case_harness.TestCaseHarness) error {
2727
commandTestCase := test_cases.SendCommandTestCase{
2828
Command: "ping",
2929
Args: []string{},
30-
Assertion: resp_assertions.NewStringAssertion("PONG"),
30+
Assertion: resp_assertions.NewSimpleStringAssertion("PONG"),
3131
}
3232

3333
if err := commandTestCase.Run(client, logger); err != nil {
@@ -122,7 +122,7 @@ func runPing(logger *logger.Logger, client *instrumented_resp_connection.Instrum
122122
commandTestCase := test_cases.SendCommandTestCase{
123123
Command: "ping",
124124
Args: []string{},
125-
Assertion: resp_assertions.NewStringAssertion("PONG"),
125+
Assertion: resp_assertions.NewSimpleStringAssertion("PONG"),
126126
}
127127

128128
if err := commandTestCase.Run(client, logger); err != nil {

internal/test_pubsub_subscribe4.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func testPubSubSubscribe4(stageHarness *test_case_harness.TestCaseHarness) error
4545
/* Test against ping from a separate (unsubscribed) client */
4646
pingTestCase2 := test_cases.SendCommandTestCase{
4747
Command: "PING",
48-
Assertion: resp_assertions.NewStringAssertion("PONG"),
48+
Assertion: resp_assertions.NewSimpleStringAssertion("PONG"),
4949
}
5050
return pingTestCase2.Run(clients[1], logger)
5151
}

0 commit comments

Comments
 (0)