Thursday, February 29, 2024
HomeGolangPlease assist my make Mock Operate to AddVector - Getting Assist

Please assist my make Mock Operate to AddVector – Getting Assist


sort VectorService interface {
    AddVector() [2]int
}

sort InitService struct{
         x    int
	     y    int
}

sort MyService struct {
    VService VectorService
}

func (sms InitService) AddVector() [2]int {
    var b [2]int
	b[0] = sms.x + 100
	b[1] = sms.y + 200
    return b
}

func (a MyService) ChargeVector(x int, y int) [2]int {
    r := a.VService.AddVector()
	var b [2]int
	b[0] = r[0] + 10 
	b[1] = r[1] + 22
    return b
}

func foremost() {
    myService := MyService{InitService{1,2}}
    a := myService.ChargeVector(100, 200)
	fmt.Printf("Charging Buyer For the worth of %d  %dn", a[0], a[1])
}

Check PASS, however now I need use InitServiceMock with X and Y filed How I can do it?

   sort InitServiceMock struct {
          mock.Mock
   }

   func (sms *InitServiceMock) AddToVector() [2]int {
    fmt.Println("Mocked cost notification perform")
	fmt.Printf("Charging Buyer For the worth of -- %d --  %d -- n", 100, 200)
	

	var b [2]int
 	b[0] = 100
	b[1] = 200

	return  b
   }

    func TestChargeCustomer(t *testing.T) {

   	var b [2]int
   	b[0] = 101
  	b[1] = 202
	
	smsService := new(InitServiceMock)
   	smsService.On("AddToVector").Return(b)
	
 	myService := check.MyService{check.InitService{1,2}}
    a := myService.ChargeVector(100,200)

    assert.Equal(t, a[0], 111, "One")
	assert.Equal(t, a[1], 224, "Two")
	
	fmt.Printf("Charging Buyer For the worth of %d  %dn", a[0], a[1])
   }

I solved this drawback. Thank you numerous!

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments