Skip to content

Commit 2ea648b

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; reviewed by João Reis, for CASSGO-59
1 parent f35d463 commit 2ea648b

File tree

6 files changed

+19
-9
lines changed

6 files changed

+19
-9
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
- uses: actions/setup-go@v4
2323
with:
2424
go-version: ${{ matrix.go }}
25-
- run: go vet
25+
- run: go vet ./...
2626
- name: Run unit tests
2727
run: go test -v -tags unit -race
2828
integration-cassandra:

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3939

4040
- Refactor HostInfo creation and ConnectAddress() method (CASSGO-45)
4141

42+
- Refactoring hostpool package test and Expose HostInfo creation (CASSGO-59)
43+
4244
### Fixed
4345
- Cassandra version unmarshal fix (CASSGO-49)
4446

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)