Revision d75aa385a9fee027b9d35f96e63e5f78c12c8f50 authored by Martynas Pumputis on 22 November 2021, 19:12:17 UTC, committed by Martynas Pumputis on 23 November 2021, 15:36:25 UTC
Signed-off-by: Martynas Pumputis <m@lambda.lt>
1 parent ef1068f
kvstore_watchdog_test.go
// Copyright 2020 Authors of Cilium
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// +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)
}
})
}
}
![swh spinner](/static/img/swh-spinner.gif)
Computing file changes ...