I have troubles with mocking.. I have same code:
type OtherInterface interface {
Do() error
}
type MyInterface interface {
MethodA() error
MethodB() error
}
type MyStruct struct {
OtherStruct OtherInterface
}
func(s *MyStruct) MethodA() error {
return s.MethodB()
}
func(s *MyStruct) MethodB() error {
return s.OtherStruct.Do()
}
And test code of MethodB:
type MockOtherStruct struct {
Do_Error error
}
func (t *MockOtherStruct) Do() error {return t.Do_Error}
TestMyStruct_MethodB(t *testing.B) {
expectedError = nil
mos := &MockOtherStruct{
Do_Error: nil
}
ms := MyStruct{
OtherStruct: mos,
}
err := ms.MethodB()
if err != expectedError {
t.Fatal(err)
}
}
But how can I test MethodA?
Yes, I can also mock OtherStruct and use not mocked MethodB, but in big structs I can have many fields with other structs, but use one internal method..