go.temporal.io/server@v1.23.0/common/rpc/interceptor/stream_error_test.go (about)

     1  // The MIT License
     2  //
     3  // Copyright (c) 2020 Temporal Technologies Inc.  All rights reserved.
     4  //
     5  // Copyright (c) 2020 Uber Technologies, Inc.
     6  //
     7  // Permission is hereby granted, free of charge, to any person obtaining a copy
     8  // of this software and associated documentation files (the "Software"), to deal
     9  // in the Software without restriction, including without limitation the rights
    10  // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    11  // copies of the Software, and to permit persons to whom the Software is
    12  // furnished to do so, subject to the following conditions:
    13  //
    14  // The above copyright notice and this permission notice shall be included in
    15  // all copies or substantial portions of the Software.
    16  //
    17  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    18  // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    19  // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    20  // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    21  // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    22  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    23  // THE SOFTWARE.
    24  
    25  package interceptor
    26  
    27  import (
    28  	"io"
    29  	"testing"
    30  
    31  	"github.com/stretchr/testify/require"
    32  	"github.com/stretchr/testify/suite"
    33  	"go.temporal.io/api/serviceerror"
    34  	"google.golang.org/grpc/codes"
    35  	"google.golang.org/grpc/status"
    36  )
    37  
    38  type (
    39  	streamErrorSuite struct {
    40  		*require.Assertions
    41  		suite.Suite
    42  	}
    43  )
    44  
    45  func TestStreamErrorSuite(t *testing.T) {
    46  	s := new(streamErrorSuite)
    47  	suite.Run(t, s)
    48  }
    49  
    50  func (s *streamErrorSuite) SetupSuite() {
    51  	s.Assertions = require.New(s.T())
    52  }
    53  
    54  func (s *streamErrorSuite) TearDownSuite() {
    55  }
    56  
    57  func (s *streamErrorSuite) SetupTest() {
    58  }
    59  
    60  func (s *streamErrorSuite) TearDownTest() {
    61  }
    62  
    63  func (s *streamErrorSuite) TestErrorConversion() {
    64  	s.Equal(nil, errorConvert(nil))
    65  	s.Equal(io.EOF, errorConvert(io.EOF))
    66  
    67  	s.IsType(nil, errorConvert(status.Error(codes.OK, "")))
    68  	s.IsType(&serviceerror.DeadlineExceeded{}, errorConvert(status.Error(codes.DeadlineExceeded, "")))
    69  	s.IsType(&serviceerror.Canceled{}, errorConvert(status.Error(codes.Canceled, "")))
    70  	s.IsType(&serviceerror.InvalidArgument{}, errorConvert(status.Error(codes.InvalidArgument, "")))
    71  	s.IsType(&serviceerror.FailedPrecondition{}, errorConvert(status.Error(codes.FailedPrecondition, "")))
    72  	s.IsType(&serviceerror.Unavailable{}, errorConvert(status.Error(codes.Unavailable, "")))
    73  	s.IsType(&serviceerror.Internal{}, errorConvert(status.Error(codes.Internal, "")))
    74  	s.IsType(&serviceerror.Internal{}, errorConvert(status.Error(codes.Unknown, "")))
    75  }