codeberg.org/gruf/go-errors/v2@v2.3.1/value_test.go (about)

     1  package errors_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"codeberg.org/gruf/go-errors/v2"
     7  )
     8  
     9  func TestErrorValue(t *testing.T) {
    10  	err := errors.New("base error")
    11  
    12  	err = errors.WithValue(err, "hello", "world")
    13  
    14  	err = errors.WithValue(err, "float", 1.0)
    15  
    16  	err = errors.WithValue(err, "int", 1)
    17  
    18  	err2 := errors.New("second error")
    19  	err = errors.WithValue(err, "error", err2)
    20  
    21  	err = errors.Join(
    22  		err,
    23  		err2,
    24  	)
    25  
    26  	switch {
    27  	case errors.Value(err, "hello") != "world":
    28  		t.Error("failed storing string in error")
    29  
    30  	case errors.Value(err, "float") != 1.0:
    31  		t.Error("failed storing float in error")
    32  
    33  	case errors.Value(err, "int") != 1:
    34  		t.Error("failed storing int in error")
    35  
    36  	case errors.Value(err, "error") != err2:
    37  		t.Error("failed storing error in error")
    38  	}
    39  }