...

Source file src/edge-infra.dev/pkg/k8s/net/calico/calico_test.go

Documentation: edge-infra.dev/pkg/k8s/net/calico

     1  package net
     2  
     3  import (
     4  	"context"
     5  	"net"
     6  	"os"
     7  	"testing"
     8  
     9  	"github.com/stretchr/testify/assert"
    10  	v1 "k8s.io/api/core/v1"
    11  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    12  
    13  	"edge-infra.dev/test/f2"
    14  )
    15  
    16  var f f2.Framework
    17  
    18  func TestMain(m *testing.M) {
    19  	f = f2.New(context.Background(), f2.WithExtensions()).
    20  		Setup().
    21  		Teardown()
    22  	os.Exit(f.Run(m))
    23  }
    24  
    25  func TestGetNodeIPs(t *testing.T) {
    26  	feature := f2.NewFeature("k8s net get node ip's").
    27  		Test("get single node ip", func(ctx f2.Context, t *testing.T) f2.Context {
    28  			ip, ipNet, err := net.ParseCIDR("10.10.12.1/32")
    29  			assert.NoError(t, err)
    30  
    31  			node := createMockNode(ipNet)
    32  
    33  			actualIP, err := ParseNodeIPs(node)
    34  			assert.NoError(t, err)
    35  
    36  			assert.Equal(t, ip, *actualIP[0])
    37  
    38  			actualIPNet, err := ParseNodeCIDRs(node)
    39  			assert.NoError(t, err)
    40  
    41  			assert.Equal(t, *ipNet, *actualIPNet[0])
    42  
    43  			return ctx
    44  		}).Feature()
    45  
    46  	f.Test(t, feature)
    47  }
    48  
    49  func createMockNode(ip *net.IPNet) v1.Node {
    50  	return v1.Node{
    51  		ObjectMeta: metav1.ObjectMeta{
    52  			Annotations: map[string]string{
    53  				IPAnnotation: ip.String(),
    54  			},
    55  		},
    56  	}
    57  }
    58  

View as plain text