-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12171 from hashicorp/f-gh-259
service discovery: add RPC endpoints and FSM logic
- Loading branch information
Showing
18 changed files
with
2,562 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package ipaddr | ||
|
||
// IsAny checks if the given IP address is an IPv4 or IPv6 ANY address. | ||
func IsAny(ip string) bool { | ||
return isAnyV4(ip) || isAnyV6(ip) | ||
} | ||
|
||
func isAnyV4(ip string) bool { return ip == "0.0.0.0" } | ||
|
||
func isAnyV6(ip string) bool { return ip == "::" || ip == "[::]" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package ipaddr | ||
|
||
import ( | ||
"net" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func Test_IsAny(t *testing.T) { | ||
testCases := []struct { | ||
inputIP string | ||
expectedOutput bool | ||
name string | ||
}{ | ||
{ | ||
inputIP: "0.0.0.0", | ||
expectedOutput: true, | ||
name: "string ipv4 any IP", | ||
}, | ||
{ | ||
inputIP: "::", | ||
expectedOutput: true, | ||
name: "string ipv6 any IP", | ||
}, | ||
{ | ||
inputIP: net.IPv4zero.String(), | ||
expectedOutput: true, | ||
name: "net.IP ipv4 any", | ||
}, | ||
{ | ||
inputIP: net.IPv6zero.String(), | ||
expectedOutput: true, | ||
name: "net.IP ipv6 any", | ||
}, | ||
{ | ||
inputIP: "10.10.10.10", | ||
expectedOutput: false, | ||
name: "internal ipv4 address", | ||
}, | ||
{ | ||
inputIP: "8.8.8.8", | ||
expectedOutput: false, | ||
name: "public ipv4 address", | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
require.Equal(t, tc.expectedOutput, IsAny(tc.inputIP)) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.