github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/helper/ipaddr/ipaddr_test.go (about)

     1  package ipaddr
     2  
     3  import (
     4  	"net"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/require"
     8  )
     9  
    10  func Test_IsAny(t *testing.T) {
    11  	testCases := []struct {
    12  		inputIP        string
    13  		expectedOutput bool
    14  		name           string
    15  	}{
    16  		{
    17  			inputIP:        "0.0.0.0",
    18  			expectedOutput: true,
    19  			name:           "string ipv4 any IP",
    20  		},
    21  		{
    22  			inputIP:        "::",
    23  			expectedOutput: true,
    24  			name:           "string ipv6 any IP",
    25  		},
    26  		{
    27  			inputIP:        net.IPv4zero.String(),
    28  			expectedOutput: true,
    29  			name:           "net.IP ipv4 any",
    30  		},
    31  		{
    32  			inputIP:        net.IPv6zero.String(),
    33  			expectedOutput: true,
    34  			name:           "net.IP ipv6 any",
    35  		},
    36  		{
    37  			inputIP:        "10.10.10.10",
    38  			expectedOutput: false,
    39  			name:           "internal ipv4 address",
    40  		},
    41  		{
    42  			inputIP:        "8.8.8.8",
    43  			expectedOutput: false,
    44  			name:           "public ipv4 address",
    45  		},
    46  	}
    47  
    48  	for _, tc := range testCases {
    49  		t.Run(tc.name, func(t *testing.T) {
    50  			require.Equal(t, tc.expectedOutput, IsAny(tc.inputIP))
    51  		})
    52  	}
    53  }