milvus/internal/util/streamingutil/status/client_stream_wrapper_test.go
chyezh c725416288
enhance: move streaming proto into pkg (#35284)
issue: #33285

- move streaming related proto into pkg.
- add v2 message type and change flush message into v2 message.

Signed-off-by: chyezh <chyezh@outlook.com>
2024-08-07 10:34:16 +08:00

34 lines
1.1 KiB
Go

package status
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/milvus-io/milvus/internal/mocks/google.golang.org/mock_grpc"
"github.com/milvus-io/milvus/pkg/streaming/proto/streamingpb"
)
func TestClientStreamWrapper(t *testing.T) {
s := mock_grpc.NewMockClientStream(t)
s.EXPECT().SendMsg(mock.Anything).Return(NewGRPCStatusFromStreamingError(NewOnShutdownError("test")).Err())
s.EXPECT().RecvMsg(mock.Anything).Return(NewGRPCStatusFromStreamingError(NewOnShutdownError("test")).Err())
w := NewClientStreamWrapper("method", s)
err := w.SendMsg(context.Background())
assert.NotNil(t, err)
streamingErr := AsStreamingError(err)
assert.Equal(t, streamingpb.StreamingCode_STREAMING_CODE_ON_SHUTDOWN, streamingErr.Code)
assert.Contains(t, streamingErr.Cause, "test")
err = w.RecvMsg(context.Background())
assert.NotNil(t, err)
streamingErr = AsStreamingError(err)
assert.Equal(t, streamingpb.StreamingCode_STREAMING_CODE_ON_SHUTDOWN, streamingErr.Code)
assert.Contains(t, streamingErr.Cause, "test")
assert.Nil(t, NewClientStreamWrapper("method", nil))
}