Skip to content

Commit

Permalink
tests: in case 'go test' is run in a container, skip TestGetPIDLimit()
Browse files Browse the repository at this point in the history
In (standard, non-privileged) container environments the /sys/fs/cgroup
mountpoint is not available. This would cause the tests to fail, as
TestGetPIDLimit() tries to write to the cgroup configuration.

The test will work when run as root on a privileged container or
directly on a host (as Travis CI does).

Setting the CEPH_CSI_RUN_ALL_TESTS environment variable to a non-empty
value will cause the test to be executed.

Signed-off-by: Niels de Vos <ndevos@redhat.com>
  • Loading branch information
nixpanic authored and mergify[bot] committed Apr 2, 2020
1 parent 1557843 commit a1de56d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ env:
- MINIKUBE_VERSION=v1.6.0
- CHANGE_MINIKUBE_NONE_USER=true
- KUBECONFIG=$HOME/.kube/config
# set CEPH_CSI_RUN_ALL_TESTS to non-empty to run all tests
- CEPH_CSI_RUN_ALL_TESTS=true

before_install:
- mkdir -p $GOPATH/bin
Expand Down
4 changes: 4 additions & 0 deletions docs/development-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ tests:

`$ make test`

Certain unit tests may require extended permissions or other external resources
that are not available by default. To run these tests as well, export the
environment variable `CEPH_CSI_RUN_ALL_TESTS=1` before running the tests.

You will need to provide unit tests and functional tests for your changes
wherever applicable.

Expand Down
8 changes: 7 additions & 1 deletion pkg/util/pidlimit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,18 @@ limitations under the License.
package util

import (
"os"
"testing"
)

// minimal test to check if GetPIDLimit() returns an int
// changing the limit require root permissions, not tested
func TestGetPIDLimix(t *testing.T) {
func TestGetPIDLimit(t *testing.T) {
runTest := os.Getenv("CEPH_CSI_RUN_ALL_TESTS")
if runTest == "" {
t.Skip("not running test that requires root permissions and cgroup support")
}

limit, err := GetPIDLimit()

if err != nil {
Expand Down

0 comments on commit a1de56d

Please sign in to comment.