forked from cilium/cilium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkvstore_watchdog_test.go
146 lines (140 loc) · 3 KB
/
kvstore_watchdog_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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// SPDX-License-Identifier: Apache-2.0
// Copyright Authors of Cilium
//go:build !privileged_tests
// +build !privileged_tests
package main
import (
"reflect"
"testing"
"github.com/cilium/cilium/pkg/kvstore"
)
func Test_getOldestLeases(t *testing.T) {
type args struct {
m map[string]kvstore.Value
}
tests := []struct {
name string
args args
want map[string]kvstore.Value
}{
{
name: "test-1",
args: args{
m: map[string]kvstore.Value{},
},
want: map[string]kvstore.Value{},
},
{
name: "test-2",
args: args{
m: map[string]kvstore.Value{
"foo/bar/1": {
Data: nil,
ModRevision: 1,
LeaseID: 1,
},
"foo/bar/2": {
Data: nil,
ModRevision: 2,
LeaseID: 2,
},
"foo/bar/3": {
Data: nil,
ModRevision: 3,
LeaseID: 3,
},
"foo/bar/4": {
Data: nil,
ModRevision: 4,
LeaseID: 4,
},
"foo/bar/5": {
Data: nil,
ModRevision: 5,
LeaseID: 5,
},
"foo/baz/6": {
Data: nil,
ModRevision: 6,
LeaseID: 6,
},
"foo/bbz/7": {
Data: nil,
ModRevision: 3,
LeaseID: 3,
},
},
},
want: map[string]kvstore.Value{
"foo/bar/1": {
Data: nil,
ModRevision: 1,
LeaseID: 1,
},
"foo/baz/6": {
Data: nil,
ModRevision: 6,
LeaseID: 6,
},
"foo/bbz/7": {
Data: nil,
ModRevision: 3,
LeaseID: 3,
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := getOldestLeases(tt.args.m); !reflect.DeepEqual(got, tt.want) {
t.Errorf("getOldestLeases() = %v, want %v", got, tt.want)
}
})
}
}
func Test_getPath(t *testing.T) {
type args struct {
k string
}
tests := []struct {
name string
args args
want string
}{
{
name: "test-1",
args: args{
k: "cilium/state/identities/v1/locks/" +
"k8s:io.cilium.k8s.policy.cluster=default;" +
"k8s:io.cilium.k8s.policy.serviceaccount=default;" +
"k8s:io.kubernetes.pod.namespace=default;k8s:k8s-app.guestbook=redis;" +
"k8s:role=master;" +
"/29c66fd840fa06f7",
},
want: "cilium/state/identities/v1/locks/" +
"k8s:io.cilium.k8s.policy.cluster=default;" +
"k8s:io.cilium.k8s.policy.serviceaccount=default;" +
"k8s:io.kubernetes.pod.namespace=default;k8s:k8s-app.guestbook=redis;" +
"k8s:role=master;",
},
{
name: "test-2",
args: args{
k: "cilium/state/identities/v1/locks/" +
"k8s:io.cilium.k8s.policy.cluster=default;" +
"k8s:role=master/////;" +
"/29c66fd840fa06f7",
},
want: "cilium/state/identities/v1/locks/" +
"k8s:io.cilium.k8s.policy.cluster=default;" +
"k8s:role=master/////;",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := keyPathFromLockPath(tt.args.k); got != tt.want {
t.Errorf("keyPathFromLockPath() = %v, want %v", got, tt.want)
}
})
}
}