forked from go-zookeeper/zk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_mode_test.go
43 lines (39 loc) · 1.07 KB
/
create_mode_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
package zk
import (
"strings"
"testing"
)
func TestParseCreateMode(t *testing.T) {
changeDetectorTests := []struct {
name string
flag int32
wantIntValue int32
}{
{"valid flag createmode 0 persistant", FlagPersistent, 0},
{"ephemeral", FlagEphemeral, 1},
{"sequential", FlagSequence, 2},
{"ephemeral sequential", FlagEphemeralSequential, 3},
{"container", FlagContainer, 4},
{"ttl", FlagTTL, 5},
{"persistentSequential w/TTL", FlagPersistentSequentialWithTTL, 6},
}
for _, tt := range changeDetectorTests {
t.Run(tt.name, func(t *testing.T) {
cm, err := parseCreateMode(tt.flag)
requireNoErrorf(t, err)
if cm.flag != tt.wantIntValue {
// change detector test for enum values.
t.Fatalf("createmode value of flag; want: %v, got: %v", cm.flag, tt.wantIntValue)
}
})
}
t.Run("failed to parse", func(t *testing.T) {
cm, err := parseCreateMode(-123)
if err == nil {
t.Fatalf("error expected, got: %v", cm)
}
if !strings.Contains(err.Error(), "invalid flag value") {
t.Fatalf("unexpected error value: %v", err)
}
})
}