diff --git a/tests/root.bats b/tests/root.bats new file mode 100644 index 0000000000000000000000000000000000000000..0b2d94931e537e45d33f91c7f1d3aba70625e905 --- /dev/null +++ b/tests/root.bats @@ -0,0 +1,19 @@ +_test_root () { + name="${1:-$BATS_TEST_DESCRIPTION}" + tag="${2:-latest}" + docker build -t "runas-$name" --build-arg "image=$name:$tag" ./ + docker run --rm -v "$BATS_TEST_DIRNAME:/data" "runas-$name" touch "$name.root" + test "$(id -u)" = "$(stat -c '%u' $name.root)" + test "$(id -g)" = "$(stat -c '%g' $name.root)" +} + +teardown () { + docker image ls --format '{{.ID}}' runas-* | xargs -r docker image rm + rm -f *.touch +} + +@test "ubuntu" { _test_root buildpack-deps bionic; } +@test "debian" { _test_root buildpack-deps stretch; } +@test "centos" { _test_root; } +@test "fedora" { _test_root; } +@test "alpine" { _test_root; } diff --git a/tests/test.bats b/tests/user.bats similarity index 56% rename from tests/test.bats rename to tests/user.bats index 70ceaa9a944b6812bcfe1c6b1786e98b888afcd1..cf18dc12a2ef5129cc57cd7d154f060d994642ef 100644 --- a/tests/test.bats +++ b/tests/user.bats @@ -1,12 +1,3 @@ -_test_root () { - name="${1:-$BATS_TEST_DESCRIPTION}" - tag="${2:-latest}" - docker build -t "runas-$name" --build-arg "image=$name:$tag" ./ - docker run --rm -v "$BATS_TEST_DIRNAME:/data" "runas-$name" touch "$name.root" - test "$(id -u)" = "$(stat -c '%u' $name.root)" - test "$(id -g)" = "$(stat -c '%g' $name.root)" -} - _test_user () { name="${1:-$BATS_TEST_DESCRIPTION}" tag="${2:-latest}" @@ -23,11 +14,6 @@ teardown () { rm -f *.touch } -@test "ubuntu" { _test_root buildpack-deps bionic; } -@test "debian" { _test_root buildpack-deps stretch; } -@test "centos" { _test_root; } -@test "fedora" { _test_root; } -@test "alpine" { _test_root; } @test "ubuntu" { _test_user buildpack-deps bionic; } @test "debian" { _test_user buildpack-deps stretch; } @test "centos" { _test_user; }