github.com/wfusion/gofusion@v1.1.14/test/common/utils/cases/func_test.go (about)

     1  package cases
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/suite"
     8  	"github.com/wfusion/gofusion/test/internal/mock"
     9  
    10  	"github.com/wfusion/gofusion/common/utils"
    11  	"github.com/wfusion/gofusion/common/utils/serialize"
    12  	"github.com/wfusion/gofusion/log"
    13  	testUtl "github.com/wfusion/gofusion/test/common/utils"
    14  )
    15  
    16  func TestFunc(t *testing.T) {
    17  	t.Parallel()
    18  	testingSuite := &Func{Test: new(testUtl.Test)}
    19  	suite.Run(t, testingSuite)
    20  }
    21  
    22  type Func struct {
    23  	*testUtl.Test
    24  }
    25  
    26  func (t *Func) BeforeTest(suiteName, testName string) {
    27  	t.Catch(func() {
    28  		log.Info(context.Background(), "right before %s %s", suiteName, testName)
    29  	})
    30  }
    31  
    32  func (t *Func) AfterTest(suiteName, testName string) {
    33  	t.Catch(func() {
    34  		log.Info(context.Background(), "right after %s %s", suiteName, testName)
    35  	})
    36  }
    37  
    38  func (t *Func) TestWrapFuncMissInAndOutMatch() {
    39  	t.Catch(func() {
    40  		// Given
    41  		ctx := context.Background()
    42  		obj := mock.GenObjBySerializeAlgo(serialize.AlgorithmGob).(*mock.RandomObj)
    43  		hd := func(paramCtx context.Context, paramObj *mock.CommonObj) {
    44  			t.EqualValues(ctx, paramCtx)
    45  			t.EqualValues(obj.Basic.Str, paramObj.Basic.Str)
    46  		}
    47  		wrapper := utils.WrapFunc1[error](hd)
    48  
    49  		// When
    50  		err := wrapper(ctx, obj)
    51  		t.NoError(err)
    52  	})
    53  }