Skip to content

Commit 94a6707

Browse files
committed
Test fix for hostpool package
hostpool package test was refactored to create HostInfo via exported NewhostInfo() constructor. NewHostInfo() was exposed. patch by Oleksandr Luzhniy; for CASSGO-59
1 parent 65e2caf commit 94a6707

File tree

4 files changed

+16
-8
lines changed

4 files changed

+16
-8
lines changed

conn.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1690,7 +1690,7 @@ func (c *Conn) awaitSchemaAgreement(ctx context.Context) (err error) {
16901690
}
16911691

16921692
for _, row := range rows {
1693-
h, err := newHostInfo(c.host.ConnectAddress(), c.session.cfg.Port)
1693+
h, err := NewHostInfo(c.host.ConnectAddress(), c.session.cfg.Port)
16941694
if err != nil {
16951695
goto cont
16961696
}

control.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ func hostInfo(addr string, defaultPort int) ([]*HostInfo, error) {
146146

147147
// Check if host is a literal IP address
148148
if ip := net.ParseIP(host); ip != nil {
149-
h, err := newHostInfo(ip, port)
149+
h, err := NewHostInfo(ip, port)
150150
if err != nil {
151151
return nil, err
152152
}
@@ -176,7 +176,7 @@ func hostInfo(addr string, defaultPort int) ([]*HostInfo, error) {
176176
}
177177

178178
for _, ip := range ips {
179-
h, err := newHostInfo(ip, port)
179+
h, err := NewHostInfo(ip, port)
180180
if err != nil {
181181
return nil, err
182182
}

host_source.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,9 @@ type HostInfo struct {
181181
tokens []string
182182
}
183183

184-
func newHostInfo(addr net.IP, port int) (*HostInfo, error) {
184+
// NewHostInfo creates HostInfo with provided connectAddress and port.
185+
// It returns an error if addr is invalid.
186+
func NewHostInfo(addr net.IP, port int) (*HostInfo, error) {
185187
if !validIpAddr(addr) {
186188
return nil, errors.New("invalid host address")
187189
}

hostpool/hostpool_test.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,18 @@ func TestHostPolicy_HostPool(t *testing.T) {
1717
// {hostId: "0", connectAddress: net.IPv4(10, 0, 0, 0)},
1818
// {hostId: "1", connectAddress: net.IPv4(10, 0, 0, 1)},
1919
//}
20-
firstHost := &gocql.HostInfo{}
20+
21+
firstHost, err := gocql.NewHostInfo(net.IPv4(10, 0, 0, 0), 9042)
22+
if err != nil {
23+
t.Errorf("Error creating first host: %v", err)
24+
}
2125
firstHost.SetHostID("0")
22-
firstHost.SetConnectAddress(net.IPv4(10, 0, 0, 0))
23-
secHost := &gocql.HostInfo{}
26+
27+
secHost, err := gocql.NewHostInfo(net.IPv4(10, 0, 0, 1), 9042)
28+
if err != nil {
29+
t.Errorf("Error creating second host: %v", err)
30+
}
2431
secHost.SetHostID("1")
25-
secHost.SetConnectAddress(net.IPv4(10, 0, 0, 1))
2632
hosts := []*gocql.HostInfo{firstHost, secHost}
2733
// Using set host to control the ordering of the hosts as calling "AddHost" iterates the map
2834
// which will result in an unpredictable ordering

0 commit comments

Comments
 (0)