From 40942affe92a2596309e8393d23663ac2a8d900d Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Mon, 27 Jun 2022 10:24:17 +0300 Subject: [PATCH] [#278] client: Add unit test for error checkers `IsErr*` functions assert `error` argument corresponds to particular typed error. Signed-off-by: Leonard Lyubich --- client/errors_test.go | 44 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 client/errors_test.go diff --git a/client/errors_test.go b/client/errors_test.go new file mode 100644 index 00000000..bc3a5ee7 --- /dev/null +++ b/client/errors_test.go @@ -0,0 +1,44 @@ +package client_test + +import ( + "testing" + + "github.com/nspcc-dev/neofs-sdk-go/client" + apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status" + "github.com/stretchr/testify/require" +) + +func TestErrors(t *testing.T) { + for _, tc := range []struct { + check func(error) bool + errs []error + }{ + { + check: client.IsErrContainerNotFound, + errs: []error{ + apistatus.ContainerNotFound{}, + new(apistatus.ContainerNotFound), + }, + }, + { + check: client.IsErrObjectNotFound, + errs: []error{ + apistatus.ObjectNotFound{}, + new(apistatus.ObjectNotFound), + }, + }, + { + check: client.IsErrObjectAlreadyRemoved, + errs: []error{ + apistatus.ObjectAlreadyRemoved{}, + new(apistatus.ObjectAlreadyRemoved), + }, + }, + } { + require.NotEmpty(t, tc.errs) + + for i := range tc.errs { + require.True(t, tc.check(tc.errs[i]), tc.errs[i]) + } + } +}