package sysuser import "testing" func TestIsSelf(t *testing.T) { if !IsSelf("") { t.Error("empty user must be self") } if cur := Current(); cur != "" && !IsSelf(cur) { t.Errorf("current user %q must be self", cur) } } func TestCommand_Self(t *testing.T) { cmd, err := Command(Current(), "true") if err != nil { t.Fatalf("Command() error: %v", err) } if cmd.Args[0] != "true" { t.Errorf("self command should run directly, got %v", cmd.Args) } } func TestCommand_OtherUserRequiresRoot(t *testing.T) { if IsRoot() { t.Skip("running as root") } if _, err := Command("root", "true"); err == nil { t.Error("running as another user without root should error") } }