...

Source file src/github.com/goph/emperror/handler_testing_test.go

Documentation: github.com/goph/emperror

     1  package emperror
     2  
     3  import (
     4  	"errors"
     5  	"testing"
     6  )
     7  
     8  func TestTestHandler_Count(t *testing.T) {
     9  	handler := NewTestHandler()
    10  
    11  	err1 := errors.New("error 1")
    12  	err2 := errors.New("error 2")
    13  
    14  	handler.Handle(err1)
    15  	handler.Handle(err2)
    16  
    17  	if got, want := handler.Count(), 2; got != want {
    18  		t.Errorf("error count not match the expected one\nactual:   %d\nexpected: %d", got, want)
    19  	}
    20  }
    21  
    22  func TestTestHandler_LastError(t *testing.T) {
    23  	handler := NewTestHandler()
    24  
    25  	err1 := errors.New("error 1")
    26  	err2 := errors.New("error 2")
    27  
    28  	handler.Handle(err1)
    29  	handler.Handle(err2)
    30  
    31  	if got, want := handler.LastError(), err2; got != want {
    32  		t.Errorf("error does not match the expected one\nactual:   %s\nexpected: %s", got, want)
    33  	}
    34  }
    35  
    36  func TestTestHandler_Errors(t *testing.T) {
    37  	handler := NewTestHandler()
    38  
    39  	err1 := errors.New("error 1")
    40  	err2 := errors.New("error 2")
    41  
    42  	handler.Handle(err1)
    43  	handler.Handle(err2)
    44  
    45  	errs := handler.Errors()
    46  
    47  	if got, want := errs[0], err1; got != want {
    48  		t.Errorf("error 1 does not match the expected one\nactual:   %s\nexpected: %s", got, want)
    49  	}
    50  
    51  	if got, want := errs[1], err2; got != want {
    52  		t.Errorf("error 2 does not match the expected one\nactual:   %s\nexpected: %s", got, want)
    53  	}
    54  }
    55  

View as plain text