Skip to content

Commit c75ff5f

Browse files
tengu-altjoao-r-reis
authored andcommitted
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 63b6d78 commit c75ff5f

File tree

9 files changed

+32
-10
lines changed

9 files changed

+32
-10
lines changed

.github/workflows/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ 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
27-
run: go test -v -tags unit -race
27+
run: go test -v -tags unit -race ./...
2828
integration-cassandra:
2929
timeout-minutes: 15
3030
needs:

CHANGELOG.md

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

4949
- gocql.Compressor interface changes to follow append-like design. Bumped Go version to 1.19 (CASSGO-1)
5050

51+
- Refactoring hostpool package test and Expose HostInfo creation (CASSGO-59)
52+
5153
### Fixed
5254
- Cassandra version unmarshal fix (CASSGO-49)
5355

conn.go

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

19161916
for _, row := range rows {
1917-
h, err := newHostInfo(c.host.ConnectAddress(), c.session.cfg.Port)
1917+
h, err := NewHostInfo(c.host.ConnectAddress(), c.session.cfg.Port)
19181918
if err != nil {
19191919
goto cont
19201920
}

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: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//go:build all || unit
2+
// +build all unit
3+
14
package hostpool
25

36
import (
@@ -17,12 +20,18 @@ func TestHostPolicy_HostPool(t *testing.T) {
1720
// {hostId: "0", connectAddress: net.IPv4(10, 0, 0, 0)},
1821
// {hostId: "1", connectAddress: net.IPv4(10, 0, 0, 1)},
1922
//}
20-
firstHost := &gocql.HostInfo{}
23+
24+
firstHost, err := gocql.NewHostInfo(net.IPv4(10, 0, 0, 0), 9042)
25+
if err != nil {
26+
t.Errorf("Error creating first host: %v", err)
27+
}
2128
firstHost.SetHostID("0")
22-
firstHost.SetConnectAddress(net.IPv4(10, 0, 0, 0))
23-
secHost := &gocql.HostInfo{}
29+
30+
secHost, err := gocql.NewHostInfo(net.IPv4(10, 0, 0, 1), 9042)
31+
if err != nil {
32+
t.Errorf("Error creating second host: %v", err)
33+
}
2434
secHost.SetHostID("1")
25-
secHost.SetConnectAddress(net.IPv4(10, 0, 0, 1))
2635
hosts := []*gocql.HostInfo{firstHost, secHost}
2736
// Using set host to control the ordering of the hosts as calling "AddHost" iterates the map
2837
// which will result in an unpredictable ordering

internal/lru/lru_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//go:build all || unit
2+
// +build all unit
3+
14
/*
25
Copyright 2015 To gocql authors
36
Copyright 2013 Google Inc.

internal/murmur/murmur_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//go:build all || unit
2+
// +build all unit
3+
14
/*
25
* Licensed to the Apache Software Foundation (ASF) under one
36
* or more contributor license agreements. See the NOTICE file

lz4/lz4_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//go:build all || unit
2+
// +build all unit
3+
14
/*
25
* Licensed to the Apache Software Foundation (ASF) under one
36
* or more contributor license agreements. See the NOTICE file

0 commit comments

Comments
 (0)