github.com/mvdan/u-root-coreutils@v0.0.0-20230122170626-c2eef2898555/pkg/uefivars/vars_test.go (about)

     1  // Copyright 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  	"testing"
    12  )
    13  
    14  // func AllVars() EfiVars
    15  func TestAllVars(t *testing.T) {
    16  	n := 32
    17  	vars := AllVars()
    18  	if len(vars) != n {
    19  		t.Errorf("expect %d vars, got %d", n, len(vars))
    20  	}
    21  }
    22  
    23  // func DecodeUTF16(b []byte) (string, error)
    24  func TestDecodeUTF16(t *testing.T) {
    25  	want := "TEST"
    26  	got, err := DecodeUTF16([]byte{84, 0, 69, 0, 83, 0, 84, 0})
    27  	if err != nil {
    28  		t.Error(err)
    29  	}
    30  	if got != want {
    31  		t.Errorf("want %s, got %s", want, got)
    32  	}
    33  }
    34  
    35  // func (vars EfiVars) Filter(filt VarFilter) EfiVars
    36  func TestFilter(t *testing.T) {
    37  	filt := func(_, _ string) bool { return true }
    38  	v := AllVars()
    39  	matches := v.Filter(AndFilter(filt, NotFilter(filt)))
    40  	if len(matches) != 0 {
    41  		t.Errorf("should be no matches but got\n%#v", matches)
    42  	}
    43  }