github.com/agiledragon/gomonkey/v2@v2.11.1-0.20240427155748-d56c6823ec17/dsl/behavior.go (about)

     1  package dsl
     2  
     3  import . "github.com/agiledragon/gomonkey/v2"
     4  
     5  type Behavior interface {
     6  	Apply() []Params
     7  }
     8  
     9  type ReturnBehavior struct {
    10  	rets   []Params
    11  	params Params
    12  }
    13  
    14  func (this *ReturnBehavior) Apply() []Params {
    15  	this.rets = append(this.rets, this.params)
    16  	return this.rets
    17  }
    18  
    19  type RepeatBehavior struct {
    20  	rets     []Params
    21  	behavior Behavior
    22  	times    int
    23  }
    24  
    25  func (this *RepeatBehavior) Apply() []Params {
    26  	for i := 0; i < this.times; i++ {
    27  		this.rets = append(this.rets, this.behavior.Apply()[0])
    28  	}
    29  	return this.rets
    30  }