mirror of
https://github.com/status-im/consul.git
synced 2025-01-09 21:35:52 +00:00
5fb9df1640
* Adding explicit MPL license for sub-package This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository. * Adding explicit MPL license for sub-package This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository. * Updating the license from MPL to Business Source License Going forward, this project will be licensed under the Business Source License v1.1. Please see our blog post for more details at <Blog URL>, FAQ at www.hashicorp.com/licensing-faq, and details of the license at www.hashicorp.com/bsl. * add missing license headers * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 --------- Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
60 lines
1.5 KiB
Go
60 lines
1.5 KiB
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package ipaddr
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
)
|
|
|
|
func TestIsIPv6(t *testing.T) {
|
|
tests := []struct {
|
|
ip string
|
|
ipv6 bool
|
|
}{
|
|
// IPv4 private addresses
|
|
{"10.0.0.1", false}, // private network address
|
|
{"100.64.0.1", false}, // shared address space
|
|
{"172.16.0.1", false}, // private network address
|
|
{"192.168.0.1", false}, // private network address
|
|
{"192.0.0.1", false}, // IANA address
|
|
{"192.0.2.1", false}, // documentation address
|
|
{"127.0.0.1", false}, // loopback address
|
|
{"169.254.0.1", false}, // link local address
|
|
|
|
// IPv4 public addresses
|
|
{"1.2.3.4", false},
|
|
|
|
// IPv6 private addresses
|
|
{"::1", true}, // loopback address
|
|
{"fe80::1", true}, // link local address
|
|
{"fc00::1", true}, // unique local address
|
|
{"fec0::1", true}, // site local address
|
|
{"2001:db8::1", true}, // documentation address
|
|
|
|
// IPv6 public addresses
|
|
{"2004:db6::1", true},
|
|
|
|
// hostname
|
|
{"example.com", false},
|
|
{"localhost", false},
|
|
{"1.257.0.1", false},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.ip, func(t *testing.T) {
|
|
port := 1234
|
|
formated := FormatAddressPort(tt.ip, port)
|
|
if tt.ipv6 {
|
|
if fmt.Sprintf("[%s]:%d", tt.ip, port) != formated {
|
|
t.Fatalf("Wrong format %s for %s", formated, tt.ip)
|
|
}
|
|
} else {
|
|
if fmt.Sprintf("%s:%d", tt.ip, port) != formated {
|
|
t.Fatalf("Wrong format %s for %s", formated, tt.ip)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|