pkg/guid: Support big-endian and Windows encodings

Signed-off-by: Kevin Parsons <kevpar@microsoft.com>
This commit is contained in:
Kevin Parsons
2019-05-13 14:28:49 -07:00
parent 6dd84a2574
commit 2dc6637e2c
2 changed files with 82 additions and 8 deletions
+34
View File
@@ -40,6 +40,40 @@ func Test_V4HasCorrectVersionAndVariant(t *testing.T) {
}
}
func Test_ToArray(t *testing.T) {
g := mustFromString(t, "73c39589-192e-4c64-9acf-6c5d0aa18528")
b := g.ToArray()
expected := [16]byte{0x73, 0xc3, 0x95, 0x89, 0x19, 0x2e, 0x4c, 0x64, 0x9a, 0xcf, 0x6c, 0x5d, 0x0a, 0xa1, 0x85, 0x28}
if b != expected {
t.Fatalf("GUID does not match array form: %x, %x", expected, b)
}
}
func Test_FromArrayAndBack(t *testing.T) {
b := [16]byte{0x73, 0xc3, 0x95, 0x89, 0x19, 0x2e, 0x4c, 0x64, 0x9a, 0xcf, 0x6c, 0x5d, 0x0a, 0xa1, 0x85, 0x28}
b2 := FromArray(b).ToArray()
if b != b2 {
t.Fatalf("Arrays do not match: %x, %x", b, b2)
}
}
func Test_ToWindowsArray(t *testing.T) {
g := mustFromString(t, "73c39589-192e-4c64-9acf-6c5d0aa18528")
b := g.ToWindowsArray()
expected := [16]byte{0x89, 0x95, 0xc3, 0x73, 0x2e, 0x19, 0x64, 0x4c, 0x9a, 0xcf, 0x6c, 0x5d, 0x0a, 0xa1, 0x85, 0x28}
if b != expected {
t.Fatalf("GUID does not match array form: %x, %x", expected, b)
}
}
func Test_FromWindowsArrayAndBack(t *testing.T) {
b := [16]byte{0x73, 0xc3, 0x95, 0x89, 0x19, 0x2e, 0x4c, 0x64, 0x9a, 0xcf, 0x6c, 0x5d, 0x0a, 0xa1, 0x85, 0x28}
b2 := FromWindowsArray(b).ToWindowsArray()
if b != b2 {
t.Fatalf("Arrays do not match: %x, %x", b, b2)
}
}
func Test_FromString(t *testing.T) {
orig := "8e35239e-2084-490e-a3db-ab18ee0744cb"
g := mustFromString(t, orig)