From 5c031fc6b2ede36233c8d213ece893384929cbfd Mon Sep 17 00:00:00 2001 From: Evgeniy Kulikov Date: Mon, 25 Nov 2019 15:47:57 +0300 Subject: [PATCH 1/2] service: ProcessRequestTTL shouldn't change status errors --- service/meta.go | 4 ++++ service/meta_test.go | 31 +++++++++++++++++++------------ 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/service/meta.go b/service/meta.go index 6b5b8b7..abffdad 100644 --- a/service/meta.go +++ b/service/meta.go @@ -101,6 +101,10 @@ func ProcessRequestTTL(req MetaHeader, cond ...TTLCondition) error { // check specific condition: if err := cond[i](ttl); err != nil { + if st, ok := status.FromError(err); ok { + return st.Err() + } + return status.New(codes.InvalidArgument, err.Error()).Err() } } diff --git a/service/meta_test.go b/service/meta_test.go index 893ca5e..496ea51 100644 --- a/service/meta_test.go +++ b/service/meta_test.go @@ -9,58 +9,65 @@ import ( ) type mockedRequest struct { - msg string - name string - role NodeRole - code codes.Code + msg string + name string + code codes.Code + handler TTLCondition RequestMetaHeader } func TestMetaRequest(t *testing.T) { tests := []mockedRequest{ { - role: InnerRingNode, name: "direct to ir node", + handler: IRNonForwarding(InnerRingNode), RequestMetaHeader: RequestMetaHeader{TTL: NonForwardingTTL}, }, { - role: StorageNode, code: codes.InvalidArgument, msg: ErrIncorrectTTL.Error(), name: "direct to storage node", + handler: IRNonForwarding(StorageNode), RequestMetaHeader: RequestMetaHeader{TTL: NonForwardingTTL}, }, { - role: StorageNode, msg: ErrZeroTTL.Error(), code: codes.InvalidArgument, name: "zero ttl", + handler: IRNonForwarding(StorageNode), RequestMetaHeader: RequestMetaHeader{TTL: ZeroTTL}, }, { - role: InnerRingNode, name: "default to ir node", + handler: IRNonForwarding(InnerRingNode), RequestMetaHeader: RequestMetaHeader{TTL: SingleForwardingTTL}, }, { - role: StorageNode, name: "default to storage node", + handler: IRNonForwarding(StorageNode), RequestMetaHeader: RequestMetaHeader{TTL: SingleForwardingTTL}, }, + { + msg: "not found", + code: codes.NotFound, + name: "custom status error", + RequestMetaHeader: RequestMetaHeader{TTL: SingleForwardingTTL}, + handler: func(_ uint32) error { return status.Error(codes.NotFound, "not found") }, + }, } for i := range tests { tt := tests[i] t.Run(tt.name, func(t *testing.T) { before := tt.GetTTL() - err := ProcessRequestTTL(&tt, IRNonForwarding(tt.role)) + err := ProcessRequestTTL(&tt, tt.handler) if tt.msg != "" { require.Errorf(t, err, tt.msg) state, ok := status.FromError(err) require.True(t, ok) - require.Equal(t, state.Code(), tt.code) - require.Equal(t, state.Message(), tt.msg) + require.Equal(t, tt.code, state.Code()) + require.Equal(t, tt.msg, state.Message()) } else { require.NoError(t, err) require.NotEqualf(t, before, tt.GetTTL(), "ttl should be changed: %d vs %d", before, tt.GetTTL()) From 50a8be84c4ca08f9bd86d14028220d9b2c0eb2bf Mon Sep 17 00:00:00 2001 From: Evgeniy Kulikov Date: Mon, 25 Nov 2019 15:59:53 +0300 Subject: [PATCH 2/2] CHANGELOG --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c2ce5b8..2e7736d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ # Changelog This is the changelog for NeoFS Proto +## [0.2.2] - 2019-11-22 + +### Changed +- ProcessRequestTTL don't changes status errors from TTLCondition + ## [0.2.1] - 2019-11-22 ### Changed @@ -27,3 +32,4 @@ Initial public release [0.2.0]: https://github.com/nspcc-dev/neofs-proto/compare/v0.1.0...v0.2.0 [0.2.1]: https://github.com/nspcc-dev/neofs-proto/compare/v0.2.0...v0.2.1 +[0.2.2]: https://github.com/nspcc-dev/neofs-proto/compare/v0.2.1...v0.2.2