github.com/influx6/npkg@v0.8.8/nerror/errors_test.go (about)

     1  package nerror_test
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  
     9  	"github.com/influx6/npkg/nerror"
    10  )
    11  
    12  func TestErrorCallGraph(t *testing.T) {
    13  	newErr := nerror.New("failed connection: %s", "10.9.1.0")
    14  	assert.NotNil(t, newErr.Frames)
    15  	assert.Equal(t, newErr.Message, "failed connection: 10.9.1.0")
    16  }
    17  
    18  func TestErrorWithStack(t *testing.T) {
    19  	newErr := nerror.NewStack("failed connection: %s", "10.9.1.0")
    20  	assert.NotNil(t, newErr.Frames)
    21  	assert.Equal(t, newErr.Message, "failed connection: 10.9.1.0")
    22  }
    23  
    24  func TestErrorWithWrapOnly(t *testing.T) {
    25  	newErr := nerror.WrapOnly(doBad())
    26  	assert.NotNil(t, newErr.Frames)
    27  	assert.Equal(t, "Very bad error", nerror.ErrorMessage(newErr).GetMessage())
    28  	fmt.Println(newErr.String())
    29  }
    30  
    31  func doBad() error {
    32  	return nerror.WrapOnly(doBad2())
    33  }
    34  
    35  func doBad2() error {
    36  	return nerror.WrapOnly(doBad3())
    37  }
    38  
    39  func doBad3() error {
    40  	return nerror.New("Very bad error")
    41  }