...

Source file src/github.com/hashicorp/go-multierror/prefix_test.go

Documentation: github.com/hashicorp/go-multierror

     1  package multierror
     2  
     3  import (
     4  	"errors"
     5  	"testing"
     6  )
     7  
     8  func TestPrefix_Error(t *testing.T) {
     9  	original := &Error{
    10  		Errors: []error{errors.New("foo")},
    11  	}
    12  
    13  	result := Prefix(original, "bar")
    14  	if result.(*Error).Errors[0].Error() != "bar foo" {
    15  		t.Fatalf("bad: %s", result)
    16  	}
    17  }
    18  
    19  func TestPrefix_NilError(t *testing.T) {
    20  	var err error
    21  	result := Prefix(err, "bar")
    22  	if result != nil {
    23  		t.Fatalf("bad: %#v", result)
    24  	}
    25  }
    26  
    27  func TestPrefix_NonError(t *testing.T) {
    28  	original := errors.New("foo")
    29  	result := Prefix(original, "bar")
    30  	if result == nil {
    31  		t.Fatal("error result was nil")
    32  	}
    33  	if result.Error() != "bar foo" {
    34  		t.Fatalf("bad: %s", result)
    35  	}
    36  }
    37  

View as plain text