From a7a52da1c238096ffef4fa80e33486d8698728b8 Mon Sep 17 00:00:00 2001 From: guangzhixu Date: Mon, 23 Oct 2023 19:13:23 +0800 Subject: [PATCH] add server and client test --- rotom_test.go | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/rotom_test.go b/rotom_test.go index f7db9db..7eed2fe 100644 --- a/rotom_test.go +++ b/rotom_test.go @@ -85,7 +85,6 @@ func TestDB(t *testing.T) { assert.False(db.Remove("num-new")) db.printRuntimeStats() - go db.Listen("localhost:7676") time.Sleep(time.Second * 5) // close @@ -463,3 +462,29 @@ func TestSetAndBitmap(t *testing.T) { assert.Equal(err, base.ErrWrongType) } } + +func TestClient(t *testing.T) { + assert := assert.New(t) + + cfg := DefaultConfig + cfg.Path = gofakeit.UUID() + ".db" + db, err := Open(cfg) + assert.Nil(err) + + go db.Listen("localhost:9876") + time.Sleep(time.Second) + + cli, err := NewClient("localhost:9876") + assert.Nil(err) + + validator := NewCodec(Response).Int(int64(RES_SUCCESS)).Str("ok").B + + for i := 0; i < 10000; i++ { + k := gofakeit.Phone() + v := gofakeit.UUID() + + res, err := cli.Set(k, []byte(v)) + assert.Equal(res, validator) + assert.Nil(err) + } +}