github.com/u-root/u-root@v7.0.1-0.20200915234505-ad7babab0a8e+incompatible/pkg/uefivars/guid_test.go (about)

     1  // Copyright 2015-2020 the u-root Authors. All rights reserved
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  //
     5  // SPDX-License-Identifier: BSD-3-Clause
     6  //
     7  
     8  package uefivars
     9  
    10  import (
    11  	"bytes"
    12  	"testing"
    13  )
    14  
    15  func TestEncodeDecode(t *testing.T) {
    16  	for _, td := range []struct {
    17  		name, want string
    18  		in         MixedGUID
    19  	}{
    20  		{
    21  			name: "1",
    22  			in:   MixedGUID{0xCD, 0x5C, 0x63, 0x81, 0x4F, 0x1B, 0x3F, 0x4D, 0xB7, 0xB7, 0xF7, 0x8A, 0x5B, 0x02, 0x9F, 0x35},
    23  			want: "81635ccd-1b4f-4d3f-b7b7-f78a5b029f35",
    24  		}, {
    25  			name: "2",
    26  			in:   MixedGUID{0xa2, 0xd1, 0x1b, 0x1d, 0xd9, 0x0f, 0xe9, 0x41, 0xbb, 0xb5, 0xa9, 0x8b, 0xac, 0x57, 0x0b, 0x2a},
    27  			want: "1d1bd1a2-0fd9-41e9-bbb5-a98bac570b2a",
    28  		}, {
    29  			name: "3",
    30  			in:   MixedGUID{0x3e, 0x14, 0xbe, 0xcf, 0x9e, 0x5e, 0x25, 0x46, 0xa5, 0x00, 0xc3, 0xf0, 0x36, 0x20, 0x04, 0x11},
    31  			want: "cfbe143e-5e9e-4625-a500-c3f036200411",
    32  		},
    33  	} {
    34  		t.Run(td.name, func(t *testing.T) {
    35  			mstr := td.in.String()
    36  			if mstr != td.want {
    37  				t.Errorf("mismatch\nwant %s\n got %s", td.want, mstr)
    38  			}
    39  			std := td.in.ToStdEnc()
    40  			sstr := std.String()
    41  			if sstr != td.want {
    42  				t.Errorf("mismatch\nwant %s\n got %s", td.want, sstr)
    43  			}
    44  			guid := std.ToMixedGUID()
    45  			if !bytes.Equal(guid[:], td.in[:]) {
    46  				t.Errorf("mismatch\nwant %x\n got %x", td.in, guid)
    47  			}
    48  		})
    49  	}
    50  }