github.com/mgoltzsche/ctnr@v0.7.1-alpha/pkg/errors/typed_test.go (about)

     1  package errors
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	orgerrors "github.com/pkg/errors"
     8  	"github.com/stretchr/testify/require"
     9  )
    10  
    11  func TestTyped(t *testing.T) {
    12  	tname := "testtype"
    13  	for _, err := range []error{Typed(tname, "test msg"), Typedf(tname, "test %s", "msg")} {
    14  		require.Error(t, err)
    15  		s := err.Error()
    16  		if s != "test msg" {
    17  			t.Errorf("Error() returned %q", s)
    18  		}
    19  		sf := fmt.Sprintf("%+v", err)
    20  		if s == sf || len(sf) == 0 {
    21  			t.Error("Format() not implemented properly")
    22  		}
    23  		if HasType(err, "unknowntype") {
    24  			t.Errorf("HasType(unknown, type) must return false")
    25  		}
    26  		if !HasType(err, tname) {
    27  			t.Errorf("HasType(err, type) must return true")
    28  		}
    29  		err = orgerrors.Wrap(err, "wrapped")
    30  		if !HasType(err, tname) {
    31  			t.Errorf("HasType(Wrap(err), type) must return true")
    32  		}
    33  	}
    34  }