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/gopkg.in/asn1-ber.v1/length_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/gopkg.in/asn1-ber.v1/length_test.go')
-rw-r--r-- | vendor/gopkg.in/asn1-ber.v1/length_test.go | 45 |
1 files changed, 39 insertions, 6 deletions
diff --git a/vendor/gopkg.in/asn1-ber.v1/length_test.go b/vendor/gopkg.in/asn1-ber.v1/length_test.go index afe0e8037..289510a8d 100644 --- a/vendor/gopkg.in/asn1-ber.v1/length_test.go +++ b/vendor/gopkg.in/asn1-ber.v1/length_test.go @@ -11,7 +11,7 @@ func TestReadLength(t *testing.T) { testcases := map[string]struct { Data []byte - ExpectedLength int + ExpectedLength int64 ExpectedBytesRead int ExpectedError string }{ @@ -68,7 +68,19 @@ func TestReadLength(t *testing.T) { ExpectedLength: 127, ExpectedBytesRead: 2, }, - "long-definite-form max length": { + "long-definite-form max length (32-bit)": { + Data: []byte{ + LengthLongFormBitmask | 4, + 0x7F, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + }, + ExpectedLength: math.MaxInt32, + ExpectedBytesRead: 5, + }, + "long-definite-form max length (64-bit)": { Data: []byte{ LengthLongFormBitmask | 8, 0x7F, @@ -86,6 +98,11 @@ func TestReadLength(t *testing.T) { } for k, tc := range testcases { + // Skip tests requiring 64-bit integers on platforms that don't support them + if tc.ExpectedLength != int64(int(tc.ExpectedLength)) { + continue + } + reader := bytes.NewBuffer(tc.Data) length, read, err := readLength(reader) @@ -104,7 +121,7 @@ func TestReadLength(t *testing.T) { t.Errorf("%s: expected read %d, got %d", k, tc.ExpectedBytesRead, read) } - if length != tc.ExpectedLength { + if int64(length) != tc.ExpectedLength { t.Errorf("%s: expected length %d, got %d", k, tc.ExpectedLength, length) } } @@ -112,7 +129,7 @@ func TestReadLength(t *testing.T) { func TestEncodeLength(t *testing.T) { testcases := map[string]struct { - Length int + Length int64 ExpectedBytes []byte }{ "0": { @@ -133,7 +150,18 @@ func TestEncodeLength(t *testing.T) { ExpectedBytes: []byte{LengthLongFormBitmask | 1, 128}, }, - "max long-form length": { + "max long-form length (32-bit)": { + Length: math.MaxInt32, + ExpectedBytes: []byte{ + LengthLongFormBitmask | 4, + 0x7F, + 0xFF, + 0xFF, + 0xFF, + }, + }, + + "max long-form length (64-bit)": { Length: math.MaxInt64, ExpectedBytes: []byte{ LengthLongFormBitmask | 8, @@ -150,7 +178,12 @@ func TestEncodeLength(t *testing.T) { } for k, tc := range testcases { - b := encodeLength(tc.Length) + // Skip tests requiring 64-bit integers on platforms that don't support them + if tc.Length != int64(int(tc.Length)) { + continue + } + + b := encodeLength(int(tc.Length)) if bytes.Compare(tc.ExpectedBytes, b) != 0 { t.Errorf("%s: Expected\n\t%#v\ngot\n\t%#v", k, tc.ExpectedBytes, b) } |