Files
kata-containers/virtcontainers/pkg/rootless/rootless_test.go
Julio Montes c36c667b10 cli: implement --rootless option
By default virtcontainer auto-detects if the current process is running
rootless or not, but this behavior can change from commandline with the
--rootless option

fixes #2417

Signed-off-by: Julio Montes <julio.montes@intel.com>
2020-02-12 19:09:32 +00:00

37 lines
585 B
Go

// Copyright (c) 2020 Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0
//
package rootless
import (
"os"
"testing"
"github.com/opencontainers/runc/libcontainer/system"
"github.com/stretchr/testify/assert"
)
func TestIsRootless(t *testing.T) {
assert := assert.New(t)
isRootless = nil
var rootless bool
if os.Getuid() != 0 {
rootless = true
} else {
rootless = system.RunningInUserNS()
}
assert.Equal(rootless, isRootlessFunc())
SetRootless(true)
assert.True(isRootlessFunc())
SetRootless(false)
assert.False(isRootlessFunc())
isRootless = nil
}