forked from segmentio/kafka-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
version.go
58 lines (52 loc) · 1.28 KB
/
version.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package testing
import (
"os"
"strconv"
"strings"
)
type semver []int
func (v semver) atLeast(other semver) bool {
for i := range v {
if i >= len(other) {
break
}
if v[i] < other[i] {
return false
}
if v[i] > other[i] {
return true
}
}
for i := len(v); i < len(other); i++ {
if other[i] > 0 {
return false
}
}
return true
}
// kafkaVersion is set in the circle config. It can also be provided on the
// command line in order to target a particular kafka version.
var kafkaVersion = parseVersion(os.Getenv("KAFKA_VERSION"))
// KafkaIsAtLeast returns true when the test broker is running a protocol
// version that is semver or newer. It determines the broker's version using
// the `KAFKA_VERSION` environment variable. If the var is unset, then this
// function will return true.
func KafkaIsAtLeast(semver string) bool {
return kafkaVersion.atLeast(parseVersion(semver))
}
func parseVersion(semver string) semver {
if semver == "" {
return nil
}
parts := strings.Split(semver, ".")
version := make([]int, len(parts))
for i := range version {
v, err := strconv.Atoi(parts[i])
if err != nil {
// panic-ing because tests should be using hard-coded version values
panic("invalid version string: " + semver)
}
version[i] = v
}
return version
}