Skip to content
This repository has been archived by the owner on Mar 24, 2020. It is now read-only.

Commit

Permalink
Merge pull request #11 from rn/motest
Browse files Browse the repository at this point in the history
Add mostly volume sharing tests
  • Loading branch information
rn authored Feb 28, 2018
2 parents f5cfa81 + e5c69ba commit 9ca2bb6
Show file tree
Hide file tree
Showing 51 changed files with 1,188 additions and 42 deletions.
2 changes: 1 addition & 1 deletion tests/cases/020_pull/010_multiarch/test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
# LABELS:
# REPEAT:

docker pull --platform linux alpine:3.6
docker pull --platform linux alpine:3.7
if ($lastexitcode -ne 0) { exit 1 }
exit 0
2 changes: 1 addition & 1 deletion tests/cases/020_pull/020_dct/test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
# REPEAT:

$env:DOCKER_CONTENT_TRUST=1
docker pull --platform linux alpine:3.6
docker pull --platform linux alpine:3.7
if ($lastexitcode -ne 0) { exit 1 }
exit 0
23 changes: 0 additions & 23 deletions tests/cases/025_image/020_export/test.ps1

This file was deleted.

2 changes: 1 addition & 1 deletion tests/cases/030_build/010_simple/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
FROM alpine:3.6
FROM alpine:3.7
RUN touch /simple
2 changes: 1 addition & 1 deletion tests/cases/030_build/012_tag/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
FROM alpine:3.6
FROM alpine:3.7
RUN touch /tag
2 changes: 1 addition & 1 deletion tests/cases/030_build/014_iid/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
FROM alpine:3.6
FROM alpine:3.7
RUN touch /iid
2 changes: 1 addition & 1 deletion tests/cases/030_build/016_fail/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
FROM alpine:3.6
FROM alpine:3.7
RUN exit 1
2 changes: 1 addition & 1 deletion tests/cases/030_build/020_build_arg/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
FROM alpine:3.6
FROM alpine:3.7
ARG ARGUMENT
RUN echo ${ARGUMENT}
2 changes: 1 addition & 1 deletion tests/cases/030_build/024_from_build_arg/test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Set-PSDebug -Trace 2

$imageName = "build-from-build-arg"

docker build --platform linux -t $imageName --build-arg IMAGE=alpine:3.6 .
docker build --platform linux -t $imageName --build-arg IMAGE=alpine:3.7 .
if ($lastexitcode -ne 0) {
exit 1
}
Expand Down
2 changes: 1 addition & 1 deletion tests/cases/030_build/026_workdir/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
FROM alpine:3.6
FROM alpine:3.7
WORKDIR /foo
RUN touch workdir
6 changes: 3 additions & 3 deletions tests/cases/030_build/030_multistage/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
FROM alpine:3.6 AS stage0
FROM alpine:3.7 AS stage0
RUN touch /multi0

FROM alpine:3.6 AS stage1
FROM alpine:3.7 AS stage1
RUN touch /multi1

FROM alpine:3.6
FROM alpine:3.7
COPY --from=stage0 /multi0 /
COPY --from=stage1 /multi1 /
4 changes: 2 additions & 2 deletions tests/cases/030_build/032_multistage_scratch/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM alpine:3.6 AS stage0
FROM alpine:3.7 AS stage0
RUN touch /multi-scratch0

FROM alpine:3.6 AS stage1
FROM alpine:3.7 AS stage1
RUN touch /multi-scratch1

FROM scratch
Expand Down
12 changes: 7 additions & 5 deletions tests/cases/060_volume/010_touch/test.ps1
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
# SUMMARY: Simple test that we can create (touch) a file on the host
# SUMMARY: Create (touch) a file on volume mount and check on the host
# LABELS:
# REPEAT:

Set-PSDebug -Trace 2

$fileName = "foobar"

# Make sure the
Remove-Item -Path $fileName -Force
if (Test-Path $fileName) {
Remove-Item -Path $fileName -Force
}

$p = [string]$pwd.Path
docker run --platform linux --rm -v $p`:/test alpine:3.6 touch /test/$fileName
docker run --platform linux --rm -v $p`:/test alpine:3.7 sh -c "touch /test/$fileName"
if ($lastexitcode -ne 0) {
exit 1
}

if (Test-Path $fileName) {
if (Test-Path $fileName -PathType leaf) {
Remove-Item -Path $fileName -Force
exit 0
}
exit 1
28 changes: 28 additions & 0 deletions tests/cases/060_volume/015_echo/test.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# SUMMARY: Create a file on mounted volume and check contents on the host
# LABELS:
# REPEAT:

Set-PSDebug -Trace 2

$fileName = "foobar"

if (Test-Path $fileName) {
Remove-Item -Path $fileName -Force
}

$p = [string]$pwd.Path
docker run --platform linux --rm -v $p`:/test alpine:3.7 sh -c "echo -n $fileName > /test/$fileName"
if ($lastexitcode -ne 0) {
exit 1
}

if (Test-Path $fileName -PathType leaf) {
$content = Get-Content $fileName -Raw
Remove-Item -Path $fileName -Force
if ($content -ne $fileName) {
$content
exit 1
}
exit 0
}
exit 1
23 changes: 23 additions & 0 deletions tests/cases/060_volume/020_mkdir/test.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# SUMMARY: Create a directory on a mounted volume and check on the host
# LABELS:
# REPEAT:

Set-PSDebug -Trace 2

$fileName = "foobar"

if (Test-Path $fileName) {
Remove-Item -Path $fileName -Force
}

$p = [string]$pwd.Path
docker run --platform linux --rm -v $p`:/test alpine:3.7 sh -c "mkdir /test/$fileName"
if ($lastexitcode -ne 0) {
exit 1
}

if (Test-Path $fileName -PathType container) {
Remove-Item -Path $fileName -Force
exit 0
}
exit 1
26 changes: 26 additions & 0 deletions tests/cases/060_volume/022_mkdir_host/test.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# SUMMARY: Create a sub-directory on a mounted volume and check on the host
# LABELS:
# REPEAT:

Set-PSDebug -Trace 2

$baseName = "foobar"
$fileName = "baz"

if (Test-Path $fileName) {
Remove-Item -Path $fileName -Force -Recurse
}

New-Item -ItemType directory $baseName

$p = [string]$pwd.Path
docker run --platform linux --rm -v $p`:/test alpine:3.7 sh -c "mkdir /test/$baseName/$fileName"
if ($lastexitcode -ne 0) {
exit 1
}

if (Test-Path $baseName\$fileName -PathType container) {
Remove-Item -Path $baseName -Force -Recurse
exit 0
}
exit 1
24 changes: 24 additions & 0 deletions tests/cases/060_volume/025_mkdir_p/test.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# SUMMARY: Create directories on a mounted volume and check on the host
# LABELS:
# REPEAT:

Set-PSDebug -Trace 2

$fileName = "foo/bar"
$fileNameWin = "foo\bar"

if (Test-Path $fileNameWin) {
Remove-Item -Path $fileNameWin -Force
}

$p = [string]$pwd.Path
docker run --platform linux --rm -v $p`:/test alpine:3.7 sh -c "mkdir -p /test/$fileName"
if ($lastexitcode -ne 0) {
exit 1
}

if (Test-Path $fileNameWin -PathType container) {
Remove-Item -Path $fileNameWin -Force
exit 0
}
exit 1
25 changes: 25 additions & 0 deletions tests/cases/060_volume/030_rmdir_host/test.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# SUMMARY: Remove a subdir create on the host in a container
# LABELS:
# REPEAT:

Set-PSDebug -Trace 2

$dirName = "foobar"

if (Test-Path $dirName) {
Remove-Item -Path $dirName -Force -Recurse
}

New-Item -ItemType directory $dirName

$p = [string]$pwd.Path
docker run --platform linux --rm -v $p`:/test alpine:3.7 sh -c "rmdir /test/$dirName"
if ($lastexitcode -ne 0) {
exit 1
}

if (Test-Path $dirName) {
Remove-Item -Path $baseName -Force -Recurse
exit 1
}
exit 0
3 changes: 3 additions & 0 deletions tests/cases/060_volume/035_rmdir_nonempty/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM alpine:3.7
COPY rmdir_test.sh /
RUN chmod ugo+x rmdir_test.sh
15 changes: 15 additions & 0 deletions tests/cases/060_volume/035_rmdir_nonempty/rmdir_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh

set -e
set -x

DIR=$1

cd "$DIR" || exit 1
rm -rf foo
mkdir foo
touch foo/bar
(rmdir foo 2> output || true)
cat output
rm -rf foo
grep "Directory not empty" output
19 changes: 19 additions & 0 deletions tests/cases/060_volume/035_rmdir_nonempty/test.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# SUMMARY: Try to remove a non-empty sub-directory on a mounted volume
# LABELS:
# REPEAT:

Set-PSDebug -Trace 2

$imageName = "rmdir-nonempty"

docker build --platform linux -t $imageName .
if ($lastexitcode -ne 0) {
exit 1
}

$p = [string]$pwd.Path
docker run --rm -v $p`:/test $imageName /rmdir_test.sh /test
if ($lastexitcode -ne 0) {
exit 1
}
exit 0
3 changes: 3 additions & 0 deletions tests/cases/060_volume/050_symlink_volume/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM alpine:3.7
COPY symlink_test.sh /
RUN chmod ugo+x symlink_test.sh
21 changes: 21 additions & 0 deletions tests/cases/060_volume/050_symlink_volume/symlink_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/sh

set -e
set -x

FILE=$1
LINK=$2
CONTENT="foo"

echo "$CONTENT" > $FILE
ln -s "$FILE" "$LINK"

if [[ $(readlink "$LINK") != "$FILE" ]]; then
echo "Symlink $LINK is not pointing to $FILE"
exit 1
fi

if [[ $(cat "$LINK") != "$CONTENT" ]]; then
echo "Contents don't match"
exit 1
fi
37 changes: 37 additions & 0 deletions tests/cases/060_volume/050_symlink_volume/test.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# SUMMARY: Create a symlink on a volume mount and check in container
# LABELS:
# REPEAT:

Set-PSDebug -Trace 2

$imageName = "symlink-container"
$fileName = "foobar"
$linkName = "barfoo"

if (Test-Path $fileName) {
Remove-Item -Path $fileName -Force
}
if (Test-Path $linkName) {
Remove-Item -Path $linkName -Force
}

docker build --platform linux -t $imageName .
if ($lastexitcode -ne 0) {
exit 1
}

$p = [string]$pwd.Path
docker run --rm -v $p`:/test $imageName /symlink_test.sh /test/$fileName /test/$linkName
if ($lastexitcode -ne 0) {
if (Test-Path $fileName) {
Remove-Item -Path $fileName -Force
}
if (Test-Path $linkName) {
Remove-Item -Path $linkName -Force
}
exit 1
}

Remove-Item -Path $fileName -Force
Remove-Item -Path $linkName -Force
exit 0
3 changes: 3 additions & 0 deletions tests/cases/060_volume/055_hardlink_volume/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM alpine:3.7
COPY hardlink_test.sh /
RUN chmod ugo+x hardlink_test.sh
31 changes: 31 additions & 0 deletions tests/cases/060_volume/055_hardlink_volume/hardlink_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/sh

set -e
set -x

FILE=$1
LINK=$2
CONTENT="foo"

echo "$CONTENT" > $FILE
ln "$FILE" "$LINK"

if [[ $(stat -c %h "$FILE") != $(stat -c %h "$LINK") ]]; then
echo "Number of hardlinks don't match"
exit 1
fi

if [[ $(stat -c %i "$FILE") != $(stat -c %i "$LINK") ]]; then
echo "Inode numbers don't match"
exit 1
fi

if [[ $(stat -c %h "$FILE") <= 1 ]]; then
echo "$FILE should Number of hardlinks greater than 1"
exit 1
fi

if [[ $(cat "$LINK") != "$CONTENT" ]]; then
echo "Contents don't match"
exit 1
fi
Loading

0 comments on commit 9ca2bb6

Please sign in to comment.