-
Notifications
You must be signed in to change notification settings - Fork 630
CASSGO-71 Make HostFilter interface easier to test #1874
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
base: trunk
Are you sure you want to change the base?
Conversation
Currently external HostFilter implementations cannot be tested against HostFilter interface. To fix that the Accept method should have an interface as the parameter instead of HostInfo so that it is possible to mock it. Patch by: Mykyta Oleksiienko; Revieved by: ***; For CASSGO-71.
@joao-r-reis, could you please review the PR? |
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.
Left one comment. Overall LGTM
Set(v string) error | ||
UnmarshalCQL(info TypeInfo, data []byte) error | ||
AtLeast(major, minor, patch int) bool | ||
String() string | ||
} | ||
|
||
// HostFilterFunc converts a func(host HostInfo) bool into a HostFilter |
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 think it also needs to be updated to func(host Host) bool
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.
Added some comments.
I think there's other parts of the public API that need their HostInfo
references changed to Host
like observers, Iter
and policies
@@ -480,6 +480,12 @@ func TestCAS(t *testing.T) { | |||
t.Fatalf("insert should have not been applied: title=%v revID=%v modified=%v", titleCAS, revidCAS, modifiedCAS) | |||
} | |||
|
|||
// TODO: This test failing with error due to "function dateof" on cassandra side. | |||
// It was officially removed in version 5.0.0. The recommended replacement for dateOf is the toTimestamp function. | |||
// As we are not testing against deprecated cassandra versions, it makes sense to update tests to keep them up to date |
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 believe this was done in #1828 so once that is merged and this PR is rebased it should be fixed
@@ -227,9 +227,6 @@ func (s *Session) handleNodeUp(eventIp net.IP, eventPort int) { | |||
return | |||
} | |||
|
|||
if d := host.Version().nodeUpDelay(); d > 0 { |
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.
Why remove this?
Set(v string) error | ||
UnmarshalCQL(info TypeInfo, data []byte) error | ||
AtLeast(major, minor, patch int) bool | ||
String() string |
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 think this needs some changes, just making an interface out of the methods of the private type feels wrong here, we shouldn't expose Set
or Unmarshal
method and we should definitely expose a way to get the actual version fields.
Ideally CassVersion
would be:
type CassVersion interface {
Major() int
Minor() int
Patch() int
Qualifier() string
String() string
}
The methods on cassVersion
can be converted into global private functions.
func (c *cassVersion) Set(v string) error
func (c *cassVersion) UnmarshalCQL(info TypeInfo, data []byte) error
func (c *cassVersion) unmarshal(data []byte) error {
func (c cassVersion) Before(major, minor, patch int) bool
func (c cassVersion) AtLeast(major, minor, patch int) bool
func parseCassVersion(v string) (CassVersion, error) {
c := &cassVersion{}
if v == "" {
return c, nil
}
return c.unmarshalCQL(nil, []byte(v))
}
func (c *cassVersion) unmarshalCQL(info TypeInfo, data []byte) error {
return c.unmarshal(data)
}
// can be kept as is
func (c *cassVersion) unmarshal(data []byte) error
// these two should just be global, private and have `CassVersion` parameters instead
func before(v1 CassVersion, v2 CassVersion) bool
func atLeast(v1 CassVersion, v2 CassVersion) bool
Closes #1311
Currently, external HostFilter implementations cannot be tested against HostFilter interface.
To fix that, the Accept method has an Host interface as the parameter instead of HostInfo so that it is possible to mock it.