|
1 | 1 | import subprocess
|
| 2 | +import sys |
| 3 | +from os.path import basename |
2 | 4 |
|
3 | 5 |
|
4 | 6 | def test_disl_exceeds_limit(image_name: str) -> None:
|
@@ -58,3 +60,92 @@ def test_disl_max_layers(image_name: str) -> None:
|
58 | 60 | assert process.returncode == 1
|
59 | 61 | assert 'maximum layers by' in output
|
60 | 62 | assert image_name in output
|
| 63 | + |
| 64 | + |
| 65 | +def test_disl_current_size(image_name: str) -> None: |
| 66 | + """Runs `disl` command with --current-size flag.""" |
| 67 | + process = subprocess.Popen( |
| 68 | + [ |
| 69 | + 'disl', |
| 70 | + image_name, |
| 71 | + '1 kb', |
| 72 | + '--current-size', |
| 73 | + ], |
| 74 | + stdout=subprocess.PIPE, |
| 75 | + stderr=subprocess.PIPE, |
| 76 | + universal_newlines=True, |
| 77 | + encoding='utf8', |
| 78 | + ) |
| 79 | + output, _ = process.communicate() |
| 80 | + |
| 81 | + assert process.returncode == 1 |
| 82 | + assert 'current size is' in output |
| 83 | + assert image_name in output |
| 84 | + |
| 85 | + |
| 86 | +def test_disl_exit_zero(image_name: str) -> None: |
| 87 | + """Runs `disl` command with --exit-zero flag.""" |
| 88 | + process = subprocess.Popen( |
| 89 | + [ |
| 90 | + 'disl', |
| 91 | + image_name, |
| 92 | + '1 kb', |
| 93 | + '--current-size', |
| 94 | + '--exit-zero', |
| 95 | + ], |
| 96 | + stdout=subprocess.PIPE, |
| 97 | + stderr=subprocess.PIPE, |
| 98 | + universal_newlines=True, |
| 99 | + encoding='utf8', |
| 100 | + ) |
| 101 | + output, _ = process.communicate() |
| 102 | + |
| 103 | + assert process.returncode == 0 |
| 104 | + assert 'current size is' in output |
| 105 | + assert image_name in output |
| 106 | + |
| 107 | + |
| 108 | +def test_docker_image_size_limit_as_module(image_name: str) -> None: |
| 109 | + """Runs `disl` command with --exit-zero flag.""" |
| 110 | + interpreter_binary_name = basename(sys.executable) |
| 111 | + process = subprocess.Popen( |
| 112 | + [ |
| 113 | + '{0}'.format(interpreter_binary_name), |
| 114 | + '-m', |
| 115 | + 'docker_image_size_limit', |
| 116 | + image_name, |
| 117 | + '1 kb', |
| 118 | + '--current-size', |
| 119 | + '--exit-zero', |
| 120 | + ], |
| 121 | + stdout=subprocess.PIPE, |
| 122 | + stderr=subprocess.PIPE, |
| 123 | + universal_newlines=True, |
| 124 | + encoding='utf8', |
| 125 | + ) |
| 126 | + output, _ = process.communicate() |
| 127 | + |
| 128 | + assert process.returncode == 0 |
| 129 | + assert 'current size is' in output |
| 130 | + assert image_name in output |
| 131 | + |
| 132 | + |
| 133 | +def test_docker_image_size_limit_as_module_help_flag(image_name: str) -> None: # noqa: WPS118,E501 |
| 134 | + """Runs `disl` command via it python module.""" |
| 135 | + interpreter_binary_name = basename(sys.executable) |
| 136 | + process = subprocess.Popen( |
| 137 | + [ |
| 138 | + '{0}'.format(interpreter_binary_name), |
| 139 | + '-m', |
| 140 | + 'docker_image_size_limit', |
| 141 | + '--help', |
| 142 | + ], |
| 143 | + stdout=subprocess.PIPE, |
| 144 | + stderr=subprocess.PIPE, |
| 145 | + universal_newlines=True, |
| 146 | + encoding='utf8', |
| 147 | + ) |
| 148 | + output, _ = process.communicate() |
| 149 | + |
| 150 | + assert process.returncode == 0 |
| 151 | + assert 'docker_image_size_limit' in output |
0 commit comments