Merge pull request #3173 from quay/move-label-validation-tests

Move label validation tests into pytest
This commit is contained in:
Joseph Schorr 2018-07-19 11:22:40 -04:00 committed by GitHub
commit 7a350b9cd1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 45 deletions

View file

@ -1,44 +0,0 @@
import unittest
from util.validation import validate_label_key
class TestLabelKeyValidation(unittest.TestCase):
def assertValidKey(self, key):
self.assertTrue(validate_label_key(key))
def assertInvalidKey(self, key):
self.assertFalse(validate_label_key(key))
def test_basic_keys(self):
self.assertValidKey('foo')
self.assertValidKey('bar')
self.assertValidKey('foo1')
self.assertValidKey('bar2')
self.assertValidKey('1')
self.assertValidKey('12')
self.assertValidKey('123')
self.assertValidKey('1234')
self.assertValidKey('git-sha')
self.assertValidKey('com.coreos.something')
self.assertValidKey('io.quay.git-sha')
def test_invalid_keys(self):
self.assertInvalidKey('')
self.assertInvalidKey('git_sha')
def test_must_start_with_alphanumeric(self):
self.assertInvalidKey('-125')
self.assertInvalidKey('-foo')
self.assertInvalidKey('foo-')
self.assertInvalidKey('123-')
def test_no_double_dashesdots(self):
self.assertInvalidKey('foo--bar')
self.assertInvalidKey('foo..bar')
if __name__ == '__main__':
unittest.main()

View file

@ -1,6 +1,7 @@
import pytest
from util.validation import is_json
from util.validation import is_json, validate_label_key
@pytest.mark.parametrize('string_value,expected', [
('{}', True),
@ -15,3 +16,35 @@ from util.validation import is_json
])
def test_is_json(string_value, expected):
assert is_json(string_value) == expected
@pytest.mark.parametrize('key, is_valid', [
('foo', True),
('bar', True),
('foo1', True),
('bar2', True),
('1', True),
('12', True),
('123', True),
('1234', True),
('git-sha', True),
('com.coreos.something', True),
('io.quay.git-sha', True),
('', False),
('git_sha', False),
('-125', False),
('-foo', False),
('foo-', False),
('123-', False),
('foo--bar', False),
('foo..bar', False),
])
def test_validate_label_key(key, is_valid):
assert validate_label_key(key) == is_valid