github.com/vmware/transport-go@v1.3.4/plank/pkg/server/base_error_test.go (about)

     1  package server
     2  
     3  import (
     4  	"errors"
     5  	"github.com/stretchr/testify/assert"
     6  	"testing"
     7  )
     8  
     9  func TestBaseError_Is_errServerInit(t *testing.T) {
    10  	e := wrapError(errServerInit, errors.New("some init fail"))
    11  	assert.True(t, errors.Is(e, errServerInit))
    12  }
    13  
    14  func TestBaseError_Error_errServerInit(t *testing.T) {
    15  	e := wrapError(errServerInit, errors.New("some init fail"))
    16  	assert.EqualValues(t, "[plank] Error: Server initialization failed: some init fail\n", e.Error())
    17  }
    18  
    19  func TestBaseError_Is_errInternal(t *testing.T) {
    20  	e := wrapError(errInternal, errors.New("internal server error"))
    21  	assert.True(t, errors.Is(e, errInternal))
    22  }
    23  
    24  func TestBaseError_Error_errInternal(t *testing.T) {
    25  	e := wrapError(errInternal, errors.New("internal server error"))
    26  	assert.EqualValues(t, "[plank] Error: Internal error: internal server error\n", e.Error())
    27  }
    28  
    29  func TestBaseError_Is_errHttp(t *testing.T) {
    30  	e := wrapError(errHttp, errors.New("404"))
    31  	assert.True(t, errors.Is(e, errHttp))
    32  }
    33  
    34  func TestBaseError_Error_errHttp(t *testing.T) {
    35  	e := wrapError(errHttp, errors.New("404"))
    36  	assert.EqualValues(t, "[plank] Error: HTTP error: 404\n", e.Error())
    37  }
    38  
    39  func TestBaseError_Is_undefined(t *testing.T) {
    40  	e := wrapError(errors.New("some random stuff"), errors.New("?"))
    41  	assert.True(t, errors.Is(e, errUndefined))
    42  }
    43  
    44  func TestBaseError_Error_undefined(t *testing.T) {
    45  	e := wrapError(errors.New("some random stuff"), errors.New("?"))
    46  	assert.EqualValues(t, "[plank] Error: Undefined error: ?\n", e.Error())
    47  }