Files
kata-containers/src/runtime/virtcontainers/pkg/rootless/rootless_test.go
Peng Tao a02a8bda66 runtime: move all code to src/runtime
To prepare for merging into kata-containers repository.

Signed-off-by: Peng Tao <bergwolf@hyper.sh>
2020-04-27 19:39:25 -07: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
}