good41898 commented on PR #1786:
URL: https://github.com/apache/tinkerpop/pull/1786#issuecomment-1219753208
To give an example of the issue, I have abstracted the gremlin-go driver
into an interface like this:
```
GremlinGoDriver interface {
Submit(traversalString string) (gremlingo.ResultSet, error)
Close()
}
```
Which contains the two methods of the driver that I use. While unit testing,
I am able to mock out any methods (like the Submit() and Close() method) as
long as the function signatures for the mocked methods match the signatures of
the actual methods. Where I am running into issues is when trying to mock
returned data from a `ResultSet` object. I am able to create a new struct
containing the result set so I can mock those methods (like the ResultSet.All()
method) as well, like this:
```
type MockResultSet struct {
ResultSet
}
func (m MockResultSet) All() ([]*Result, error) {
var res []*Result
return res
}
```
However, since the function signatures must match, this mocked All() method
must return a Result object, which I cannot assign data to as the result field
is non-exported.
Let me know if this is helpful/ makes sense. Thanks.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]