github.com/wfusion/gofusion@v1.1.14/test/mq/cases/construct_test.go (about)

     1  package cases
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/suite"
     8  
     9  	"github.com/wfusion/gofusion/config"
    10  	"github.com/wfusion/gofusion/log"
    11  	"github.com/wfusion/gofusion/mq"
    12  
    13  	testMq "github.com/wfusion/gofusion/test/mq"
    14  )
    15  
    16  func TestConstruct(t *testing.T) {
    17  	testingSuite := &Construct{Test: new(testMq.Test)}
    18  	testingSuite.Init(testingSuite)
    19  	suite.Run(t, testingSuite)
    20  }
    21  
    22  type Construct struct {
    23  	*testMq.Test
    24  }
    25  
    26  func (t *Construct) 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 *Construct) 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 *Construct) TestRaw() {
    39  	t.Catch(func() {
    40  		ctx, cancel := context.WithCancel(context.Background())
    41  		defer cancel()
    42  		name := "Construct_TestRaw"
    43  		confs := map[string]*mq.Conf{
    44  			name: {
    45  				Topic:               name,
    46  				Type:                "gochannel",
    47  				Producer:            true,
    48  				Consumer:            true,
    49  				ConsumerGroup:       name,
    50  				ConsumerConcurrency: 10,
    51  				Endpoint:            nil,
    52  				Persistent:          false,
    53  				SerializeType:       "gob",
    54  				CompressType:        "zstd",
    55  				EnableLogger:        false,
    56  				Logger:              "",
    57  			},
    58  		}
    59  		mq.Construct(ctx, confs, config.AppName(t.AppName()))
    60  		(&Raw{Test: t.Test}).defaultTest(name)
    61  	})
    62  }
    63  
    64  func (t *Construct) TestEvent() {
    65  	t.Catch(func() {
    66  		ctx, cancel := context.WithCancel(context.Background())
    67  		defer cancel()
    68  		name := "Construct_TestEvent"
    69  		confs := map[string]*mq.Conf{
    70  			name: {
    71  				Topic:               name,
    72  				Type:                "gochannel",
    73  				Producer:            true,
    74  				Consumer:            true,
    75  				ConsumerGroup:       name,
    76  				ConsumerConcurrency: 10,
    77  				Endpoint:            nil,
    78  				Persistent:          false,
    79  				SerializeType:       "gob",
    80  				CompressType:        "zstd",
    81  				EnableLogger:        false,
    82  				Logger:              "",
    83  			},
    84  		}
    85  		mq.Construct(ctx, confs, config.AppName(t.AppName()))
    86  		(&Event{Test: t.Test}).defaultTest(name)
    87  	})
    88  }