diff options
author | Christopher Speller <crspeller@gmail.com> | 2017-05-17 16:51:25 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-17 16:51:25 -0400 |
commit | d103ed6ca97ca5a2669f6cf5fe4b3d2a9c945f26 (patch) | |
tree | dbde13123c6add150448f7b75753ac022d862475 /vendor/github.com/hashicorp/go-sockaddr/rfc_test.go | |
parent | cd23b8139a9463b67e3096744321f6f4eb0ca40a (diff) | |
download | chat-d103ed6ca97ca5a2669f6cf5fe4b3d2a9c945f26.tar.gz chat-d103ed6ca97ca5a2669f6cf5fe4b3d2a9c945f26.tar.bz2 chat-d103ed6ca97ca5a2669f6cf5fe4b3d2a9c945f26.zip |
Upgrading server dependancies (#6431)
Diffstat (limited to 'vendor/github.com/hashicorp/go-sockaddr/rfc_test.go')
-rw-r--r-- | vendor/github.com/hashicorp/go-sockaddr/rfc_test.go | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/vendor/github.com/hashicorp/go-sockaddr/rfc_test.go b/vendor/github.com/hashicorp/go-sockaddr/rfc_test.go new file mode 100644 index 000000000..af669a43f --- /dev/null +++ b/vendor/github.com/hashicorp/go-sockaddr/rfc_test.go @@ -0,0 +1,63 @@ +package sockaddr_test + +import ( + "testing" + + sockaddr "github.com/hashicorp/go-sockaddr" +) + +func TestVisitAllRFCs(t *testing.T) { + const expectedNumRFCs = 28 + numRFCs := 0 + sockaddr.VisitAllRFCs(func(rfcNum uint, sas sockaddr.SockAddrs) { + numRFCs++ + }) + if numRFCs != expectedNumRFCs { + t.Fatalf("wrong number of RFCs: %d", numRFCs) + } +} + +func TestIsRFC(t *testing.T) { + tests := []struct { + name string + sa sockaddr.SockAddr + rfcNum uint + result bool + }{ + { + name: "rfc1918 pass", + sa: sockaddr.MustIPv4Addr("192.168.0.0/16"), + rfcNum: 1918, + result: true, + }, + { + name: "rfc1918 fail", + sa: sockaddr.MustIPv4Addr("1.2.3.4"), + rfcNum: 1918, + result: false, + }, + { + name: "rfc1918 pass", + sa: sockaddr.MustIPv4Addr("192.168.1.1"), + rfcNum: 1918, + result: true, + }, + { + name: "invalid rfc", + sa: sockaddr.MustIPv4Addr("192.168.0.0/16"), + rfcNum: 999999999999, + result: false, + }, + } + + for i, test := range tests { + if test.name == "" { + t.Fatalf("test %d needs a name", i) + } + + result := sockaddr.IsRFC(test.rfcNum, test.sa) + if result != test.result { + t.Fatalf("expected a match") + } + } +} |