mirror of
https://github.com/EchoVault/SugarDB.git
synced 2025-10-05 16:06:57 +08:00
Added test setup that adds keys for RANDOMKEY command instead of relying on keys from other tests.
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -2021,7 +2021,6 @@ func Test_Generic(t *testing.T) {
|
|||||||
t.Run("Test_HandlerDECR", func(t *testing.T) {
|
t.Run("Test_HandlerDECR", func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
conn, err := internal.GetConnection("localhost", port)
|
conn, err := internal.GetConnection("localhost", port)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
return
|
return
|
||||||
@@ -2760,6 +2759,20 @@ func Test_Generic(t *testing.T) {
|
|||||||
|
|
||||||
t.Run("Test_HandleRANDOMKEY", func(t *testing.T) {
|
t.Run("Test_HandleRANDOMKEY", func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
// Populate the store with keys first
|
||||||
|
for i := 0; i < 10; i++ {
|
||||||
|
_, _, err := mockServer.Set(
|
||||||
|
fmt.Sprintf("RandomKey%d", i),
|
||||||
|
fmt.Sprintf("Value%d", i),
|
||||||
|
echovault.SetOptions{},
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
conn, err := internal.GetConnection("localhost", port)
|
conn, err := internal.GetConnection("localhost", port)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
@@ -2770,10 +2783,7 @@ func Test_Generic(t *testing.T) {
|
|||||||
}()
|
}()
|
||||||
client := resp.NewConn(conn)
|
client := resp.NewConn(conn)
|
||||||
|
|
||||||
// Reuse existing keys to test RANDOMKEY
|
|
||||||
// All keys used for other tests contain the substring 'Key'
|
|
||||||
expected := "Key"
|
expected := "Key"
|
||||||
// Test RANDOMKEY
|
|
||||||
if err = client.WriteArray([]resp.Value{resp.StringValue("RANDOMKEY")}); err != nil {
|
if err = client.WriteArray([]resp.Value{resp.StringValue("RANDOMKEY")}); err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
@@ -2786,7 +2796,5 @@ func Test_Generic(t *testing.T) {
|
|||||||
if !strings.Contains(res.String(), expected) {
|
if !strings.Contains(res.String(), expected) {
|
||||||
t.Errorf("expected a key containing substring '%s', got %s", expected, res.String())
|
t.Errorf("expected a key containing substring '%s', got %s", expected, res.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user