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

Add a lot more tests #16

Merged
merged 17 commits into from
Mar 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions tests/cases/020_image/010_pull/030_pub-registry/test.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# SUMMARY: Pull an image from a different public registry (gcr.io)
# LABELS:
# REPEAT:

docker pull --platform linux gcr.io/google_containers/k8s-dns-sidecar-amd64:1.14.7
if ($lastexitcode -ne 0) { exit 1 }
exit 0
13 changes: 9 additions & 4 deletions tests/cases/020_image/020_build/014_iid/test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@

Set-PSDebug -Trace 2

$ret = 0

$imageName = "build-iid"
$imageIIDFile = "build-iid.file"

Remove-Item -Path $imageIIDFile -Force -Recurse -ErrorAction Ignore

docker build --platform linux -t $imageName --iidfile $imageIIDFile .
if ($lastexitcode -ne 0) {
exit 1
Expand All @@ -20,12 +24,13 @@ $iid = Get-Content $imageIIDFile -Raw

docker inspect $iid
if ($lastexitcode -ne 0) {
exit 1
$ret = 1
}

docker rmi $iid
if ($lastexitcode -ne 0) {
exit 1
$ret = 1
}
Remove-Item -Path $imageIIDFile -Force
exit 0

Remove-Item -Path $imageIIDFile -Force -Recurse -ErrorAction Ignore
exit $ret
10 changes: 6 additions & 4 deletions tests/cases/020_image/020_build/020_build_arg/test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

Set-PSDebug -Trace 2

$ret = 0

$imageName = "build-arg"

$output = [string] (& docker build --platform linux -t $imageName --build-arg ARGUMENT=foobar . 2>&1)
Expand All @@ -18,16 +20,16 @@ $output
# Check that it echoed the right thing
$tmp = $output | select-string "foobar" -SimpleMatch
if ($tmp.length -eq 0) {
exit 1
$ret = 1
}

docker inspect $imageName
if ($lastexitcode -ne 0) {
exit 1
$ret = 1
}

docker rmi $imageName
if ($lastexitcode -ne 0) {
exit 1
$ret = 1
}
exit 0
exit $ret
8 changes: 5 additions & 3 deletions tests/cases/020_image/020_build/022_from_scratch/test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

Set-PSDebug -Trace 2

$ret = 0

$imageName = "build-from-scratch"

docker build --platform linux -t $imageName .
Expand All @@ -16,11 +18,11 @@ if ($lastexitcode -ne 0) {

docker inspect $imageName
if ($lastexitcode -ne 0) {
exit 1
$ret = 1
}

docker rmi $imageName
if ($lastexitcode -ne 0) {
exit 1
$ret = 1
}
exit 0
exit $ret
8 changes: 5 additions & 3 deletions tests/cases/020_image/020_build/024_from_build_arg/test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

Set-PSDebug -Trace 2

$ret = 0

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

docker build --platform linux -t $imageName --build-arg IMAGE=alpine:3.7 .
Expand All @@ -15,11 +17,11 @@ if ($lastexitcode -ne 0) {

docker inspect $imageName
if ($lastexitcode -ne 0) {
exit 1
$ret = 1
}

docker rmi $imageName
if ($lastexitcode -ne 0) {
exit 1
$ret = 1
}
exit 0
exit $ret
8 changes: 5 additions & 3 deletions tests/cases/020_image/020_build/026_workdir/test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

Set-PSDebug -Trace 2

$ret = 0

$imageName = "build-workdir"

docker build --platform linux -t $imageName .
Expand All @@ -15,11 +17,11 @@ if ($lastexitcode -ne 0) {

docker inspect $imageName
if ($lastexitcode -ne 0) {
exit 1
$ret = 1
}

docker rmi $imageName
if ($lastexitcode -ne 0) {
exit 1
$ret = 1
}
exit 0
exit $ret
8 changes: 5 additions & 3 deletions tests/cases/020_image/020_build/030_multistage/test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

Set-PSDebug -Trace 2

$ret = 0

$imageName = "build-multi-stage"

docker build --platform linux -t $imageName .
Expand All @@ -15,11 +17,11 @@ if ($lastexitcode -ne 0) {

docker inspect $imageName
if ($lastexitcode -ne 0) {
exit 1
$ret = 1
}

docker rmi $imageName
if ($lastexitcode -ne 0) {
exit 1
$ret = 1
}
exit 0
exit $ret
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
# See:
# https://github.com/Microsoft/opengcs/issues/169
# https://github.com/moby/moby/issues/35413
# https://github.com/moby/moby/issues/36115
# https://github.com/Microsoft/opengcs/issues/156


Set-PSDebug -Trace 2

$ret = 0

$imageName = "build-multi-stage-scratch"

docker build --platform linux -t $imageName .
Expand All @@ -18,11 +21,11 @@ if ($lastexitcode -ne 0) {

docker inspect $imageName
if ($lastexitcode -ne 0) {
exit 1
$ret = 1
}

docker rmi $imageName
if ($lastexitcode -ne 0) {
exit 1
$ret = 1
}
exit 0
exit $ret
38 changes: 38 additions & 0 deletions tests/cases/020_image/020_build/100_copy/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
FROM alpine:3.7

# Copy a file
COPY /Dockerfile .
COPY /test.ps1 /

# Copy a file to non-existing destination and directory
COPY /Dockerfile /bar/Dockerfile
COPY /Dockerfile /foo/bar/baz/
COPY Dockerfile test.ps1 /baz/

# Copy a directory to root or another directory
COPY folder1 /
COPY folder1 /dest1

# Copy a nested directory
COPY folder2 /
COPY folder2 /dest2/

# Relative to WORKDIR
WORKDIR /work
COPY Dockerfile .

# verify. These are separate RUN commands to make it easier to debug
RUN test -f /Dockerfile
RUN test -f /test.ps1

RUN test -f /bar/Dockerfile
RUN test -f /foo/bar/baz/Dockerfile
RUN test -f /baz/Dockerfile && test -f /baz/test.ps1

RUN test -f /Dockerfile
RUN test -f /dest1/Dockerfile

RUN test -f /folder3/test.ps1 && test -f /folder3/Dockerfile
RUN test -f /dest2/folder3/test.ps1 && test -f /dest2/folder3/Dockerfile

RUN test -f /work/Dockerfile
44 changes: 44 additions & 0 deletions tests/cases/020_image/020_build/100_copy/test.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# SUMMARY: Test COPY variations
# LABELS:
# REPEAT:
# See:
# https://github.com/moby/moby/issues/36353

Set-PSDebug -Trace 2

$ret = 0

$imageName = "build-copy"
$testDir1 = "folder1"
$testDir2 = "folder2"
$testDir3 = "folder3"

Remove-Item -Path $testDir1 -Force -Recurse -ErrorAction Ignore
Remove-Item -Path $testDir2 -Force -Recurse -ErrorAction Ignore
New-Item -ItemType Directory -Force -Path $testDir1
New-Item -ItemType Directory -Force -Path $testDir2\$testDir3
Copy-Item Dockerfile $testDir1
Copy-Item test.ps1 $testDir2\$testDir3\
Copy-Item Dockerfile $testDir2\$testDir3\
# After this we should have
# - Dockerfile
# - test.ps1
# - folder1
# - Dockerfile
# - folder2
# - folder3
# - test.ps1
# - Dockerfile

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

Remove-Item -Path $testDir1 -Force -Recurse -ErrorAction Ignore
Remove-Item -Path $testDir2 -Force -Recurse -ErrorAction Ignore
exit $ret
12 changes: 7 additions & 5 deletions tests/cases/020_image/030_save/test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

Set-PSDebug -Trace 2

$ret = 0

$fileName = "hello-world.tar"

docker pull --platform linux hello-world
Expand All @@ -13,11 +15,11 @@ if ($lastexitcode -ne 0) {

docker image save -o $fileName hello-world
if ($lastexitcode -ne 0) {
exit 1
$ret = 1
}

if (Test-Path $fileName) {
Remove-Item -Path $fileName -Force
exit 0
if (!(Test-Path $fileName)) {
$ret = 1
}
exit 1
Remove-Item -Path $fileName -Force -Recurse -ErrorAction Ignore
exit $ret
18 changes: 18 additions & 0 deletions tests/cases/030_container/030_run/030_user/test.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# SUMMARY: Verify that docker container run --user works
# LABELS:
# REPEAT:

Set-PSDebug -Trace 2

$output = [string] (& docker container run --platform linux --rm --user postgres alpine:3.7 id 2>&1)
if ($lastexitcode -ne 0) {
$output
exit 1
}
$output

$tmp = $output | select-string "(postgres)" -SimpleMatch
if ($tmp.length -eq 0) {
exit 1
}
exit 0
18 changes: 18 additions & 0 deletions tests/cases/030_container/030_run/035_env/test.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# SUMMARY: Verify that docker container run --env works
# LABELS:
# REPEAT:

Set-PSDebug -Trace 2

$output = [string] (& docker container run --platform linux --rm --env FOOBAR=foobar alpine:3.7 env 2>&1)
if ($lastexitcode -ne 0) {
$output
exit 1
}
$output

$tmp = $output | select-string "FOOBAR=foobar" -SimpleMatch
if ($tmp.length -eq 0) {
exit 1
}
exit 0
18 changes: 18 additions & 0 deletions tests/cases/030_container/030_run/040_workdir/test.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# SUMMARY: Verify that docker container run --workdir works
# LABELS:
# REPEAT:

Set-PSDebug -Trace 2

$output = [string] (& docker container run --platform linux --rm --workdir /foobar alpine:3.7 pwd 2>&1)
if ($lastexitcode -ne 0) {
$output
exit 1
}
$output

$tmp = $output | select-string "/foobar" -SimpleMatch
if ($tmp.length -eq 0) {
exit 1
}
exit 0
11 changes: 11 additions & 0 deletions tests/cases/030_container/030_run/050_read-only/test.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# SUMMARY: Verify docker run --read-only works
# LABELS:
# REPEAT:

Set-PSDebug -Trace 2

docker container run --platform linux --rm --read-only alpine:3.7 touch /foobar
if ($lastexitcode -eq 0) {
exit 1
}
exit 0
13 changes: 13 additions & 0 deletions tests/cases/030_container/030_run/100_privileged/test.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# SUMMARY: Verify that docker container run --privileged works
# LABELS:
# REPEAT:

Set-PSDebug -Trace 2

$output = [string] (& docker container run --platform linux --rm --privileged alpine:3.7 id 2>&1)
if ($lastexitcode -ne 0) {
$output
exit 1
}
$output
exit 0
Loading