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

     1  package errcore
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  
     7  	"gitlab.com/evatix-go/core/constants"
     8  )
     9  
    10  type ExpectationMessageDef struct {
    11  	CaseIndex         int
    12  	FuncName          string
    13  	TestCaseName      string
    14  	When              string
    15  	Expected          interface{}
    16  	ActualProcessed   interface{}
    17  	ExpectedProcessed interface{}
    18  	IsNonWhiteSort    bool
    19  	expectedString    *string
    20  }
    21  
    22  func (it ExpectationMessageDef) ExpectedSafeString() string {
    23  	if it.expectedString != nil {
    24  		return *it.expectedString
    25  	}
    26  
    27  	var expectedStr string
    28  
    29  	if it.Expected != nil {
    30  		expectedStr = fmt.Sprintf(
    31  			constants.SprintValueFormat,
    32  			it.Expected)
    33  	}
    34  
    35  	it.expectedString = &expectedStr
    36  
    37  	return *it.expectedString
    38  }
    39  
    40  func (it ExpectationMessageDef) ExpectedStringTrim() string {
    41  	return strings.TrimSpace(it.ExpectedString())
    42  }
    43  
    44  func (it ExpectationMessageDef) ExpectedString() string {
    45  	if it.Expected == nil {
    46  		panic("ExpectationMessageDef! Expected needs to be set before getting it!")
    47  	}
    48  
    49  	return it.ExpectedSafeString()
    50  }
    51  
    52  func (it ExpectationMessageDef) ToString(actual interface{}) string {
    53  	return GetWhenActualAndExpectProcessedMessage(
    54  		actual,
    55  		&it)
    56  }
    57  
    58  func (it ExpectationMessageDef) PrintIf(
    59  	isPrint bool,
    60  	actual interface{},
    61  ) {
    62  	if !isPrint {
    63  		return
    64  	}
    65  
    66  	it.Print(actual)
    67  }
    68  
    69  func (it ExpectationMessageDef) PrintIfFailed(
    70  	isPrintOnFail,
    71  	isFailed bool,
    72  	actual interface{},
    73  ) {
    74  	if isPrintOnFail && isFailed {
    75  		it.Print(actual)
    76  	}
    77  }
    78  
    79  func (it ExpectationMessageDef) Print(actual interface{}) {
    80  	msg := MsgHeaderPlusEnding(
    81  		it.When,
    82  		it.ToString(actual))
    83  
    84  	fmt.Println(msg)
    85  }