This is an automated email from the ASF dual-hosted git repository. joaoreis pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/cassandra-gocql-driver.git
The following commit(s) were added to refs/heads/trunk by this push: new c75ff5f Test fix for hostpool package hostpool package test was refactored to create HostInfo via exported NewhostInfo() constructor. NewHostInfo() was exposed. c75ff5f is described below commit c75ff5f282183704b0921610d55ff3f031f45737 Author: tengu-alt <olexandr.luzh...@gmail.com> AuthorDate: Wed Mar 19 14:02:33 2025 +0200 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 --- .github/workflows/main.yml | 4 ++-- CHANGELOG.md | 2 ++ conn.go | 2 +- control.go | 4 ++-- host_source.go | 4 +++- hostpool/hostpool_test.go | 17 +++++++++++++---- internal/lru/lru_test.go | 3 +++ internal/murmur/murmur_test.go | 3 +++ lz4/lz4_test.go | 3 +++ 9 files changed, 32 insertions(+), 10 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0ca9d20..ab4c136 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -22,9 +22,9 @@ jobs: - uses: actions/setup-go@v4 with: go-version: ${{ matrix.go }} - - run: go vet + - run: go vet ./... - name: Run unit tests - run: go test -v -tags unit -race + run: go test -v -tags unit -race ./... integration-cassandra: timeout-minutes: 15 needs: diff --git a/CHANGELOG.md b/CHANGELOG.md index 351b731..37ae55e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,6 +48,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - gocql.Compressor interface changes to follow append-like design. Bumped Go version to 1.19 (CASSGO-1) +- Refactoring hostpool package test and Expose HostInfo creation (CASSGO-59) + ### Fixed - Cassandra version unmarshal fix (CASSGO-49) diff --git a/conn.go b/conn.go index d2f83d7..114f159 100644 --- a/conn.go +++ b/conn.go @@ -1914,7 +1914,7 @@ func (c *Conn) awaitSchemaAgreement(ctx context.Context) (err error) { } for _, row := range rows { - h, err := newHostInfo(c.host.ConnectAddress(), c.session.cfg.Port) + h, err := NewHostInfo(c.host.ConnectAddress(), c.session.cfg.Port) if err != nil { goto cont } diff --git a/control.go b/control.go index 95ba1c0..113bfaa 100644 --- a/control.go +++ b/control.go @@ -146,7 +146,7 @@ func hostInfo(addr string, defaultPort int) ([]*HostInfo, error) { // Check if host is a literal IP address if ip := net.ParseIP(host); ip != nil { - h, err := newHostInfo(ip, port) + h, err := NewHostInfo(ip, port) if err != nil { return nil, err } @@ -176,7 +176,7 @@ func hostInfo(addr string, defaultPort int) ([]*HostInfo, error) { } for _, ip := range ips { - h, err := newHostInfo(ip, port) + h, err := NewHostInfo(ip, port) if err != nil { return nil, err } diff --git a/host_source.go b/host_source.go index ffe54cf..adcf1a7 100644 --- a/host_source.go +++ b/host_source.go @@ -181,7 +181,9 @@ type HostInfo struct { tokens []string } -func newHostInfo(addr net.IP, port int) (*HostInfo, error) { +// NewHostInfo creates HostInfo with provided connectAddress and port. +// It returns an error if addr is invalid. +func NewHostInfo(addr net.IP, port int) (*HostInfo, error) { if !validIpAddr(addr) { return nil, errors.New("invalid host address") } diff --git a/hostpool/hostpool_test.go b/hostpool/hostpool_test.go index 19b2fb7..1006433 100644 --- a/hostpool/hostpool_test.go +++ b/hostpool/hostpool_test.go @@ -1,3 +1,6 @@ +//go:build all || unit +// +build all unit + package hostpool import ( @@ -17,12 +20,18 @@ func TestHostPolicy_HostPool(t *testing.T) { // {hostId: "0", connectAddress: net.IPv4(10, 0, 0, 0)}, // {hostId: "1", connectAddress: net.IPv4(10, 0, 0, 1)}, //} - firstHost := &gocql.HostInfo{} + + firstHost, err := gocql.NewHostInfo(net.IPv4(10, 0, 0, 0), 9042) + if err != nil { + t.Errorf("Error creating first host: %v", err) + } firstHost.SetHostID("0") - firstHost.SetConnectAddress(net.IPv4(10, 0, 0, 0)) - secHost := &gocql.HostInfo{} + + secHost, err := gocql.NewHostInfo(net.IPv4(10, 0, 0, 1), 9042) + if err != nil { + t.Errorf("Error creating second host: %v", err) + } secHost.SetHostID("1") - secHost.SetConnectAddress(net.IPv4(10, 0, 0, 1)) hosts := []*gocql.HostInfo{firstHost, secHost} // Using set host to control the ordering of the hosts as calling "AddHost" iterates the map // which will result in an unpredictable ordering diff --git a/internal/lru/lru_test.go b/internal/lru/lru_test.go index 0585626..705a246 100644 --- a/internal/lru/lru_test.go +++ b/internal/lru/lru_test.go @@ -1,3 +1,6 @@ +//go:build all || unit +// +build all unit + /* Copyright 2015 To gocql authors Copyright 2013 Google Inc. diff --git a/internal/murmur/murmur_test.go b/internal/murmur/murmur_test.go index b9b818f..c50aa6b 100644 --- a/internal/murmur/murmur_test.go +++ b/internal/murmur/murmur_test.go @@ -1,3 +1,6 @@ +//go:build all || unit +// +build all unit + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/lz4/lz4_test.go b/lz4/lz4_test.go index 379afd4..ea64371 100644 --- a/lz4/lz4_test.go +++ b/lz4/lz4_test.go @@ -1,3 +1,6 @@ +//go:build all || unit +// +build all unit + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org For additional commands, e-mail: commits-h...@cassandra.apache.org