From 1bf4c277dbe0ca5431b2ade2249363fa303ba38a Mon Sep 17 00:00:00 2001 From: Maksim Konovalov Date: Mon, 26 Aug 2024 19:51:23 +0300 Subject: [PATCH] fix/tests: after pr #35 tests were broken, fix it with few error and ignore tmp files changes --- .gitignore | 5 ++++- CHANGELOG.md | 1 + replicaset.go | 2 +- replicaset_test.go | 37 +++++++++++++++++++++---------------- 4 files changed, 27 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index 0c753c7..d647a7e 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,7 @@ *.pid # Go output -*.out \ No newline at end of file +*.out + +# Tmp +*.tmp \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 144d917..ddd66c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ REFACTOR: * Refactored docs (add QuickStart doc) and that library base on vhsard router * Several linters are enabled because they are usefull +* Ignore .tmp files diff --git a/replicaset.go b/replicaset.go index 6a4261c..e7f4a00 100644 --- a/replicaset.go +++ b/replicaset.go @@ -53,7 +53,7 @@ func (rs *Replicaset) BucketStat(ctx context.Context, bucketID uint64) (BucketSt } if len(respData) < 1 { - return bsInfo, fmt.Errorf("respData len is 0 for %s", bucketStatFnc) + return bsInfo, fmt.Errorf("respData len is 0 for %s; unsupported or broken proto", bucketStatFnc) } if respData[0] == nil { diff --git a/replicaset_test.go b/replicaset_test.go index b7d300e..1a34779 100644 --- a/replicaset_test.go +++ b/replicaset_test.go @@ -57,20 +57,9 @@ func TestReplicaset_BucketStat(t *testing.T) { require.Equal(t, futureError, err) }) - t.Run("wrong bucket", func(t *testing.T) { + t.Run("unsupported or broken proto resp", func(t *testing.T) { f := tarantool.NewFuture(tarantool.NewCallRequest("vshard.storage.bucket_stat")) - /* - unix/:./data/storage_1_a.control> vshard.storage.bucket_stat(1000) - --- - - null - - bucket_id: 1000 - reason: Not found - code: 1 - type: ShardingError - message: 'Cannot perform action with bucket 1000, reason: Not found' - name: WRONG_BUCKET - ... - */ + bts, _ := msgpack.Marshal([]interface{}{1}) err := f.SetResponse(tarantool.Header{}, bytes.NewReader(bts)) @@ -81,8 +70,24 @@ func TestReplicaset_BucketStat(t *testing.T) { rs.conn = mPool // todo: add real tests - require.Panics(t, func() { - _, err = rs.BucketStat(ctx, 123) - }) + + statInfo, err := rs.BucketStat(ctx, 123) + require.Error(t, err) + require.Equal(t, statInfo, BucketStatInfo{BucketID: 0, Status: ""}) }) + + /* + TODO: add test for wrong bucket response + + unix/:./data/storage_1_a.control> vshard.storage.bucket_stat(1000) + --- + - null + - bucket_id: 1000 + reason: Not found + code: 1 + type: ShardingError + message: 'Cannot perform action with bucket 1000, reason: Not found' + name: WRONG_BUCKET + ... + */ }