github.com/hernad/nomad@v1.6.112/helper/ipaddr/ipaddr_test.go (about)

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