forked from quic-go/quic-go
add some simple tests
This commit is contained in:
@@ -21,4 +21,9 @@ var _ = Describe("Version", func() {
|
|||||||
It("has proper tag list", func() {
|
It("has proper tag list", func() {
|
||||||
Expect(protocol.SupportedVersionsAsTags).To(Equal([]byte("Q030Q032")))
|
Expect(protocol.SupportedVersionsAsTags).To(Equal([]byte("Q030Q032")))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("recognizes supported versions", func() {
|
||||||
|
Expect(protocol.IsSupportedVersion(0)).To(BeFalse())
|
||||||
|
Expect(protocol.IsSupportedVersion(protocol.SupportedVersions[0])).To(BeTrue())
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// ReadUintN reads N bytes
|
// ReadUintN reads N bytes
|
||||||
// ToDo: add tests
|
|
||||||
func ReadUintN(b io.ByteReader, length uint8) (uint64, error) {
|
func ReadUintN(b io.ByteReader, length uint8) (uint64, error) {
|
||||||
var res uint64
|
var res uint64
|
||||||
for i := uint8(0); i < length; i++ {
|
for i := uint8(0); i < length; i++ {
|
||||||
|
|||||||
@@ -94,4 +94,25 @@ var _ = Describe("Utils", func() {
|
|||||||
Expect(Min(5, 7)).To(Equal(5))
|
Expect(Min(5, 7)).To(Equal(5))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Context("ReadUintN", func() {
|
||||||
|
It("reads n bytes", func() {
|
||||||
|
m := map[uint8]uint64{
|
||||||
|
0: 0x0, 1: 0x01, 2: 0x0201, 3: 0x030201, 4: 0x04030201, 5: 0x0504030201,
|
||||||
|
6: 0x060504030201, 7: 0x07060504030201, 8: 0x0807060504030201,
|
||||||
|
}
|
||||||
|
for n, expected := range m {
|
||||||
|
b := bytes.NewReader([]byte{0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8})
|
||||||
|
i, err := ReadUintN(b, n)
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
Expect(i).To(Equal(expected))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
It("errors", func() {
|
||||||
|
b := bytes.NewReader([]byte{0x1, 0x2})
|
||||||
|
_, err := ReadUintN(b, 3)
|
||||||
|
Expect(err).To(HaveOccurred())
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user