diff --git a/go/Makefile b/go/Makefile index c9f9db18d0..19cbca177d 100644 --- a/go/Makefile +++ b/go/Makefile @@ -119,7 +119,6 @@ stop-redis-cluster: var-test: @OUTPUT=$$(python3 ../utils/cluster_manager.py start --cluster-mode); \ GLIDE_CLUSTER_NODES=$$(echo "$$OUTPUT" | grep 'CLUSTER_NODES=' | cut -d'=' -f2); \ - echo "=================================================="; \ echo $$GLIDE_CLUSTER_NODES # example tests - skip complete IT suite (including MT) @@ -127,9 +126,10 @@ example-test: mkdir -p reports set -o pipefail; \ ../utils/cluster_manager.py start -p 6379 -r 0 - ../utils/cluster_manager.py start --cluster-mode -p 7001 7002 7003 7004 7005 7006 + @OUTPUT=$$(python3 ../utils/cluster_manager.py start --cluster-mode); \ + GLIDE_CLUSTER_NODES=$$(echo "$$OUTPUT" | grep 'CLUSTER_NODES=' | cut -d'=' -f2); \ LD_LIBRARY_PATH=$(shell find . -name libglide_rs.a|grep -w release|tail -1|xargs dirname|xargs readlink -f):${LD_LIBRARY_PATH} \ - go test -v -race ./api -skip Test $(if $(test-filter), -run $(test-filter)) -standalonenode 127.0.0.1:6379 -clusternodes 127.0.0.1:7006,127.0.0.1:7004,127.0.0.1:7001,127.0.0.1:7002,127.0.0.1:7003,127.0.0.1:7005 \ + go test -v ./api -skip Test $(if $(test-filter), -run $(test-filter)) -clusternodes $$GLIDE_CLUSTER_NODES \ | tee >(go tool test2json -t -p github.com/valkey-io/valkey-glide/go/api \ | go-test-report -o reports/example-tests.html -t example-test > /dev/null) diff --git a/go/api/example_utils.go b/go/api/example_utils.go index bb38889d54..13430a6599 100644 --- a/go/api/example_utils.go +++ b/go/api/example_utils.go @@ -5,11 +5,12 @@ package api import ( "flag" "fmt" + "strconv" + "strings" "sync" ) var clusterNodes = flag.String("clusternodes", "", "AddressNodes for running Valkey/Redis cluster nodes") -var standaloneNode = flag.String("standalonenode", "", "Address for running Valkey/Redis standalone node") var clusterClient *GlideClusterClient var clusterOnce sync.Once @@ -51,8 +52,9 @@ func getExampleGlideClient() *GlideClient { func getExampleGlideClusterClient() *GlideClusterClient { clusterOnce.Do(func() { + addresses := parseHosts(*clusterNodes) config := NewGlideClusterClientConfiguration(). - WithAddress(&NodeAddress{Host: "localhost", Port: 7001}). + WithAddress(&addresses[0]). WithRequestTimeout(5000) client, err := NewGlideClusterClient(config) @@ -71,3 +73,20 @@ func getExampleGlideClusterClient() *GlideClusterClient { return clusterClient } + +func parseHosts(addresses string) []NodeAddress { + var result []NodeAddress + + addressList := strings.Split(addresses, ",") + for _, address := range addressList { + parts := strings.Split(address, ":") + port, err := strconv.Atoi(parts[1]) + if err != nil { + fmt.Printf("Failed to parse port from string %s: %s", parts[1], err.Error()) + continue + } + + result = append(result, NodeAddress{Host: parts[0], Port: port}) + } + return result +}