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

     1  // Copyright 2019 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  	"os"
     9  	"testing"
    10  
    11  	"github.com/linuxboot/fiano/pkg/uefi"
    12  )
    13  
    14  func TestNVRamCompact(t *testing.T) {
    15  	path := "../../integration/roms/nvartest/"
    16  
    17  	tmpDir, err := os.MkdirTemp("", "section-test")
    18  
    19  	if err != nil {
    20  		t.Fatalf("could not create temp dir: %v", err)
    21  	}
    22  	defer os.RemoveAll(tmpDir)
    23  
    24  	var parsedRoot uefi.Firmware
    25  	// Call ParseDir
    26  	pd := ParseDir{BasePath: path}
    27  	if parsedRoot, err = pd.Parse(); err != nil {
    28  		t.Fatal(err)
    29  	}
    30  	// Assemble the tree from the bottom up
    31  	a := Assemble{}
    32  	if err = a.Run(parsedRoot); err != nil {
    33  		t.Fatal(err)
    34  	}
    35  
    36  	// initial count
    37  	count := &Count{}
    38  	if err = count.Run(parsedRoot); err != nil {
    39  		t.Fatal(err)
    40  	}
    41  
    42  	want := 6
    43  	got := count.FirmwareTypeCount["NVar"]
    44  	if got != want {
    45  		t.Fatalf("counted %d NVar, want %d", got, want)
    46  	}
    47  
    48  	// Compact
    49  	compact := &NVRamCompact{}
    50  	if err = compact.Run(parsedRoot); err != nil {
    51  		t.Fatal(err)
    52  	}
    53  
    54  	// count
    55  	if err = count.Run(parsedRoot); err != nil {
    56  		t.Fatal(err)
    57  	}
    58  
    59  	want = 5
    60  	got = count.FirmwareTypeCount["NVar"]
    61  	if got != want {
    62  		t.Fatalf("counted %d NVar, want %d", got, want)
    63  	}
    64  
    65  }