Skip to content

Commit a323a8f

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 a323a8f

File tree

9 files changed

+34
-12
lines changed

9 files changed

+34
-12
lines changed

.github/workflows/main.yml

Lines changed: 4 additions & 4 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:
@@ -110,7 +110,7 @@ jobs:
110110
run: |
111111
source ~/venv/bin/activate
112112
export JVM_EXTRA_OPTS="${{env.JVM_EXTRA_OPTS}}"
113-
go test -v -tags "${{ matrix.tags }} gocql_debug" -timeout=5m -race ${{ env.args }}
113+
go test -v -tags "${{ matrix.tags }} gocql_debug" -timeout=5m -race ${{ env.args }} ./...
114114
- name: 'Save ccm logs'
115115
if: 'failure()'
116116
uses: actions/upload-artifact@v4
@@ -202,4 +202,4 @@ jobs:
202202
run: |
203203
source ~/venv/bin/activate
204204
export JVM_EXTRA_OPTS="${{env.JVM_EXTRA_OPTS}}"
205-
go test -v -run=TestAuthentication -tags "${{ matrix.tags }} gocql_debug" -timeout=15s -runauth ${{ env.args }}
205+
go test -v -run=TestAuthentication -tags "${{ matrix.tags }} gocql_debug" -timeout=15s -runauth ${{ env.args }} ./...

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: 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)