summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/hashicorp/go-sockaddr/template/template_test.go
diff options
context:
space:
mode:
authorChristopher Speller <crspeller@gmail.com>2017-06-21 19:06:17 -0700
committerCorey Hulen <corey@hulen.com>2017-06-21 19:06:17 -0700
commit42f28ab8e374137fe3f5d25424489d879d4724f8 (patch)
tree20353f2446b506d32e6d353b72a57bf48f070389 /vendor/github.com/hashicorp/go-sockaddr/template/template_test.go
parent6b39c308d882a0aeac533f8ab1d90b48a2ae4b5a (diff)
downloadchat-42f28ab8e374137fe3f5d25424489d879d4724f8.tar.gz
chat-42f28ab8e374137fe3f5d25424489d879d4724f8.tar.bz2
chat-42f28ab8e374137fe3f5d25424489d879d4724f8.zip
Updating server dependancies (#6712)
Diffstat (limited to 'vendor/github.com/hashicorp/go-sockaddr/template/template_test.go')
-rw-r--r--vendor/github.com/hashicorp/go-sockaddr/template/template_test.go75
1 files changed, 75 insertions, 0 deletions
diff --git a/vendor/github.com/hashicorp/go-sockaddr/template/template_test.go b/vendor/github.com/hashicorp/go-sockaddr/template/template_test.go
index 6f2b47828..ec9822e77 100644
--- a/vendor/github.com/hashicorp/go-sockaddr/template/template_test.go
+++ b/vendor/github.com/hashicorp/go-sockaddr/template/template_test.go
@@ -181,6 +181,81 @@ func TestSockAddr_Parse(t *testing.T) {
{{- end -}}`,
output: `true`,
},
+ {
+ name: "math address +",
+ input: `{{GetAllInterfaces | include "name" "^lo0$" | include "type" "IP" | math "address" "+2" | sort "+type,+address" | join "address" " " }}`,
+ output: `127.0.0.3 ::3 fe80::3`,
+ },
+ {
+ name: "math address + overflow",
+ input: `|{{- with $ifAddrs := GetAllInterfaces | include "name" "^lo0$" | include "type" "IP" | math "address" "+16777217" | sort "+type,+address" -}}
+ {{- range $ifAddrs -}}
+ {{- attr "address" . }} -- {{ attr "network" . }}/{{ attr "size" . }}|{{ end -}}
+{{- end -}}`,
+ output: `|128.0.0.2 -- 128.0.0.0/16777216|::100:2 -- ::100:2/1|fe80::100:2 -- fe80::/18446744073709551616|`,
+ },
+ {
+ name: "math address + overflow+wrap",
+ input: `{{GetAllInterfaces | include "name" "^lo0$" | include "type" "IP" | math "address" "+4294967294" | sort "+type,+address" | join "address" " " }}`,
+ output: `126.255.255.255 ::ffff:ffff fe80::ffff:ffff`,
+ },
+ {
+ name: "math address -",
+ input: `{{GetAllInterfaces | include "name" "^lo0$" | include "type" "IP" | math "address" "-256" | sort "+type,+address" | join "address" " " }}`,
+ output: `126.255.255.1 fe7f:ffff:ffff:ffff:ffff:ffff:ffff:ff01 ffff:ffff:ffff:ffff:ffff:ffff:ffff:ff01`,
+ },
+ {
+ name: "math address - underflow",
+ input: `{{GetAllInterfaces | include "name" "^lo0$" | include "type" "IP" | math "address" "-4278190082" | sort "+type,+address" | join "address" " " }}`,
+ output: `127.255.255.255 fe7f:ffff:ffff:ffff:ffff:ffff:ff:ffff ffff:ffff:ffff:ffff:ffff:ffff:ff:ffff`,
+ },
+ {
+ // Note to readers: lo0's link-local address (::1) address has a mask of
+ // /128 which means its value never changes and this is expected. lo0's
+ // site-local address has a /64 address and is expected to change.
+ name: "math network",
+ input: `{{GetAllInterfaces | include "name" "^lo0$" | include "type" "IP" | math "network" "+2" | sort "+type,+address" | join "address" " " }}`,
+ output: `127.0.0.2 ::1 fe80::2`,
+ },
+ {
+ // Assume an IPv4 input of 127.0.0.1. With a value of 0xff00ff01, we wrap once on purpose.
+ name: "math network + wrap",
+ input: `{{GetAllInterfaces | include "name" "^lo0$" | include "type" "IP" | math "network" "+4278255368" | sort "+type,+address" | join "address" " " }}`,
+ output: `127.0.255.8 ::1 fe80::ff00:ff08`,
+ },
+ {
+ name: "math network -",
+ input: `{{GetAllInterfaces | include "name" "^lo0$" | include "type" "IP" | math "network" "-2" | sort "+type,+address" | join "address" " " }}`,
+ output: `127.255.255.254 ::1 fe80::ffff:ffff:ffff:fffe`,
+ },
+ {
+ // Assume an IPv4 input of 127.0.0.1. With a value of 0xff000008 it
+ // should wrap and underflow by 8. Assume an IPv6 input of ::1. With a
+ // value of -0xff000008 the value underflows and wraps.
+ name: "math network - underflow+wrap",
+ input: `{{GetAllInterfaces | include "name" "^lo0$" | include "type" "IP" | sort "+type,+address" | math "network" "-4278190088" | join "address" " " }}`,
+ output: `127.255.255.248 ::1 fe80::ffff:ffff:ff:fff8`,
+ },
+ {
+ // Assume the private IPs available on the host are: 10.1.2.3
+ // fe80::1025:f732:1001:203
+ name: "GetPrivateIPs",
+ input: `{{GetPrivateIPs}}`,
+ output: `10.1.2.3 fe80::1025:f732:1001:203`,
+ },
+ {
+ // Assume the public IPs available on the host are: 1.2.3.4 6.7.8.9
+ name: "GetPublicIPs",
+ input: `{{GetPublicIPs}}`,
+ output: `1.2.3.4 6.7.8.9`,
+ },
+ {
+ // Assume the private IPs on this host are just the IPv4 addresses:
+ // 10.1.2.3 and 172.16.4.6
+ name: "GetInterfaceIPs",
+ input: `{{GetInterfaceIPs "en0"}}`,
+ output: `10.1.2.3 and 172.16.4.6`,
+ },
}
for i, test := range tests {