github.com/linuxboot/fiano@v1.2.0/pkg/visitors/dump_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  
    13  func TestDump(t *testing.T) {
    14  	f := parseImage(t)
    15  
    16  	b := bytes.Buffer{}
    17  	// Apply the visitor.
    18  	dump := &Dump{
    19  		Predicate: FindFileGUIDPredicate(*testGUID),
    20  		W:         &b,
    21  	}
    22  	if err := dump.Run(f); err != nil {
    23  		t.Fatal(err)
    24  	}
    25  
    26  	// Read in expected file.
    27  	file, err := os.ReadFile("../../integration/roms/testfile.ffs")
    28  	if err != nil {
    29  		t.Fatal(err)
    30  	}
    31  	// W should now contain the file.
    32  	if !bytes.Equal(b.Bytes(), file) {
    33  		// TODO: Should dump the file somewhere for comparison.
    34  		t.Errorf("files are not equal! expected file is in integration/roms/testfile.ffs")
    35  	}
    36  }