hotfix: delete old pod (#488)

This commit is contained in:
naison
2025-03-23 17:13:11 +08:00
committed by GitHub
parent b46f7a9877
commit 2ac187eb64
2 changed files with 53 additions and 0 deletions

View File

@@ -2,10 +2,15 @@ package handler
import (
"net"
"reflect"
"sort"
"testing"
"time"
"github.com/google/gopacket/routing"
"github.com/libp2p/go-netroute"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func TestRoute(t *testing.T) {
@@ -149,3 +154,47 @@ func TestRemoveCIDRsContainingIPs(t *testing.T) {
})
}
}
func TestSort(t *testing.T) {
list := v1.PodList{
Items: []v1.Pod{
{
ObjectMeta: metav1.ObjectMeta{
Name: "a",
DeletionTimestamp: nil,
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: "b",
DeletionTimestamp: &metav1.Time{
Time: time.Now(),
},
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: "c",
DeletionTimestamp: nil,
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: "d",
DeletionTimestamp: nil,
},
},
},
}
sort.SliceStable(list.Items, func(i, j int) bool {
return list.Items[i].DeletionTimestamp != nil
})
var names []string
for _, item := range list.Items {
names = append(names, item.Name)
}
equal := reflect.DeepEqual(names, []string{"b", "a", "c", "d"})
if !equal {
t.Fatal()
}
}