Golang calling a function without implementation

Viewed 35

I'm very new to Golang and I recently stumbled across this neat package for testing called "testify". And in it, I noticed that all you have to do is add an additional mock object to our testing struct:

type MyTestObject struct {
     // add a Mock object instance
     mock.Mock
     // other fields go here as normal
}

And out of nowhere, we're allowed to call a function named called

func (o *MyTestObject) SavePersonDetails(firstname, lastname string, age int) (int, error) {
  args := o.Called(firstname, lastname, age)
  return args.Int(0), args.Error(1)
}

As a new Golang programmer, this completely throws me off. How does this work? How, by just adding another field in the struct, are we allowed to call a function that we did not implement? Did I miss an important lesson in Golang here? Is this a thing I can do in my programs too? If so, can someone point me at a tutorial/description of how to do this?

0 Answers
Related