github.com/git-lfs/git-lfs@v2.5.2+incompatible/errors/errors_test.go (about)

     1  package errors
     2  
     3  import (
     4  	"errors"
     5  	"testing"
     6  )
     7  
     8  func TestChecksHandleGoErrors(t *testing.T) {
     9  	err := errors.New("Go Error")
    10  
    11  	if IsFatalError(err) {
    12  		t.Error("go error should not be a fatal error")
    13  	}
    14  }
    15  
    16  func TestCheckHandlesWrappedErrors(t *testing.T) {
    17  	err := errors.New("Go error")
    18  
    19  	fatal := NewFatalError(err)
    20  
    21  	if !IsFatalError(fatal) {
    22  		t.Error("expected error to be fatal")
    23  	}
    24  }
    25  
    26  func TestBehaviorWraps(t *testing.T) {
    27  	err := errors.New("Go error")
    28  
    29  	fatal := NewFatalError(err)
    30  	ni := NewNotImplementedError(fatal)
    31  
    32  	if !IsNotImplementedError(ni) {
    33  		t.Error("expected erro to be not implemeted")
    34  	}
    35  
    36  	if !IsFatalError(ni) {
    37  		t.Error("expected wrapped error to also be fatal")
    38  	}
    39  
    40  	if IsNotImplementedError(fatal) {
    41  		t.Error("expected fatal error to not be not implemented")
    42  	}
    43  }
    44  
    45  func TestContextOnGoErrors(t *testing.T) {
    46  	err := errors.New("Go error")
    47  
    48  	SetContext(err, "foo", "bar")
    49  
    50  	v := GetContext(err, "foo")
    51  	if v == "bar" {
    52  		t.Error("expected empty context on go error")
    53  	}
    54  }
    55  
    56  func TestContextOnWrappedErrors(t *testing.T) {
    57  	err := NewFatalError(errors.New("Go error"))
    58  
    59  	SetContext(err, "foo", "bar")
    60  
    61  	if v := GetContext(err, "foo"); v != "bar" {
    62  		t.Error("expected to be able to use context on wrapped errors")
    63  	}
    64  
    65  	ctxt := Context(err)
    66  	if ctxt["foo"] != "bar" {
    67  		t.Error("expected to get the context of an error")
    68  	}
    69  
    70  	DelContext(err, "foo")
    71  
    72  	if v := GetContext(err, "foo"); v == "bar" {
    73  		t.Errorf("expected to delete from error context")
    74  	}
    75  }