How to mock/stub nested struct function without using interface?

Viewed 21

I am trying to write a UT in go for the first time. I am in a situation where I want to mock a nested structure function. I will describe the scenario with an example code:

type C struct {
...
r *R,
...
}

type P struct {
c *C
}

func (p *P) doSomething(...) {
...
p.c.r.Load(...)
...
}

Here I am trying to mock p.r.c.Load() function. Any way to achieve this in go?

Important Note: We can use interfaces in go to achieve it but I cannot change the business logic.

Thanks in Advance

We can use interfaces in go to achieve it but I cannot change the business logic.

0 Answers
Related