github.com/mvdan/u-root-coreutils@v0.0.0-20230122170626-c2eef2898555/pkg/uroot/builder/binary_test.go (about)

     1  // Copyright 2022 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  	"testing"
     9  
    10  	gbbgolang "github.com/u-root/gobusybox/src/pkg/golang"
    11  	"github.com/mvdan/u-root-coreutils/pkg/ulog/ulogtest"
    12  	"github.com/mvdan/u-root-coreutils/pkg/uroot/initramfs"
    13  )
    14  
    15  func TestBinaryBuild(t *testing.T) {
    16  	dir := t.TempDir()
    17  
    18  	opts := Opts{
    19  		Env: gbbgolang.Default(),
    20  		Packages: []string{
    21  			"../test/foo",
    22  			"../../../cmds/core/elvish",
    23  			"github.com/mvdan/u-root-coreutils/cmds/core/init",
    24  			"cmd/test2json",
    25  		},
    26  		TempDir:   dir,
    27  		BinaryDir: "bbin",
    28  		BuildOpts: &gbbgolang.BuildOpts{},
    29  	}
    30  	af := initramfs.NewFiles()
    31  	var b BinaryBuilder
    32  	if err := b.Build(ulogtest.Logger{TB: t}, af, opts); err != nil {
    33  		t.Fatalf("Build(%v, %v); %v != nil", af, opts, err)
    34  	}
    35  
    36  	mustContain := []string{
    37  		"bbin/elvish",
    38  		"bbin/foo",
    39  		"bbin/init",
    40  	}
    41  	for _, name := range mustContain {
    42  		if !af.Contains(name) {
    43  			t.Errorf("expected files to include %q; archive: %v", name, af)
    44  		}
    45  	}
    46  }