frostfs-node/pkg/network/transport/container/grpc/put_test.go

59 lines
1.4 KiB
Go
Raw Normal View History

2020-07-24 13:54:03 +00:00
package container
import (
"context"
"errors"
"testing"
"github.com/nspcc-dev/neofs-api-go/container"
"github.com/stretchr/testify/require"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
// Entity for mocking interfaces.
// Implementation of any interface intercepts arguments via f (if not nil).
// If err is not nil, it returns as it is. Otherwise, casted to needed type res returns w/o error.
type testPutEntity struct {
// Set of interfaces which entity must implement, but some methods from those does not call.
// Argument interceptor. Used for ascertain of correct parameter passage between components.
f func(...interface{})
// Mocked result of any interface.
res interface{}
// Mocked error of any interface.
err error
}
func TestCnrService_Put(t *testing.T) {
ctx := context.TODO()
t.Run("unhealthy", func(t *testing.T) {
s := cnrService{
healthy: &testCommonEntity{
err: errors.New("some error"),
},
}
_, err := s.Put(ctx, new(container.PutRequest))
require.Error(t, err)
})
t.Run("invalid request structure", func(t *testing.T) {
s := cnrService{
healthy: new(testCommonEntity),
}
// create unsigned request
req := new(container.PutRequest)
require.Error(t, requestVerifyFunc(req))
_, err := s.Put(ctx, req)
require.Error(t, err)
st, ok := status.FromError(err)
require.True(t, ok)
require.Equal(t, codes.InvalidArgument, st.Code())
})
}