github.com/u-root/u-root@v7.0.1-0.20200915234505-ad7babab0a8e+incompatible/pkg/vpd/vpd_test.go (about) 1 // Copyright 2017-2019 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 package vpd 6 7 import ( 8 "reflect" 9 "testing" 10 11 "github.com/stretchr/testify/require" 12 ) 13 14 func TestGetReadOnly(t *testing.T) { 15 VpdDir = "./tests" 16 value, err := Get("key1", true) 17 require.NoError(t, err) 18 require.Equal(t, value, []byte("value1\n")) 19 } 20 21 func TestGetReadWrite(t *testing.T) { 22 VpdDir = "./tests" 23 value, err := Get("mysecretpassword", false) 24 require.NoError(t, err) 25 require.Equal(t, value, []byte("passw0rd\n")) 26 } 27 28 func TestGetReadBinary(t *testing.T) { 29 VpdDir = "./tests" 30 value, err := Get("binary1", true) 31 require.NoError(t, err) 32 require.Equal(t, value, []byte("some\x00binary\ndata")) 33 } 34 35 func TestGetAllReadOnly(t *testing.T) { 36 VpdDir = "./tests" 37 expected := map[string][]byte{ 38 "binary1": []byte("some\x00binary\ndata"), 39 "key1": []byte("value1\n"), 40 } 41 vpdMap, err := GetAll(true) 42 require.NoError(t, err) 43 if !reflect.DeepEqual(vpdMap, expected) { 44 t.FailNow() 45 } 46 }