github.com/oweisse/u-root@v0.0.0-20181109060735-d005ad25fef1/pkg/uroot/builder/bb_test.go (about) 1 // Copyright 2018 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 builder 6 7 import ( 8 "go/ast" 9 "io/ioutil" 10 "os" 11 "path/filepath" 12 "testing" 13 14 "github.com/u-root/u-root/pkg/golang" 15 "github.com/u-root/u-root/pkg/uroot/initramfs" 16 ) 17 18 func TestBBBuild(t *testing.T) { 19 dir, err := ioutil.TempDir("", "u-root") 20 if err != nil { 21 t.Fatal(err) 22 } 23 defer os.RemoveAll(dir) 24 25 opts := Opts{ 26 Env: golang.Default(), 27 Packages: []string{ 28 "github.com/u-root/u-root/pkg/uroot/test/foo", 29 "github.com/u-root/u-root/cmds/elvish", 30 }, 31 TempDir: dir, 32 BinaryDir: "bbin", 33 } 34 af := initramfs.NewFiles() 35 var bbb BBBuilder 36 if err := bbb.Build(af, opts); err != nil { 37 t.Error(err) 38 } 39 40 var mustContain = []string{ 41 "bbin/elvish", 42 "bbin/foo", 43 } 44 for _, name := range mustContain { 45 if !af.Contains(name) { 46 t.Errorf("expected files to include %q; archive: %v", name, af) 47 } 48 } 49 50 } 51 52 func findFile(filemap map[string]*ast.File, basename string) *ast.File { 53 for name, f := range filemap { 54 if filepath.Base(name) == basename { 55 return f 56 } 57 } 58 return nil 59 }