Skip to content

Conversation

@OleksiienkoMykyta
Copy link
Contributor

@OleksiienkoMykyta OleksiienkoMykyta commented Apr 2, 2025

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.

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.
@OleksiienkoMykyta
Copy link
Contributor Author

@joao-r-reis, could you please review the PR?

Copy link
Contributor

@tengu-alt tengu-alt left a 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

String() string
}

// HostFilterFunc converts a func(host HostInfo) bool into a HostFilter
Copy link
Contributor

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

@joao-r-reis joao-r-reis changed the title Make HostFilter interface easier to test CASSGO-71 Make HostFilter interface easier to test Apr 21, 2025
Copy link
Contributor

@joao-r-reis joao-r-reis left a 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


// 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
Copy link
Contributor

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

return
}

if d := host.Version().nodeUpDelay(); d > 0 {
Copy link
Contributor

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
Copy link
Contributor

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

@joao-r-reis
Copy link
Contributor

@OleksiienkoMykyta do you have time to address my review comments? We're trying to resolve the pending PRs for the 2.0 release

@joao-r-reis
Copy link
Contributor

After discussing with @jameshartig I've opened #1892 as an alternative

@joao-r-reis
Copy link
Contributor

Closed in favor of #1892

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CASSGO-71 External HostFilter implementations cannot be tested against HostFilter interface

3 participants