github.com/openshift/installer@v1.4.17/pkg/types/utils_test.go (about)

     1  package types
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  
     8  	configv1 "github.com/openshift/api/config/v1"
     9  	"github.com/openshift/installer/pkg/ipnet"
    10  )
    11  
    12  // TestStringsToIPs tests the StringsToIPs function.
    13  func TestStringsToIPs(t *testing.T) {
    14  	testcases := []struct {
    15  		ips      []string
    16  		expected []configv1.IP
    17  	}{
    18  		{
    19  			[]string{"10.0.0.1", "10.0.0.2"},
    20  			[]configv1.IP{"10.0.0.1", "10.0.0.2"},
    21  		},
    22  		{
    23  			[]string{},
    24  			[]configv1.IP{},
    25  		},
    26  		{
    27  			[]string{"fe80:1:2:3::"},
    28  			[]configv1.IP{"fe80:1:2:3::"},
    29  		},
    30  	}
    31  
    32  	for _, tc := range testcases {
    33  		res := StringsToIPs(tc.ips)
    34  		assert.Equal(t, tc.expected, res, "conversion failed")
    35  	}
    36  }
    37  
    38  // TestMachineNetworksToCIDRs tests the MachineNetworksToCIDRs function.
    39  func TestMachineNetworksToCIDRs(t *testing.T) {
    40  	testcases := []struct {
    41  		networks []MachineNetworkEntry
    42  		expected []configv1.CIDR
    43  	}{
    44  		{
    45  			[]MachineNetworkEntry{
    46  				{CIDR: *ipnet.MustParseCIDR("10.0.0.1/32")},
    47  				{CIDR: *ipnet.MustParseCIDR("10.0.0.2/32")},
    48  			},
    49  			[]configv1.CIDR{"10.0.0.1/32", "10.0.0.2/32"},
    50  		},
    51  		{
    52  			[]MachineNetworkEntry{},
    53  			[]configv1.CIDR{},
    54  		},
    55  		{
    56  			[]MachineNetworkEntry{
    57  				{CIDR: *ipnet.MustParseCIDR("fe80:1:2:3::/128")},
    58  			},
    59  			[]configv1.CIDR{"fe80:1:2:3::/128"},
    60  		},
    61  	}
    62  
    63  	for _, tc := range testcases {
    64  		res := MachineNetworksToCIDRs(tc.networks)
    65  		assert.Equal(t, tc.expected, res, "conversion failed")
    66  	}
    67  }