I saw that on here, you can have a framework called Mockery generate mocks for interfaces for you. This is close to a big deal, because I am already using testify, which has built-in mock API (which, until now, I have not used yet).
The drawback, however, is that it requires interfaces, whereas the code under test is a struct, with nested dependencies, both business logic and third-party code. I am not in charge of refactoring the code base (thank God), and am looking to mock this
package context
//ApplicationContext The context to use if the use of an application is needed.
type ApplicationContext struct {
DatabaseContext
}
//GetAppId Gets the application id from the session.
func (c *ApplicationContext) GetAppId() int {
if str := c.GetFromSession("ApplicationId"); str != nil {
return str.(int)
}
return -1
}
//SetAppId Sets the application id into the session.
func (c *ApplicationContext) SetAppId(id int) {
c.SetToSession("ApplicationId", id)
}
which extends DatabaseContext
, which has Session.Store
(third-party dependency that is used by those two functions) along with some other dependencies that are none of my concern.
How could I mock this struct?