-
Notifications
You must be signed in to change notification settings - Fork 642
CASSGO-71 Add way to create HostInfo objects for testing purposes #1892
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CASSGO-71 Add way to create HostInfo objects for testing purposes #1892
Conversation
5d5f2be to
7a91ba4
Compare
jameshartig
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few minor comments
host_source.go
Outdated
| // | ||
| // If you're looking for a way to create a HostInfo object with more than just an address and port for | ||
| // testing purposes then you can use NewTestHostInfoFromRow | ||
| func NewHostInfoFromContactPoint(addr net.IP, port int) (*HostInfo, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: What's the reason behind "ContactPoint"? What about "NewHostInfoFromAddrPort"? Not terribly opposed with contact point though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked and the only time we create host info objects from Addr and Port is during init when we are converting contact points into HostPoints, everywhere else we always use the row from the system table. I'm ok with changing to NewHostInfoFromAddrPort though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed it
| // "native_port": 9042, | ||
| // } | ||
| // host, err := NewTestHostInfoFromRow(row) | ||
| func NewTestHostInfoFromRow(row map[string]interface{}) (*HostInfo, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we have the same method on *Session too so it could still call AddressTranslator?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is meant to be used for unit testing implementations of policies and other gocql public interfaces I don't think users will be using it with a session so I don't think it's necessary to involve the address translator. Maybe we can consider it if we get requests for it in the future?
fcc8b35 to
ebe9a0d
Compare
It is not possible to test implementations of public gocql interfaces such as HostFilter because it requires creating HostInfo objects (HostInfo has private fields). With this change, it is now possible to create HostInfo objects from system.local / system.peers rows using NewTestHostInfoFromRow(). Patch by João Reis; reviewed by James Hartig for CASSGO-71
ebe9a0d to
8b51c53
Compare
Also renamed NewHostInfo to NewHostInfoFromContactPoint, this isn't a breaking change because this function was exported recently and no release has gone out since then.
What is a breaking change is making
host.SetHostIDprivate, I don't see why we would let users modify the host id