github.com/linuxboot/fiano@v1.2.0/pkg/visitors/helpers_test.go (about)

     1  // Copyright 2018 the LinuxBoot 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  package visitors
     6  
     7  import (
     8  	"bytes"
     9  	"os"
    10  	"testing"
    11  
    12  	"github.com/linuxboot/fiano/pkg/guid"
    13  	"github.com/linuxboot/fiano/pkg/uefi"
    14  )
    15  
    16  // This GUID exists somewhere in the OVMF image.
    17  var testGUID = guid.MustParse("DF1CCEF6-F301-4A63-9661-FC6030DCC880")
    18  var dxeCoreGUID = guid.MustParse("D6A2CB7F-6A18-4E2F-B43B-9920A733700A")
    19  
    20  func parseImage(t *testing.T) uefi.Firmware {
    21  	image, err := os.ReadFile("../../integration/roms/OVMF.rom")
    22  	if err != nil {
    23  		t.Fatal(err)
    24  	}
    25  	parsedRoot, err := uefi.Parse(image)
    26  	if err != nil {
    27  		t.Fatal(err)
    28  	}
    29  	return parsedRoot
    30  }
    31  
    32  func find(t *testing.T, f uefi.Firmware, guid *guid.GUID) []uefi.Firmware {
    33  	find := &Find{
    34  		Predicate: FindFileGUIDPredicate(*guid),
    35  	}
    36  	if err := find.Run(f); err != nil {
    37  		t.Fatal(err)
    38  	}
    39  	return find.Matches
    40  }
    41  
    42  func comment(t *testing.T, f uefi.Firmware) []uefi.Firmware {
    43  	var b bytes.Buffer
    44  	c := &Comment{W: &b, s: "hi"}
    45  	if err := c.Run(f); err != nil {
    46  		t.Fatal(err)
    47  	}
    48  	if b.String() != "hi\n" {
    49  		t.Fatalf("Comment: go %q, wanted 'hi'", b.String())
    50  	}
    51  	return nil
    52  }