From 21e316efd14f578b805ce07d9ecaaf04e93cbe30 Mon Sep 17 00:00:00 2001 From: zhangzujian Date: Tue, 3 Dec 2024 03:12:01 +0000 Subject: [PATCH] add unittest for pod routes Signed-off-by: zhangzujian --- pkg/util/pod_routes_test.go | 38 +++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 pkg/util/pod_routes_test.go diff --git a/pkg/util/pod_routes_test.go b/pkg/util/pod_routes_test.go new file mode 100644 index 00000000000..b67bb43b399 --- /dev/null +++ b/pkg/util/pod_routes_test.go @@ -0,0 +1,38 @@ +package util + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestPodRoutes(t *testing.T) { + routes := NewPodRoutes() + require.NotNil(t, routes) + require.Empty(t, routes) + annotations, err := routes.ToAnnotations() + require.NoError(t, err) + require.Len(t, annotations, 0) + + routes.Add("foo", "0.0.0.1", "1.1.1.1") + routes.Add("foo", "0.0.1.0/24", "1.1.1.1") + routes.Add("foo", "0.1.0.0/16", "1.1.1.2") + require.Len(t, routes, 1) + require.Len(t, routes["foo"], 2) + require.Len(t, routes["foo"]["1.1.1.1"], 2) + require.Len(t, routes["foo"]["1.1.1.2"], 1) + annotations, err = routes.ToAnnotations() + require.NoError(t, err) + require.Len(t, annotations, 1) + + routes.Add("bar", "192.168.0.1/32", "2.2.2.2") + require.Len(t, routes, 2) + require.Len(t, routes["foo"], 2) + require.Len(t, routes["foo"]["1.1.1.1"], 2) + require.Len(t, routes["foo"]["1.1.1.2"], 1) + require.Len(t, routes["bar"], 1) + require.Len(t, routes["bar"]["2.2.2.2"], 1) + annotations, err = routes.ToAnnotations() + require.NoError(t, err) + require.Len(t, annotations, 2) +}