github.com/andrewsun2898/u-root@v6.0.1-0.20200616011413-4b2895c1b815+incompatible/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  	"io/ioutil"
     9  	"os"
    10  	"testing"
    11  
    12  	"github.com/u-root/u-root/pkg/golang"
    13  	"github.com/u-root/u-root/pkg/uroot/initramfs"
    14  )
    15  
    16  func TestBBBuild(t *testing.T) {
    17  	dir, err := ioutil.TempDir("", "u-root")
    18  	if err != nil {
    19  		t.Fatal(err)
    20  	}
    21  	defer os.RemoveAll(dir)
    22  
    23  	opts := Opts{
    24  		Env: golang.Default(),
    25  		Packages: []string{
    26  			"github.com/u-root/u-root/pkg/uroot/test/foo",
    27  			"github.com/u-root/u-root/cmds/core/elvish",
    28  		},
    29  		TempDir:   dir,
    30  		BinaryDir: "bbin",
    31  	}
    32  	af := initramfs.NewFiles()
    33  	var bbb BBBuilder
    34  	if err := bbb.Build(af, opts); err != nil {
    35  		t.Error(err)
    36  	}
    37  
    38  	var mustContain = []string{
    39  		"bbin/elvish",
    40  		"bbin/foo",
    41  	}
    42  	for _, name := range mustContain {
    43  		if !af.Contains(name) {
    44  			t.Errorf("expected files to include %q; archive: %v", name, af)
    45  		}
    46  	}
    47  
    48  }