Merge pull request #7745 from ulyssessouza/maintain-version

Preserve the version when specified in the file
This commit is contained in:
Anca Iordache 2020-09-10 14:14:15 +02:00 committed by GitHub
commit bf3002771e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 29 deletions

View File

@ -224,8 +224,6 @@ class ConfigFile(namedtuple('_ConfigFile', 'filename config')):
if version.startswith("1"):
version = V1
else:
version = VERSION
if version == V1:
raise ConfigurationError(

View File

@ -284,7 +284,7 @@ services:
output = yaml.safe_load(result.stdout)
expected = {
'version': str(VERSION),
'version': '2',
'volumes': {'data': {'driver': 'local'}},
'networks': {'front': {}},
'services': {
@ -308,7 +308,7 @@ services:
self.base_dir = 'tests/fixtures/restart'
result = self.dispatch(['config'])
assert yaml.safe_load(result.stdout) == {
'version': str(VERSION),
'version': '2',
'services': {
'never': {
'image': 'busybox',
@ -354,12 +354,12 @@ services:
result = self.dispatch(['config'])
json_result = yaml.safe_load(result.stdout)
assert json_result == {
'version': str(VERSION),
'version': '2.4',
'services': {
'web': {
'command': 'true',
'image': 'alpine:latest',
'ports': [{'target': 5643}, {'target': 9999}]
'ports': ['5643/tcp', '9999/tcp']
}
}
}
@ -369,12 +369,12 @@ services:
result = self.dispatch(['--env-file', '.env2', 'config'])
json_result = yaml.safe_load(result.stdout)
assert json_result == {
'version': str(VERSION),
'version': '2.4',
'services': {
'web': {
'command': 'false',
'image': 'alpine:latest',
'ports': [{'target': 5644}, {'target': 9998}]
'ports': ['5644/tcp', '9998/tcp']
}
}
}
@ -384,12 +384,12 @@ services:
result = self.dispatch(['--project-directory', 'alt/', 'config'])
json_result = yaml.safe_load(result.stdout)
assert json_result == {
'version': str(VERSION),
'version': '2.4',
'services': {
'web': {
'command': 'echo uwu',
'image': 'alpine:3.10.1',
'ports': [{'target': 3341}, {'target': 4449}]
'ports': ['3341/tcp', '4449/tcp']
}
}
}
@ -501,7 +501,7 @@ services:
self.base_dir = 'tests/fixtures/v3-full'
result = self.dispatch(['config'])
assert yaml.safe_load(result.stdout) == {
'version': str(VERSION),
'version': '3.5',
'volumes': {
'foobar': {
'labels': {

View File

@ -160,25 +160,20 @@ class ConfigTest(unittest.TestCase):
}
def test_valid_versions(self):
for version in ['2', '2.0']:
cfg = config.load(
build_config_details({
'services': {
'foo': {'image': 'busybox'},
'bar': {'image': 'busybox', 'environment': ['FOO=1']},
}
})
)
assert cfg.version == VERSION
for version in ['2', '2.0', '2.1', '2.2', '2.3',
'3', '3.0', '3.1', '3.2', '3.3', '3.4', '3.5', '3.6', '3.7', '3.8']:
cfg = config.load(build_config_details({'version': version}))
assert cfg.version == VERSION
cfg = config.load(build_config_details({'version': '2.1'}))
assert cfg.version == VERSION
cfg = config.load(build_config_details({'version': '2.2'}))
assert cfg.version == VERSION
cfg = config.load(build_config_details({'version': '2.3'}))
assert cfg.version == VERSION
for version in ['3', '3.0']:
cfg = config.load(build_config_details({'version': version}))
assert cfg.version == VERSION
cfg = config.load(build_config_details({'version': '3.1'}))
assert cfg.version == VERSION
assert cfg.version == version
def test_v1_file_version(self):
cfg = config.load(build_config_details({'web': {'image': 'busybox'}}))