10000 Replace testutil.SkipIfNotRoot with vmtest.SkipIfNotInVM · u-root/u-root@4431a16 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4431a16

Browse files
committed
Replace testutil.SkipIfNotRoot with vmtest.SkipIfNotInVM
Signed-off-by: Chris Koch <chrisko@google.com>
1 parent 1730f1e commit 4431a16

26 files changed

+113
-121
lines changed

cmds/core/chroot/chroot_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"reflect"
1212
"testing"
1313

14-
"github.com/u-root/u-root/pkg/testutil"
14+
"github.com/hugelgupf/vmtest/guest"
1515
)
1616

1717
func TestUserSpecSet(t *testing.T) {
@@ -73,7 +73,6 @@ func TestUserSpecGet(t *testing.T) {
7373
}
7474

7575
func TestGroupsSet(t *testing.T) {
76-
7776
for _, tt := range []struct {
7877
name string
7978
input string
@@ -159,7 +158,8 @@ func TestGroupsString(t *testing.T) {
159158
}
160159

161160
func TestChroot(t *testing.T) {
162-
testutil.SkipIfNotRoot(t)
161+
guest.SkipIfNotInVM(t)
162+
163163
for _, tt := range []struct {
164164
name string
165165
args []string

cmds/core/dmesg/dmesg_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ import (
1111
"strings"
1212
"testing"
1313

14-
"github.com/u-root/u-root/pkg/testutil"
14+
"github.com/hugelgupf/vmtest/guest"
1515
)
1616

1717
func TestDmesg(t *testing.T) {
18-
testutil.SkipIfNotRoot(t)
18+
guest.SkipIfNotInVM(t)
19+
1920
for _, tt := range []struct {
2021
name string
2122
buf *bytes.Buffer

cmds/core/fusermount/fusermount_linux_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"syscall"
1717
"testing"
1818

19+
"github.com/hugelgupf/vmtest/guest"
1920
"github.com/u-root/u-root/pkg/testutil"
2021
"golang.org/x/sys/unix"
2122
)
@@ -82,9 +83,8 @@ func TestArgs(t *testing.T) {
8283
}
8384

8485
func TestMount(t *testing.T) {
85-
if os.Getuid() != 0 {
86-
t.Skip("Skipping, not root")
87-
}
86+
guest.SkipIfNotInVM(t)
87+
8888
if _, err := os.Stat("/dev/fuse"); err != nil {
8989
t.Skipf("Skipping:%v", err)
9090
}

cmds/core/ls/ls_linux_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import (
1010
"strings"
1111
"testing"
1212

13+
"github.com/hugelgupf/vmtest/guest"
1314
"github.com/u-root/u-root/pkg/ls"
14-
"github.com/u-root/u-root/pkg/testutil"
1515
"golang.org/x/sys/unix"
1616
)
1717

@@ -27,7 +27,8 @@ import (
2727

2828
// Test listName func
2929
func TestListNameLinux(t *testing.T) {
30-
testutil.SkipIfNotRoot(t)
30+
guest.SkipIfNotInVM(t)
31+
3132
// Create a directory
3233
d := t.TempDir()
3334
if err := unix.Mknod(filepath.Join(d, "large_node"), 0o660|unix.S_IFBLK, 0x12345678); err != nil {

cmds/core/sync/sync_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ import (
99
"os"
1010
"testing"
1111

12-
"github.com/u-root/u-root/pkg/testutil"
12+
"github.com/hugelgupf/vmtest/guest"
1313
)
1414

1515
func TestSync(t *testing.T) {
16-
testutil.SkipIfNotRoot(t)
16+
guest.SkipIfNotInVM(t)
17+
1718
d := t.TempDir()
1819
file1, err := os.CreateTemp(d, "file1")
1920
if err != nil {

cmds/exp/pox/pox_vm_test.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import (
1515
"time"
1616

1717
"github.com/hugelgupf/vmtest"
18+
"github.com/hugelgupf/vmtest/guest"
1819
"github.com/hugelgupf/vmtest/qemu"
19-
"github.com/u-root/u-root/pkg/testutil"
2020
)
2121

2222
func TestIntegrationPox(t *testing.T) {
@@ -28,7 +28,8 @@ func TestIntegrationPox(t *testing.T) {
2828
}
2929

3030
func TestPox(t *testing.T) {
31-
testutil.SkipIfNotRoot(t)
31+
guest.SkipIfNotInVM(t)
32+
3233
f := filepath.Join(t.TempDir(), "x.tcz")
3334
tmpFile, err := os.Create("/bin/bash")
3435
if err != nil {
@@ -92,7 +93,8 @@ func TestPox(t *testing.T) {
9293
}
9394

9495
func TestPoxCreate(t *testing.T) {
95-
testutil.SkipIfNotRoot(t)
96+
guest.SkipIfNotInVM(t)
97+
9698
f := filepath.Join(t.TempDir(), "x.tcz")
9799
tmpFile, err := os.Create("/bin/bash")
98100
if err != nil {
@@ -164,7 +166,8 @@ func TestPoxCreate(t *testing.T) {
164166
}
165167

166168
func TestPoxRun(t *testing.T) {
167-
testutil.SkipIfNotRoot(t)
169+
guest.SkipIfNotInVM(t)
170+
168171
f := filepath.Join(t.TempDir(), "x.tcz")
169172
if _, err := os.Create(f); err != nil {
170173
t.Errorf("Couldn't create file: %v", err)

cmds/exp/rush/rush_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"strings"
1212
"testing"
1313

14+
"github.com/hugelgupf/vmtest/guest"
1415
"github.com/u-root/u-root/pkg/testutil"
1516
)
1617

@@ -28,7 +29,7 @@ var tests = []struct {
2829
}
2930

3031
func TestRush(t *testing.T) {
31-
testutil.SkipIfNotRoot(t)
32+
guest.SkipIfNotInVM(t)
3233

3334
// Table-driven testing
3435
for i, tt := range tests {

cmds/exp/rush/tty_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ package main
77
import (
88
"testing"
99

10-
"github.com/u-root/u-root/pkg/testutil"
10+
"github.com/hugelgupf/vmtest/guest"
1111
)
1212

1313
func TestTTY(t *testing.T) {
14-
testutil.SkipIfNotRoot(t)
14+
guest.SkipIfNotInVM(t)
1515

1616
tty()
1717
foreground()

pkg/acpi/linux_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@
88
package acpi
99

1010
import (
11-
"os"
1211
"testing"
12+
13+
"github.com/hugelgupf/vmtest/guest"
1314
)
1415

1516
// TestLinux just verifies that tables read OK.
1617
// It does not verify content as content varies all
1718
// the time.
1819
func TestLinux(t *testing.T) {
19-
if os.Getuid() != 0 {
20-
t.Skip("not root")
21-
}
20+
guest.SkipIfNotInVM(t)
21+
2222
tab, err := RawTablesFromSys()
2323
if err != nil {
2424
t.Fatalf("Got %v, want nil", err)

pkg/acpi/rsdp_linux_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,15 @@ import (
88
"runtime"
99
"testing"
1010

11-
"github.com/u-root/u-root/pkg/testutil"
11+
"github.com/hugelgupf/vmtest/guest"
1212
)
1313

1414
// TestRSDP tests whether any method for getting an RSDP works.
1515
func TestRSDP(t *testing.T) {
16-
testutil.SkipIfNotRoot(t)
17-
16+
guest.SkipIfNotInVM(t)
1817
// Our QEMU aarch64 does not boot via UEFI, so RSDP only works on x86.
1918
if runtime.GOARCH != "amd64" {
20-
t.Skip("RSDP in QEMU only available on amd64 for now")
19+
t.Skipf("Test only supports amd64")
2120
}
2221

2322
_, err := GetRSDP()

0 commit comments

Comments
 (0)
0