Skip to content

Commit 7b2c592

Browse files
author
liuboping
committed
test: add Sentinel boundary and error depth tests (INFO replication, REPLCONF GETACK)
1 parent 4de43ef commit 7b2c592

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

internal/server/handler_depth_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,3 +1109,50 @@ func TestReplicationError_ReplconfAckWithoutArgs(t *testing.T) {
11091109
assert.True(t, ok)
11101110
assert.True(t, strings.Contains(string(*errResp), "ERR"))
11111111
}
1112+
1113+
// === Sentinel Boundary and Error Tests ===
1114+
1115+
// TestSentinelBoundary_InfoReplication tests INFO replication returns sentinel-compatible format
1116+
func TestSentinelBoundary_InfoReplication(t *testing.T) {
1117+
handler := setupTestHandler(t)
1118+
defer handler.Db.Close()
1119+
1120+
// Set up replication manager as slave to get master_link_status in output
1121+
handler.Replication = replication.NewReplicationManager(handler.Db)
1122+
handler.Replication.SetRole("slave")
1123+
handler.Replication.SetMasterAddr("127.0.0.1:6379")
1124+
1125+
resp := handler.executeCommand("INFO", [][]byte{[]byte("replication")}, "127.0.0.1:12345")
1126+
bs, ok := resp.(*proto.BulkString)
1127+
assert.True(t, ok)
1128+
info := string(*bs)
1129+
assert.True(t, strings.Contains(info, "role:"))
1130+
assert.True(t, strings.Contains(info, "master_link_status:"))
1131+
}
1132+
1133+
// TestSentinelBoundary_ReplconfGetack tests REPLCONF GETACK returns ACK format
1134+
func TestSentinelBoundary_ReplconfGetack(t *testing.T) {
1135+
handler := setupTestHandler(t)
1136+
defer handler.Db.Close()
1137+
1138+
// Set up replication manager for GETACK to work
1139+
handler.Replication = replication.NewReplicationManager(handler.Db)
1140+
1141+
resp := handler.executeCommand("REPLCONF", [][]byte{[]byte("GETACK"), []byte("*")}, "127.0.0.1:12345")
1142+
arr, ok := resp.(*proto.Array)
1143+
assert.True(t, ok)
1144+
assert.True(t, len(arr.Args) >= 3)
1145+
assert.Equal(t, []byte("REPLCONF"), arr.Args[0])
1146+
assert.Equal(t, []byte("ACK"), arr.Args[1])
1147+
}
1148+
1149+
// TestSentinelError_ReplconfUnknownSubcommand tests REPLCONF with unknown subcommand
1150+
func TestSentinelError_ReplconfUnknownSubcommand(t *testing.T) {
1151+
handler := setupTestHandler(t)
1152+
defer handler.Db.Close()
1153+
1154+
resp := handler.executeCommand("REPLCONF", [][]byte{[]byte("UNKNOWN")}, "127.0.0.1:12345")
1155+
errResp, ok := resp.(*proto.Error)
1156+
assert.True(t, ok)
1157+
assert.True(t, strings.Contains(string(*errResp), "ERR"))
1158+
}

0 commit comments

Comments
 (0)