forked from fgeller/kt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common_test.go
49 lines (45 loc) · 882 Bytes
/
common_test.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
package main
import (
"fmt"
"testing"
"github.com/IBM/sarama"
"github.com/stretchr/testify/require"
)
func TestChooseKafkaVersion(t *testing.T) {
td := map[string]struct {
arg string
env string
err error
expected sarama.KafkaVersion
}{
"default": {
expected: sarama.V3_0_0_0,
},
"arg v1": {
arg: "v1.0.0",
expected: sarama.V1_0_0_0,
},
"env v2": {
env: "v2.0.0",
expected: sarama.V2_0_0_0,
},
"arg v1 wins over env v2": {
arg: "v1.0.0",
env: "v2.0.0",
expected: sarama.V1_0_0_0,
},
"invalid": {
arg: "234",
err: fmt.Errorf("invalid version `234`"),
},
}
for tn, tc := range td {
actual, err := chooseKafkaVersion(tc.arg, tc.env)
if tc.err == nil {
require.Equal(t, tc.expected, actual, tn)
require.NoError(t, err)
} else {
require.Equal(t, tc.err, err)
}
}
}