github.com/iDigitalFlame/xmt@v0.5.4/util/xerr/xerr_test.go (about)

     1  //go:build !implant && go1.13
     2  // +build !implant,go1.13
     3  
     4  // Copyright (C) 2020 - 2023 iDigitalFlame
     5  //
     6  // This program is free software: you can redistribute it and/or modify
     7  // it under the terms of the GNU General Public License as published by
     8  // the Free Software Foundation, either version 3 of the License, or
     9  // any later version.
    10  //
    11  // This program is distributed in the hope that it will be useful,
    12  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    13  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    14  // GNU General Public License for more details.
    15  //
    16  // You should have received a copy of the GNU General Public License
    17  // along with this program.  If not, see <https://www.gnu.org/licenses/>.
    18  //
    19  
    20  package xerr
    21  
    22  import (
    23  	"errors"
    24  	"io"
    25  	"testing"
    26  )
    27  
    28  func TestErrorNew(t *testing.T) {
    29  	if v := New("test error").Error(); v != "test error" {
    30  		t.Fatalf(`TestErrorNew(): Error() "%s" did not match the given string value!`, v)
    31  	}
    32  }
    33  func TestErrorSub(t *testing.T) {
    34  	if v := Sub("test error", 0xFA).Error(); v != "test error" && v != "0xFA" {
    35  		t.Fatalf(`TestErrorSub(): Error() "%s" did not match the given string value!`, v)
    36  	}
    37  }
    38  func TestErrorWrap(t *testing.T) {
    39  	if e := Wrap("test error", io.EOF); !errors.Is(e, io.EOF) && !errors.Is(errors.Unwrap(e), io.EOF) {
    40  		t.Fatalf(`TestErrorWrap(): Wrapped error "%s" did not match the given wrapped error!`, e)
    41  	}
    42  	if e := Wrap("test error", io.EOF); e.Error() != "test error: EOF" {
    43  		t.Fatalf(`TestErrorWrap(): Wrapped error string "%s" did not match the given error string!`, e)
    44  	}
    45  }