mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-05 13:17:36 +03:00
For the client, the Versions option in the quic.Config encodes the first entry is the preferred version. If not set, this should default to the highest supported version.
65 lines
2.1 KiB
Go
65 lines
2.1 KiB
Go
package protocol
|
|
|
|
import (
|
|
. "github.com/onsi/ginkgo"
|
|
. "github.com/onsi/gomega"
|
|
)
|
|
|
|
var _ = Describe("Version", func() {
|
|
It("converts tags to numbers", func() {
|
|
Expect(VersionTagToNumber('Q' + '1'<<8 + '2'<<16 + '3'<<24)).To(Equal(VersionNumber(123)))
|
|
})
|
|
|
|
It("converts number to tag", func() {
|
|
Expect(VersionNumberToTag(VersionNumber(123))).To(Equal(uint32('Q' + '1'<<8 + '2'<<16 + '3'<<24)))
|
|
})
|
|
|
|
It("recognizes supported versions", func() {
|
|
Expect(IsSupportedVersion(SupportedVersions, 0)).To(BeFalse())
|
|
Expect(IsSupportedVersion(SupportedVersions, SupportedVersions[0])).To(BeTrue())
|
|
Expect(IsSupportedVersion(SupportedVersions, SupportedVersions[len(SupportedVersions)-1])).To(BeTrue())
|
|
})
|
|
|
|
It("has supported versions in sorted order", func() {
|
|
for i := 0; i < len(SupportedVersions)-1; i++ {
|
|
Expect(SupportedVersions[i]).To(BeNumerically(">", SupportedVersions[i+1]))
|
|
}
|
|
})
|
|
|
|
Context("highest supported version", func() {
|
|
var initialSupportedVersions []VersionNumber
|
|
|
|
BeforeEach(func() {
|
|
initialSupportedVersions = make([]VersionNumber, len(SupportedVersions))
|
|
copy(initialSupportedVersions, SupportedVersions)
|
|
})
|
|
|
|
AfterEach(func() {
|
|
SupportedVersions = initialSupportedVersions
|
|
})
|
|
|
|
It("finds the supported version", func() {
|
|
SupportedVersions = []VersionNumber{3, 2, 1}
|
|
other := []VersionNumber{3, 4, 5, 6}
|
|
found, ver := HighestSupportedVersion(other)
|
|
Expect(found).To(BeTrue())
|
|
Expect(ver).To(Equal(VersionNumber(3)))
|
|
})
|
|
|
|
It("picks the highest supported version", func() {
|
|
SupportedVersions = []VersionNumber{7, 6, 3, 2, 1}
|
|
other := []VersionNumber{3, 6, 1, 8, 2, 10}
|
|
found, ver := HighestSupportedVersion(other)
|
|
Expect(found).To(BeTrue())
|
|
Expect(ver).To(Equal(VersionNumber(6)))
|
|
})
|
|
|
|
It("handles empty inputs", func() {
|
|
SupportedVersions = []VersionNumber{102, 101}
|
|
Expect(HighestSupportedVersion([]VersionNumber{})).To(BeFalse())
|
|
SupportedVersions = []VersionNumber{}
|
|
Expect(HighestSupportedVersion([]VersionNumber{1, 2})).To(BeFalse())
|
|
Expect(HighestSupportedVersion([]VersionNumber{})).To(BeFalse())
|
|
})
|
|
})
|
|
})
|