mirror of
https://github.com/EchoVault/SugarDB.git
synced 2025-10-05 07:56:52 +08:00
test fixed
This commit is contained in:
@@ -2770,51 +2770,9 @@ func Test_Generic(t *testing.T) {
|
|||||||
}()
|
}()
|
||||||
client := resp.NewConn(conn)
|
client := resp.NewConn(conn)
|
||||||
|
|
||||||
tests := []struct {
|
// Reuse existing keys to test RANDOMKEY
|
||||||
name string
|
// All keys used for other tests contain the substring 'Key'
|
||||||
key string
|
expected := "Key"
|
||||||
value string
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
name: "1. String",
|
|
||||||
key: "RandKey1",
|
|
||||||
value: "value1",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "2. Integer",
|
|
||||||
key: "RandKey2",
|
|
||||||
value: "10",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "3. Float",
|
|
||||||
key: "RandKey3",
|
|
||||||
value: "3.142",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
// Map to check RANDOMKEY output
|
|
||||||
var expected map[string]string
|
|
||||||
// Preset the values
|
|
||||||
for _, test := range tests {
|
|
||||||
t.Run(test.name, func(t *testing.T) {
|
|
||||||
func(key, value string, expected map[string]string) {
|
|
||||||
err = client.WriteArray([]resp.Value{resp.StringValue("SET"), resp.StringValue(key), resp.StringValue(value)})
|
|
||||||
if err != nil {
|
|
||||||
t.Error(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
res, _, err := client.ReadValue()
|
|
||||||
if err != nil {
|
|
||||||
t.Error(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !strings.EqualFold(res.String(), "ok") {
|
|
||||||
t.Errorf("expected preset response to be \"OK\", got %s", res.String())
|
|
||||||
}
|
|
||||||
|
|
||||||
expected[key] = ""
|
|
||||||
}(test.key, test.value, expected)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
// Test RANDOMKEY
|
// 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)
|
||||||
@@ -2825,8 +2783,8 @@ func Test_Generic(t *testing.T) {
|
|||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, ok := expected[res.String()]; !ok {
|
if !strings.Contains(res.String(), expected) {
|
||||||
t.Errorf("expected one of %v, 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