blob: 226c7a6e18e1cf9a9d6d4071669bea94fd0a9f5c [file] [log] [blame]
Tim Windelschmidt6d33a432025-02-04 14:34:25 +01001// Copyright The Monogon Project Authors.
2// SPDX-License-Identifier: Apache-2.0
3
Lorenz Brun62a1edd2023-06-20 16:01:44 +02004package msguid
5
6import (
7 "testing"
8
9 "github.com/google/go-cmp/cmp"
10 "github.com/google/uuid"
11)
12
13func TestRoundTrip(t *testing.T) {
14 cases := []struct {
15 name string
16 uuid string
17 expected [16]byte
18 }{
19 {
20 "WikipediaExample1",
21 "00112233-4455-6677-8899-AABBCCDDEEFF",
22 [16]byte{
23 0x33, 0x22, 0x11, 0x00, 0x55, 0x44, 0x77, 0x66,
24 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
25 },
26 },
27 }
28 for _, c := range cases {
29 t.Run(c.name, func(t *testing.T) {
30 origUUID := uuid.MustParse(c.uuid)
31 got := From(origUUID)
32 diff := cmp.Diff(c.expected, got)
33 if diff != "" {
34 t.Fatalf("To(%q) returned unexpected result: %v", origUUID, diff)
35 }
36 back := To(got)
37 diff2 := cmp.Diff(origUUID, back)
38 if diff2 != "" {
39 t.Errorf("From(To(%q)) did not return original value: %v", origUUID, diff2)
40 }
41 })
42 }
43}