github.com/milvus-io/milvus-sdk-go/v2@v2.4.1/merr/errors_test.go (about)

     1  // Licensed to the LF AI & Data foundation under one
     2  // or more contributor license agreements. See the NOTICE file
     3  // distributed with this work for additional information
     4  // regarding copyright ownership. The ASF licenses this file
     5  // to you under the Apache License, Version 2.0 (the
     6  // "License"); you may not use this file except in compliance
     7  // with the License. You may obtain a copy of the License at
     8  //
     9  //     http://www.apache.org/licenses/LICENSE-2.0
    10  //
    11  // Unless required by applicable law or agreed to in writing, software
    12  // distributed under the License is distributed on an "AS IS" BASIS,
    13  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14  // See the License for the specific language governing permissions and
    15  // limitations under the License.
    16  
    17  package merr
    18  
    19  import (
    20  	"testing"
    21  
    22  	"github.com/cockroachdb/errors"
    23  	"github.com/stretchr/testify/suite"
    24  
    25  	"github.com/milvus-io/milvus-proto/go-api/v2/commonpb"
    26  )
    27  
    28  type ErrSuite struct {
    29  	suite.Suite
    30  }
    31  
    32  func (s *ErrSuite) SetupSuite() {
    33  }
    34  
    35  func (s *ErrSuite) TestOldCode() {
    36  	s.ErrorIs(OldCodeToMerr(commonpb.ErrorCode_NotReadyServe), ErrServiceNotReady)
    37  	s.ErrorIs(OldCodeToMerr(commonpb.ErrorCode_CollectionNotExists), ErrCollectionNotFound)
    38  	s.ErrorIs(OldCodeToMerr(commonpb.ErrorCode_IllegalArgument), ErrParameterInvalid)
    39  	s.ErrorIs(OldCodeToMerr(commonpb.ErrorCode_NodeIDNotMatch), ErrNodeNotMatch)
    40  	s.ErrorIs(OldCodeToMerr(commonpb.ErrorCode_InsufficientMemoryToLoad), ErrServiceMemoryLimitExceeded)
    41  	s.ErrorIs(OldCodeToMerr(commonpb.ErrorCode_MemoryQuotaExhausted), ErrServiceMemoryLimitExceeded)
    42  	s.ErrorIs(OldCodeToMerr(commonpb.ErrorCode_DiskQuotaExhausted), ErrServiceDiskLimitExceeded)
    43  	s.ErrorIs(OldCodeToMerr(commonpb.ErrorCode_RateLimit), ErrServiceRateLimit)
    44  	s.ErrorIs(OldCodeToMerr(commonpb.ErrorCode_ForceDeny), ErrServiceForceDeny)
    45  	s.ErrorIs(OldCodeToMerr(commonpb.ErrorCode_UnexpectedError), errUnexpected)
    46  }
    47  
    48  func (s *ErrSuite) TestCombine() {
    49  	var (
    50  		errFirst  = errors.New("first")
    51  		errSecond = errors.New("second")
    52  		errThird  = errors.New("third")
    53  	)
    54  
    55  	err := Combine(errFirst, errSecond)
    56  	s.True(errors.Is(err, errFirst))
    57  	s.True(errors.Is(err, errSecond))
    58  	s.False(errors.Is(err, errThird))
    59  
    60  	s.Equal("first: second", err.Error())
    61  }
    62  
    63  func (s *ErrSuite) TestCombineWithNil() {
    64  	err := errors.New("non-nil")
    65  
    66  	err = Combine(nil, err)
    67  	s.NotNil(err)
    68  }
    69  
    70  func (s *ErrSuite) TestCombineOnlyNil() {
    71  	err := Combine(nil, nil)
    72  	s.Nil(err)
    73  }
    74  
    75  func TestErrors(t *testing.T) {
    76  	suite.Run(t, new(ErrSuite))
    77  }