Skip to content

Commit

Permalink
adding requireMinimumZkVersion test helper
Browse files Browse the repository at this point in the history
inspiration from #88

cleanup up the logic. but the idea is to support the tests requiring a version of ZK based on the API support in ZK.
  • Loading branch information
jeffbean committed Apr 28, 2024
1 parent 03869bc commit 428c5e2
Showing 1 changed file with 31 additions and 15 deletions.
46 changes: 31 additions & 15 deletions zk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"reflect"
"regexp"
"sort"
"strconv"
"strings"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -186,14 +187,8 @@ func TestIntegration_CreateContainer(t *testing.T) {
}

func TestIntegration_IncrementalReconfig(t *testing.T) {
// todo: semver test harness for version?
if val, ok := os.LookupEnv("zk_version"); ok {
if !strings.HasPrefix(val, "3.5") {
t.Skip("running with zookeeper that does not support this api")
}
} else {
t.Skip("did not detect zk_version from env. skipping reconfig test")
}
requireMinimumZkVersion(t, "3.5")

ts, err := StartTestCluster(t, 3, nil, logWriter{t: t, p: "[ZKERR] "})
requireNoErrorf(t, err, "failed to setup test cluster")
defer ts.Stop()
Expand Down Expand Up @@ -279,13 +274,7 @@ func TestIntegration_IncrementalReconfig(t *testing.T) {
}

func TestIntegration_Reconfig(t *testing.T) {
if val, ok := os.LookupEnv("zk_version"); ok {
if !strings.HasPrefix(val, "3.5") {
t.Skip("running with zookeeper that does not support this api")
}
} else {
t.Skip("did not detect zk_version from env. skipping reconfig test")
}
requireMinimumZkVersion(t, "3.5")

// This test enures we can do an non-incremental reconfig
ts, err := StartTestCluster(t, 3, nil, logWriter{t: t, p: "[ZKERR] "})
Expand Down Expand Up @@ -1195,6 +1184,33 @@ func expectLogMessage(t *testing.T, logger *testLogger, pattern string) {
}
}

func requireMinimumZkVersion(t *testing.T, minimum string) {
t.Helper()

actualVersionStr, ok := os.LookupEnv("ZK_VERSION")
if !ok {
t.Skip("did not detect ZK_VERSION from env. skipping test")
}

parseFn := func(v string) (parts []int) {
for _, s := range strings.Split(v, ".") {
i, err := strconv.Atoi(s)
if err != nil {
t.Fatalf("invalid version segment: %q", s)
}
parts = append(parts, i)
}
return parts
}

minimumV, actualV := parseFn(minimum), parseFn(actualVersionStr)
for i, p := range minimumV {
if actualV[i] < p {
t.Skipf("zookeeper required min version not met; requires: %q, actual: %q", minimum, actualVersionStr)
}
}
}

type testLogger struct {
mu sync.Mutex
events []string
Expand Down

0 comments on commit 428c5e2

Please sign in to comment.