github.com/mvdan/u-root-coreutils@v0.0.0-20230122170626-c2eef2898555/pkg/mount/mount_integration_test.go (about)

     1  // Copyright 2019 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  //go:build !race
     6  // +build !race
     7  
     8  package mount
     9  
    10  import (
    11  	"io/ioutil"
    12  	"path/filepath"
    13  	"testing"
    14  
    15  	"github.com/mvdan/u-root-coreutils/pkg/cp"
    16  	"github.com/mvdan/u-root-coreutils/pkg/qemu"
    17  	"github.com/mvdan/u-root-coreutils/pkg/vmtest"
    18  )
    19  
    20  func TestIntegration(t *testing.T) {
    21  	// qemu likes to lock files.
    22  	// In practice we've seen issues with multiple instantiations of
    23  	// qemu getting into lock wars. To avoid this, copy data files to
    24  	// a temp directory.
    25  	// Don't use this, we want to let the test decide whether to delete it. tmp := t.TempDir()
    26  	tmp, err := ioutil.TempDir("", "MountTestIntegration")
    27  	if err != nil {
    28  		t.Fatalf("Creating TempDir: %v", tmp)
    29  	}
    30  	// We do not use CopyTree as it (1) recreates the full path in the tmp directory,
    31  	// and (2) we want to only copy what we want to copy.
    32  	for _, f := range []string{"1MB.ext4_vfat", "12Kzeros", "gptdisk", "gptdisk2"} {
    33  		s := filepath.Join("./testdata", f)
    34  		d := filepath.Join(tmp, f)
    35  		if err := cp.Copy(s, d); err != nil {
    36  			t.Fatalf("Copying %q to %q: got %v, want nil", s, d, err)
    37  		}
    38  	}
    39  	o := &vmtest.Options{
    40  		TmpDir: tmp,
    41  		QEMUOpts: qemu.Options{
    42  			Devices: []qemu.Device{
    43  				// CONFIG_ATA_PIIX is required for this option to work.
    44  				qemu.ArbitraryArgs{"-hda", filepath.Join(tmp, "1MB.ext4_vfat")},
    45  				qemu.ArbitraryArgs{"-hdb", filepath.Join(tmp, "12Kzeros")},
    46  				qemu.ArbitraryArgs{"-hdc", filepath.Join(tmp, "gptdisk")},
    47  				qemu.ArbitraryArgs{"-drive", "file=" + filepath.Join(tmp, "gptdisk2") + ",if=none,id=NVME1"},
    48  				// use-intel-id uses the vendor=0x8086 and device=0x5845 ids for NVME
    49  				qemu.ArbitraryArgs{"-device", "nvme,drive=NVME1,serial=nvme-1,use-intel-id"},
    50  			},
    51  		},
    52  	}
    53  	vmtest.GolangTest(t, []string{"github.com/mvdan/u-root-coreutils/pkg/mount"}, o)
    54  }