harbor/make/photon/prepare/test_purgeuploads.py
stonezdj 17d8b7b813 Add upload purge config to registry/config.yml
Enable the uploadpurging by default
  Fixes #15641

Signed-off-by: stonezdj <stonezdj@gmail.com>
2022-01-04 11:15:51 +08:00

89 lines
2.4 KiB
Python

import unittest
from models import PurgeUpload
class TestPurgeUploadsDefault(unittest.TestCase):
def test_validate_config(self):
purge_config = dict([
('enabled',True),
('age','168h'),
('interval','24h'),
('dryrun', False),
])
cfg = PurgeUpload(purge_config)
cfg.validate()
def test_validate_config(self):
purge_config = dict([
('enabled','false'),
('age','168h'),
('interval','24h'),
('dryrun', 'false'),
])
cfg = PurgeUpload(purge_config)
cfg.validate()
def test_validate_config_2hour(self):
purge_config = dict([
('enabled',True),
('age','2h'),
('interval','2h'),
('dryrun', False),
])
cfg = PurgeUpload(purge_config)
cfg.validate()
def test_validate_config_1hour(self):
purge_config = dict([
('enabled',True),
('age','1h'),
('interval','1h'),
('dryrun', False),
])
cfg = PurgeUpload(purge_config)
with self.assertRaises(Exception):
cfg.validate()
def test_validate_config_invalid_format(self):
purge_config = dict([
('enabled',True),
('age','1s'),
('interval','1s'),
('dryrun', False),
])
cfg = PurgeUpload(purge_config)
with self.assertRaises(Exception):
cfg.validate()
def test_validate_config_invalid_format(self):
purge_config = dict([
('enabled',True),
('age',168),
('interval',24),
('dryrun', False),
])
cfg = PurgeUpload(purge_config)
with self.assertRaises(Exception):
cfg.validate()
def test_validate_config_disabled_invalid_format(self):
purge_config = dict([
('enabled',"false"),
('age','ssh'),
('interval','ssh'),
('dryrun', False),
])
cfg = PurgeUpload(purge_config)
cfg.validate()
def test_validate_config_invalid_string(self):
purge_config = dict([
('enabled',True),
('age','ssh'),
('interval','ssh'),
('dryrun', False),
])
cfg = PurgeUpload(purge_config)
with self.assertRaises(Exception):
cfg.validate()