github.com/linuxboot/fiano@v1.2.0/pkg/visitors/assemble_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 "fmt" 9 "testing" 10 11 "github.com/linuxboot/fiano/pkg/guid" 12 "github.com/linuxboot/fiano/pkg/uefi" 13 ) 14 15 var ( 16 ZeroGUID = guid.MustParse("00000000-0000-0000-0000-000000000000") 17 ) 18 19 func TestBadDepex(t *testing.T) { 20 var tests = []struct { 21 name string 22 op uefi.DepExOp 23 err string 24 }{ 25 {"badOpCode", uefi.DepExOp{OpCode: "BLAH", GUID: nil}, 26 "unable to map depex opcode string to opcode, string was: BLAH"}, 27 {"pushNoGUID", uefi.DepExOp{OpCode: "PUSH", GUID: nil}, 28 "depex opcode PUSH must not have nil guid"}, 29 {"trueWithGUID", uefi.DepExOp{OpCode: "TRUE", GUID: ZeroGUID}, 30 fmt.Sprintf("depex opcode TRUE must not have a guid! got %v", *ZeroGUID)}, 31 } 32 33 for _, test := range tests { 34 t.Run(test.name, func(t *testing.T) { 35 s := &uefi.Section{} 36 s.SetType(uefi.SectionTypeDXEDepEx) 37 s.DepEx = []uefi.DepExOp{test.op} 38 a := &Assemble{} 39 err := a.Run(s) 40 if err == nil { 41 t.Fatalf("Expected error: %v, got nil!", test.err) 42 } 43 if errStr := err.Error(); test.err != errStr { 44 t.Errorf("Expected error: %v, got %v instead", test.err, errStr) 45 } 46 }) 47 } 48 }