-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfakeroot_test.go
59 lines (53 loc) · 1.25 KB
/
fakeroot_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package fakeroot_test
import (
"errors"
"os/exec"
"syscall"
"testing"
"lure.sh/fakeroot"
)
func TestCommand(t *testing.T) {
cmd, err := fakeroot.Command("whoami")
if err != nil {
t.Errorf("Unexpected error while creating command: %q", err)
}
data, err := cmd.CombinedOutput()
if err != nil {
t.Errorf("Unexpected error while executing command: %q", err)
}
if sdata := string(data); sdata != "root\n" {
t.Errorf("Expected %q, got %q", "root\n", sdata)
}
}
func TestCommandUIDError(t *testing.T) {
cmd := exec.Command("whoami")
cmd.SysProcAttr = &syscall.SysProcAttr{
UidMappings: []syscall.SysProcIDMap{
{
ContainerID: 0,
HostID: 1000,
Size: 1,
},
},
}
err := fakeroot.Apply(cmd)
if !errors.Is(err, fakeroot.ErrRootUIDAlreadyMapped) {
t.Errorf("Expected error %q, got %q", fakeroot.ErrRootUIDAlreadyMapped, err)
}
}
func TestCommandGIDError(t *testing.T) {
cmd := exec.Command("whoami")
cmd.SysProcAttr = &syscall.SysProcAttr{
GidMappings: []syscall.SysProcIDMap{
{
ContainerID: 0,
HostID: 1000,
Size: 1,
},
},
}
err := fakeroot.Apply(cmd)
if !errors.Is(err, fakeroot.ErrRootGIDAlreadyMapped) {
t.Errorf("Expected error %q, got %q", fakeroot.ErrRootGIDAlreadyMapped, err)
}
}