joao-r-reis commented on code in PR #1892:
URL:
https://github.com/apache/cassandra-gocql-driver/pull/1892#discussion_r2149914600
##########
host_source.go:
##########
@@ -492,17 +497,42 @@ func checkSystemSchema(control *controlConn) (bool,
error) {
return true, nil
}
-func (s *Session) newHostInfoFromMap(addr net.IP, port int, row
map[string]interface{}) (*HostInfo, error) {
- return s.hostInfoFromMap(row, &HostInfo{connectAddress: addr, port:
port})
-}
-
// Given a map that represents a row from either system.local or system.peers
// return as much information as we can in *HostInfo
-func (s *Session) hostInfoFromMap(row map[string]interface{}, host *HostInfo)
(*HostInfo, error) {
+func (s *Session) newHostInfoFromMap(addr net.IP, port int, row
map[string]interface{}) (*HostInfo, error) {
+ return newHostInfoFromRow(s, addr, port, row)
+}
+
+// NewTestHostInfoFromRow creates a new HostInfo object from a system.peers or
system.local row. The port
+// defaults to 9042.
+//
+// You can create a HostInfo object for testing purposes using this function:
+//
+// Example usage:
+//
+// row := map[string]interface{}{
+// "broadcast_address": net.ParseIP("10.0.0.1"),
+// "listen_address": net.ParseIP("10.0.0.1"),
+// "rpc_address": net.ParseIP("10.0.0.1"),
+// "peer": net.ParseIP("10.0.0.1"), // system.peers
only
+// "data_center": "dc1",
+// "rack": "rack1",
+// "host_id": MustRandomUUID(), // can also use
ParseUUID("550e8400-e29b-41d4-a716-446655440000")
+// "release_version": "4.0.0",
+// "native_port": 9042,
+// }
+// host, err := NewTestHostInfoFromRow(row)
+func NewTestHostInfoFromRow(row map[string]interface{}) (*HostInfo, error) {
Review Comment:
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?
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]