608ffd9663
Adds basic labels support to the registry code (V2), and the API. Note that this does not yet add any UI related support.
44 lines
No EOL
1.1 KiB
Python
44 lines
No EOL
1.1 KiB
Python
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() |