Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
docker-py
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
docker-py
Commits
cec3fe7c
Kaydet (Commit)
cec3fe7c
authored
Eki 13, 2016
tarafından
Joffrey F
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Update tests to avoid failures on Windows platforms
Signed-off-by:
Joffrey F
<
joffrey@docker.com
>
üst
9fc06b19
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
121 additions
and
82 deletions
+121
-82
build_test.py
tests/integration/build_test.py
+4
-8
conftest.py
tests/integration/conftest.py
+1
-3
container_test.py
tests/integration/container_test.py
+26
-19
image_test.py
tests/integration/image_test.py
+3
-5
network_test.py
tests/integration/network_test.py
+0
-0
api_test.py
tests/unit/api_test.py
+4
-1
container_test.py
tests/unit/container_test.py
+4
-4
fake_api.py
tests/unit/fake_api.py
+3
-0
utils_test.py
tests/unit/utils_test.py
+76
-42
No files found.
tests/integration/build_test.py
Dosyayı görüntüle @
cec3fe7c
import
io
import
json
import
os
import
shutil
import
tempfile
...
...
@@ -22,14 +21,11 @@ class BuildTest(BaseIntegrationTest):
'ADD https://dl.dropboxusercontent.com/u/20637798/silence.tar.gz'
' /tmp/silence.tar.gz'
])
.
encode
(
'ascii'
))
stream
=
self
.
client
.
build
(
fileobj
=
script
,
stream
=
True
)
logs
=
''
stream
=
self
.
client
.
build
(
fileobj
=
script
,
stream
=
True
,
decode
=
True
)
logs
=
[]
for
chunk
in
stream
:
if
six
.
PY3
:
chunk
=
chunk
.
decode
(
'utf-8'
)
json
.
loads
(
chunk
)
# ensure chunk is a single, valid JSON blob
logs
+=
chunk
self
.
assertNotEqual
(
logs
,
''
)
logs
.
append
(
chunk
)
assert
len
(
logs
)
>
0
def
test_build_from_stringio
(
self
):
if
six
.
PY3
:
...
...
tests/integration/conftest.py
Dosyayı görüntüle @
cec3fe7c
from
__future__
import
print_function
import
json
import
sys
import
warnings
...
...
@@ -18,8 +17,7 @@ def setup_test_session():
c
.
inspect_image
(
BUSYBOX
)
except
docker
.
errors
.
NotFound
:
print
(
"
\n
pulling {0}"
.
format
(
BUSYBOX
),
file
=
sys
.
stderr
)
for
data
in
c
.
pull
(
BUSYBOX
,
stream
=
True
):
data
=
json
.
loads
(
data
.
decode
(
'utf-8'
))
for
data
in
c
.
pull
(
BUSYBOX
,
stream
=
True
,
decode
=
True
):
status
=
data
.
get
(
"status"
)
progress
=
data
.
get
(
"progress"
)
detail
=
"{0} - {1}"
.
format
(
status
,
progress
)
...
...
tests/integration/container_test.py
Dosyayı görüntüle @
cec3fe7c
...
...
@@ -3,6 +3,7 @@ import signal
import
tempfile
import
docker
from
docker.constants
import
IS_WINDOWS_PLATFORM
from
docker.utils.socket
import
next_frame_size
from
docker.utils.socket
import
read_exactly
import
pytest
...
...
@@ -523,13 +524,13 @@ class ArchiveTest(BaseIntegrationTest):
def
test_copy_file_to_container
(
self
):
data
=
b
'Deaf To All But The Song'
with
tempfile
.
NamedTemporaryFile
()
as
test_file
:
with
tempfile
.
NamedTemporaryFile
(
delete
=
False
)
as
test_file
:
test_file
.
write
(
data
)
test_file
.
seek
(
0
)
ctnr
=
self
.
client
.
create_container
(
BUSYBOX
,
'cat {0}'
.
format
(
os
.
path
.
join
(
'/vol1'
,
os
.
path
.
basename
(
test_file
.
name
))
os
.
path
.
join
(
'/vol1
/
'
,
os
.
path
.
basename
(
test_file
.
name
))
),
volumes
=
[
'/vol1'
]
)
...
...
@@ -821,11 +822,12 @@ class KillTest(BaseIntegrationTest):
self
.
assertEqual
(
state
[
'Running'
],
False
)
def
test_kill_with_signal
(
self
):
container
=
self
.
client
.
create_container
(
BUSYBOX
,
[
'sleep'
,
'60'
])
id
=
container
[
'Id'
]
self
.
client
.
start
(
id
)
id
=
self
.
client
.
create_container
(
BUSYBOX
,
[
'sleep'
,
'60'
])
self
.
tmp_containers
.
append
(
id
)
self
.
client
.
kill
(
id
,
signal
=
signal
.
SIGKILL
)
self
.
client
.
start
(
id
)
self
.
client
.
kill
(
id
,
signal
=
signal
.
SIGKILL
if
not
IS_WINDOWS_PLATFORM
else
9
)
exitcode
=
self
.
client
.
wait
(
id
)
self
.
assertNotEqual
(
exitcode
,
0
)
container_info
=
self
.
client
.
inspect_container
(
id
)
...
...
@@ -901,28 +903,34 @@ class PortTest(BaseIntegrationTest):
class
ContainerTopTest
(
BaseIntegrationTest
):
def
test_top
(
self
):
container
=
self
.
client
.
create_container
(
BUSYBOX
,
[
'sleep'
,
'60'
])
BUSYBOX
,
[
'sleep'
,
'60'
]
)
id
=
container
[
'Id'
]
self
.
tmp_containers
.
append
(
container
)
self
.
client
.
start
(
container
)
res
=
self
.
client
.
top
(
container
[
'Id'
])
self
.
assertEqual
(
res
[
'Titles'
],
[
'UID'
,
'PID'
,
'PPID'
,
'C'
,
'STIME'
,
'TTY'
,
'TIME'
,
'CMD'
]
)
self
.
assertEqual
(
len
(
res
[
'Processes'
]),
1
)
self
.
assertEqual
(
res
[
'Processes'
][
0
][
7
],
'sleep 60'
)
self
.
client
.
kill
(
id
)
res
=
self
.
client
.
top
(
container
)
if
IS_WINDOWS_PLATFORM
:
assert
res
[
'Titles'
]
==
[
'PID'
,
'USER'
,
'TIME'
,
'COMMAND'
]
else
:
assert
res
[
'Titles'
]
==
[
'UID'
,
'PID'
,
'PPID'
,
'C'
,
'STIME'
,
'TTY'
,
'TIME'
,
'CMD'
]
assert
len
(
res
[
'Processes'
])
==
1
assert
res
[
'Processes'
][
0
][
-
1
]
==
'sleep 60'
self
.
client
.
kill
(
container
)
@pytest.mark.skipif
(
IS_WINDOWS_PLATFORM
,
reason
=
'No psargs support on windows'
)
def
test_top_with_psargs
(
self
):
container
=
self
.
client
.
create_container
(
BUSYBOX
,
[
'sleep'
,
'60'
])
id
=
container
[
'Id'
]
self
.
tmp_containers
.
append
(
container
)
self
.
client
.
start
(
container
)
res
=
self
.
client
.
top
(
container
[
'Id'
]
,
'waux'
)
res
=
self
.
client
.
top
(
container
,
'waux'
)
self
.
assertEqual
(
res
[
'Titles'
],
[
'USER'
,
'PID'
,
'
%
CPU'
,
'
%
MEM'
,
'VSZ'
,
'RSS'
,
...
...
@@ -930,7 +938,6 @@ class ContainerTopTest(BaseIntegrationTest):
)
self
.
assertEqual
(
len
(
res
[
'Processes'
]),
1
)
self
.
assertEqual
(
res
[
'Processes'
][
0
][
10
],
'sleep 60'
)
self
.
client
.
kill
(
id
)
class
RestartContainerTest
(
BaseIntegrationTest
):
...
...
tests/integration/image_test.py
Dosyayı görüntüle @
cec3fe7c
...
...
@@ -55,12 +55,10 @@ class PullImageTest(BaseIntegrationTest):
self
.
client
.
remove_image
(
'hello-world'
)
except
docker
.
errors
.
APIError
:
pass
stream
=
self
.
client
.
pull
(
'hello-world'
,
stream
=
True
)
stream
=
self
.
client
.
pull
(
'hello-world'
,
stream
=
True
,
decode
=
True
)
self
.
tmp_imgs
.
append
(
'hello-world'
)
for
chunk
in
stream
:
if
six
.
PY3
:
chunk
=
chunk
.
decode
(
'utf-8'
)
json
.
loads
(
chunk
)
# ensure chunk is a single, valid JSON blob
assert
isinstance
(
chunk
,
dict
)
self
.
assertGreaterEqual
(
len
(
self
.
client
.
images
(
'hello-world'
)),
1
)
...
...
@@ -150,7 +148,7 @@ class ImportImageTest(BaseIntegrationTest):
@contextlib.contextmanager
def
dummy_tar_file
(
self
,
n_bytes
):
'''Yields the name of a valid tar file of size n_bytes.'''
with
tempfile
.
NamedTemporaryFile
()
as
tar_file
:
with
tempfile
.
NamedTemporaryFile
(
delete
=
False
)
as
tar_file
:
self
.
write_dummy_tar_content
(
n_bytes
,
tar_file
)
tar_file
.
seek
(
0
)
yield
tar_file
.
name
...
...
tests/integration/network_test.py
Dosyayı görüntüle @
cec3fe7c
tests/unit/api_test.py
Dosyayı görüntüle @
cec3fe7c
...
...
@@ -86,7 +86,7 @@ def fake_delete(self, url, *args, **kwargs):
def
fake_read_from_socket
(
self
,
response
,
stream
):
return
six
.
binary_type
()
url_base
=
'
http+docker://localunixsocket/'
url_base
=
'
{0}/'
.
format
(
fake_api
.
prefix
)
url_prefix
=
'{0}v{1}/'
.
format
(
url_base
,
docker
.
constants
.
DEFAULT_DOCKER_API_VERSION
)
...
...
@@ -422,6 +422,9 @@ class StreamTest(base.Cleanup, base.BaseTestCase):
data
+=
connection
.
recv
(
2048
)
@pytest.mark.skipif
(
docker
.
constants
.
IS_WINDOWS_PLATFORM
,
reason
=
'Unix only'
)
def
test_early_stream_response
(
self
):
self
.
request_handler
=
self
.
early_response_sending_handler
lines
=
[]
...
...
tests/unit/container_test.py
Dosyayı görüntüle @
cec3fe7c
...
...
@@ -270,8 +270,8 @@ class CreateContainerTest(DockerClientTest):
{
'Content-Type'
:
'application/json'
})
def
test_create_container_with_cpu_shares
(
self
):
self
.
client
.
create_container
(
'busybox'
,
'ls'
,
cpu_shares
=
5
)
with
pytest
.
deprecated_call
():
self
.
client
.
create_container
(
'busybox'
,
'ls'
,
cpu_shares
=
5
)
args
=
fake_request
.
call_args
self
.
assertEqual
(
args
[
0
][
1
],
...
...
@@ -316,8 +316,8 @@ class CreateContainerTest(DockerClientTest):
{
'Content-Type'
:
'application/json'
})
def
test_create_container_with_cpuset
(
self
):
self
.
client
.
create_container
(
'busybox'
,
'ls'
,
cpuset
=
'0,1'
)
with
pytest
.
deprecated_call
():
self
.
client
.
create_container
(
'busybox'
,
'ls'
,
cpuset
=
'0,1'
)
args
=
fake_request
.
call_args
self
.
assertEqual
(
args
[
0
][
1
],
...
...
tests/unit/fake_api.py
Dosyayı görüntüle @
cec3fe7c
...
...
@@ -408,6 +408,9 @@ def post_fake_update_container():
# Maps real api url to fake response callback
prefix
=
'http+docker://localunixsocket'
if
constants
.
IS_WINDOWS_PLATFORM
:
prefix
=
'http+docker://localnpipe'
fake_responses
=
{
'{0}/version'
.
format
(
prefix
):
get_fake_raw_version
,
...
...
tests/unit/utils_test.py
Dosyayı görüntüle @
cec3fe7c
...
...
@@ -13,7 +13,9 @@ import pytest
import
six
from
docker.client
import
Client
from
docker.constants
import
DEFAULT_DOCKER_API_VERSION
from
docker.constants
import
(
DEFAULT_DOCKER_API_VERSION
,
IS_WINDOWS_PLATFORM
)
from
docker.errors
import
DockerException
,
InvalidVersion
from
docker.utils
import
(
parse_repository_tag
,
parse_host
,
convert_filters
,
kwargs_from_env
,
...
...
@@ -809,6 +811,12 @@ class PortsTest(base.BaseTestCase):
self
.
assertEqual
(
port_bindings
[
"2000"
],
[(
"127.0.0.1"
,
"2000"
)])
def
convert_paths
(
collection
):
if
not
IS_WINDOWS_PLATFORM
:
return
collection
return
set
(
map
(
lambda
x
:
x
.
replace
(
'/'
,
'
\\
'
),
collection
))
class
ExcludePathsTest
(
base
.
BaseTestCase
):
dirs
=
[
'foo'
,
...
...
@@ -843,7 +851,7 @@ class ExcludePathsTest(base.BaseTestCase):
return
set
(
exclude_paths
(
self
.
base
,
patterns
,
dockerfile
=
dockerfile
))
def
test_no_excludes
(
self
):
assert
self
.
exclude
([
''
])
==
self
.
all_paths
assert
self
.
exclude
([
''
])
==
convert_paths
(
self
.
all_paths
)
def
test_no_dupes
(
self
):
paths
=
exclude_paths
(
self
.
base
,
[
'!a.py'
])
...
...
@@ -858,7 +866,9 @@ class ExcludePathsTest(base.BaseTestCase):
Dockerfile and/or .dockerignore, don't exclude them from
the actual tar file.
"""
assert
self
.
exclude
([
'Dockerfile'
,
'.dockerignore'
])
==
self
.
all_paths
assert
self
.
exclude
([
'Dockerfile'
,
'.dockerignore'
])
==
convert_paths
(
self
.
all_paths
)
def
test_exclude_custom_dockerfile
(
self
):
"""
...
...
@@ -877,94 +887,116 @@ class ExcludePathsTest(base.BaseTestCase):
assert
'foo/a.py'
not
in
includes
def
test_single_filename
(
self
):
assert
self
.
exclude
([
'a.py'
])
==
self
.
all_paths
-
set
([
'a.py'
])
assert
self
.
exclude
([
'a.py'
])
==
convert_paths
(
self
.
all_paths
-
set
([
'a.py'
])
)
def
test_single_filename_leading_dot_slash
(
self
):
assert
self
.
exclude
([
'./a.py'
])
==
self
.
all_paths
-
set
([
'a.py'
])
assert
self
.
exclude
([
'./a.py'
])
==
convert_paths
(
self
.
all_paths
-
set
([
'a.py'
])
)
# As odd as it sounds, a filename pattern with a trailing slash on the
# end *will* result in that file being excluded.
def
test_single_filename_trailing_slash
(
self
):
assert
self
.
exclude
([
'a.py/'
])
==
self
.
all_paths
-
set
([
'a.py'
])
assert
self
.
exclude
([
'a.py/'
])
==
convert_paths
(
self
.
all_paths
-
set
([
'a.py'
])
)
def
test_wildcard_filename_start
(
self
):
assert
self
.
exclude
([
'*.py'
])
==
self
.
all_paths
-
set
([
'a.py'
,
'b.py'
,
'cde.py'
,
]
)
assert
self
.
exclude
([
'*.py'
])
==
convert_paths
(
self
.
all_paths
-
set
([
'a.py'
,
'b.py'
,
'cde.py'
])
)
def
test_wildcard_with_exception
(
self
):
assert
self
.
exclude
([
'*.py'
,
'!b.py'
])
==
self
.
all_paths
-
set
([
'a.py'
,
'cde.py'
,
]
)
assert
self
.
exclude
([
'*.py'
,
'!b.py'
])
==
convert_paths
(
self
.
all_paths
-
set
([
'a.py'
,
'cde.py'
])
)
def
test_wildcard_with_wildcard_exception
(
self
):
assert
self
.
exclude
([
'*.*'
,
'!*.go'
])
==
self
.
all_paths
-
set
([
assert
self
.
exclude
([
'*.*'
,
'!*.go'
])
==
convert_paths
(
self
.
all_paths
-
set
([
'a.py'
,
'b.py'
,
'cde.py'
,
'Dockerfile.alt'
,
])
)
def
test_wildcard_filename_end
(
self
):
assert
self
.
exclude
([
'a.*'
])
==
self
.
all_paths
-
set
([
'a.py'
,
'a.go'
])
assert
self
.
exclude
([
'a.*'
])
==
convert_paths
(
self
.
all_paths
-
set
([
'a.py'
,
'a.go'
])
)
def
test_question_mark
(
self
):
assert
self
.
exclude
([
'?.py'
])
==
self
.
all_paths
-
set
([
'a.py'
,
'b.py'
])
assert
self
.
exclude
([
'?.py'
])
==
convert_paths
(
self
.
all_paths
-
set
([
'a.py'
,
'b.py'
])
)
def
test_single_subdir_single_filename
(
self
):
assert
self
.
exclude
([
'foo/a.py'
])
==
self
.
all_paths
-
set
([
'foo/a.py'
])
assert
self
.
exclude
([
'foo/a.py'
])
==
convert_paths
(
self
.
all_paths
-
set
([
'foo/a.py'
])
)
def
test_single_subdir_with_path_traversal
(
self
):
assert
self
.
exclude
([
'foo/whoops/../a.py'
])
==
self
.
all_paths
-
set
([
'foo/a.py'
,
]
)
assert
self
.
exclude
([
'foo/whoops/../a.py'
])
==
convert_paths
(
self
.
all_paths
-
set
([
'foo/a.py'
])
)
def
test_single_subdir_wildcard_filename
(
self
):
assert
self
.
exclude
([
'foo/*.py'
])
==
self
.
all_paths
-
set
([
'foo/a.py'
,
'foo/b.py'
,
]
)
assert
self
.
exclude
([
'foo/*.py'
])
==
convert_paths
(
self
.
all_paths
-
set
([
'foo/a.py'
,
'foo/b.py'
])
)
def
test_wildcard_subdir_single_filename
(
self
):
assert
self
.
exclude
([
'*/a.py'
])
==
self
.
all_paths
-
set
([
'foo/a.py'
,
'bar/a.py'
,
]
)
assert
self
.
exclude
([
'*/a.py'
])
==
convert_paths
(
self
.
all_paths
-
set
([
'foo/a.py'
,
'bar/a.py'
])
)
def
test_wildcard_subdir_wildcard_filename
(
self
):
assert
self
.
exclude
([
'*/*.py'
])
==
self
.
all_paths
-
set
([
'foo/a.py'
,
'foo/b.py'
,
'bar/a.py'
,
]
)
assert
self
.
exclude
([
'*/*.py'
])
==
convert_paths
(
self
.
all_paths
-
set
([
'foo/a.py'
,
'foo/b.py'
,
'bar/a.py'
])
)
def
test_directory
(
self
):
assert
self
.
exclude
([
'foo'
])
==
self
.
all_paths
-
set
([
'foo'
,
'foo/a.py'
,
'foo/b.py'
,
'foo/bar'
,
'foo/bar/a.py'
,
'foo/Dockerfile3'
assert
self
.
exclude
([
'foo'
])
==
convert_paths
(
self
.
all_paths
-
set
([
'foo'
,
'foo/a.py'
,
'foo/b.py'
,
'foo/bar'
,
'foo/bar/a.py'
,
'foo/Dockerfile3'
])
)
def
test_directory_with_trailing_slash
(
self
):
assert
self
.
exclude
([
'foo'
])
==
self
.
all_paths
-
set
([
assert
self
.
exclude
([
'foo'
])
==
convert_paths
(
self
.
all_paths
-
set
([
'foo'
,
'foo/a.py'
,
'foo/b.py'
,
'foo/bar'
,
'foo/bar/a.py'
,
'foo/Dockerfile3'
])
)
def
test_directory_with_single_exception
(
self
):
assert
self
.
exclude
([
'foo'
,
'!foo/bar/a.py'
])
==
self
.
all_paths
-
set
([
assert
self
.
exclude
([
'foo'
,
'!foo/bar/a.py'
])
==
convert_paths
(
self
.
all_paths
-
set
([
'foo/a.py'
,
'foo/b.py'
,
'foo'
,
'foo/bar'
,
'foo/Dockerfile3'
])
)
def
test_directory_with_subdir_exception
(
self
):
assert
self
.
exclude
([
'foo'
,
'!foo/bar'
])
==
self
.
all_paths
-
set
([
'foo/a.py'
,
'foo/b.py'
,
'foo'
,
'foo/Dockerfile3'
assert
self
.
exclude
([
'foo'
,
'!foo/bar'
])
==
convert_paths
(
self
.
all_paths
-
set
([
'foo/a.py'
,
'foo/b.py'
,
'foo'
,
'foo/Dockerfile3'
])
)
def
test_directory_with_wildcard_exception
(
self
):
assert
self
.
exclude
([
'foo'
,
'!foo/*.py'
])
==
self
.
all_paths
-
set
([
'foo/bar'
,
'foo/bar/a.py'
,
'foo'
,
'foo/Dockerfile3'
assert
self
.
exclude
([
'foo'
,
'!foo/*.py'
])
==
convert_paths
(
self
.
all_paths
-
set
([
'foo/bar'
,
'foo/bar/a.py'
,
'foo'
,
'foo/Dockerfile3'
])
)
def
test_subdirectory
(
self
):
assert
self
.
exclude
([
'foo/bar'
])
==
self
.
all_paths
-
set
([
'foo/bar'
,
'foo/bar/a.py'
,
]
)
assert
self
.
exclude
([
'foo/bar'
])
==
convert_paths
(
self
.
all_paths
-
set
([
'foo/bar'
,
'foo/bar/a.py'
])
)
class
TarTest
(
base
.
Cleanup
,
base
.
BaseTestCase
):
...
...
@@ -1023,6 +1055,7 @@ class TarTest(base.Cleanup, base.BaseTestCase):
tar_data
=
tarfile
.
open
(
fileobj
=
archive
)
self
.
assertEqual
(
sorted
(
tar_data
.
getnames
()),
[
'bar'
,
'foo'
])
@pytest.mark.skipif
(
IS_WINDOWS_PLATFORM
,
reason
=
'No symlinks on Windows'
)
def
test_tar_with_file_symlinks
(
self
):
base
=
tempfile
.
mkdtemp
()
self
.
addCleanup
(
shutil
.
rmtree
,
base
)
...
...
@@ -1036,6 +1069,7 @@ class TarTest(base.Cleanup, base.BaseTestCase):
sorted
(
tar_data
.
getnames
()),
[
'bar'
,
'bar/foo'
,
'foo'
]
)
@pytest.mark.skipif
(
IS_WINDOWS_PLATFORM
,
reason
=
'No symlinks on Windows'
)
def
test_tar_with_directory_symlinks
(
self
):
base
=
tempfile
.
mkdtemp
()
self
.
addCleanup
(
shutil
.
rmtree
,
base
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment