gitlab.com/evatix-go/core@v1.3.55/errcore/shouldBe.go (about)

     1  package errcore
     2  
     3  import (
     4  	"encoding/json"
     5  	"errors"
     6  	"fmt"
     7  )
     8  
     9  type shouldBe struct{}
    10  
    11  func (it shouldBe) StrEqMsg(actual, expecting string) string {
    12  	return fmt.Sprintf(
    13  		ShouldBeMessageFormat,
    14  		actual,
    15  		expecting)
    16  }
    17  
    18  func (it shouldBe) StrEqErr(actual, expecting string) error {
    19  	msg := it.StrEqMsg(expecting, actual)
    20  
    21  	return errors.New(msg)
    22  }
    23  
    24  func (it shouldBe) AnyEqMsg(actual, expecting interface{}) string {
    25  	return fmt.Sprintf(
    26  		ShouldBeMessageFormat,
    27  		actual,
    28  		expecting)
    29  }
    30  
    31  func (it shouldBe) AnyEqErr(actual, expecting interface{}) error {
    32  	msg := it.AnyEqMsg(expecting, actual)
    33  
    34  	return errors.New(msg)
    35  }
    36  
    37  func (it shouldBe) JsonEqMsg(actual, expecting interface{}) string {
    38  	actualJson, err := json.Marshal(actual)
    39  	MustBeEmpty(err)
    40  
    41  	expectingJson, expectingErr := json.Marshal(expecting)
    42  	MustBeEmpty(expectingErr)
    43  
    44  	return fmt.Sprintf(
    45  		ShouldBeMessageFormat,
    46  		actualJson,
    47  		expectingJson)
    48  }
    49  
    50  func (it shouldBe) JsonEqErr(actual, expecting interface{}) error {
    51  	msg := it.JsonEqMsg(expecting, actual)
    52  
    53  	return errors.New(msg)
    54  }