github.com/linuxboot/fiano@v1.2.0/pkg/visitors/cat_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 "reflect" 10 "testing" 11 12 "github.com/linuxboot/fiano/pkg/guid" 13 ) 14 15 var ( 16 catGUID = guid.MustParse("1B45CC0A-156A-428A-AF62-49864DA0E6E6") 17 catdat = []byte{79, 218, 58, 155, 86, 174, 36, 76, 141, 234, 240, 59, 117, 88, 174, 80} 18 ) 19 20 func TestCat(t *testing.T) { 21 f := parseImage(t) 22 23 // Apply the visitor. 24 var b bytes.Buffer 25 cat := &Cat{ 26 Predicate: FindFileGUIDPredicate(*catGUID), 27 Writer: &b, 28 } 29 if err := cat.Run(f); err != nil { 30 t.Fatal(err) 31 } 32 33 // We expect one match. 34 if len(cat.Matches) != 1 { 35 t.Fatalf("got %d matches; expected 1", len(cat.Matches)) 36 } 37 38 if !reflect.DeepEqual(b.Bytes(), catdat) { 39 t.Errorf("bytes.Buffer: want %v; got %v", catdat, b.Bytes()) 40 } 41 }