Skip to content

Commit

Permalink
add unittest for pod routes
Browse files Browse the repository at this point in the history
Signed-off-by: zhangzujian <[email protected]>
  • Loading branch information
zhangzujian committed Dec 3, 2024
1 parent 0f95097 commit 21e316e
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions pkg/util/pod_routes_test.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit 21e316e

Please sign in to comment.