test_handler.py 2.5 KB
Newer Older
Yifan Xiong's avatar
Yifan Xiong committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

"""CLI handler test."""

import unittest

import superbench.cli._handler as cli_handler


class CLIHandlerTestCase(unittest.TestCase):
    """A class for CLI handler test cases."""
    def test_split_docker_domain(self):
        """Test split_docker_domain function which splits Docker image name to domain and remainder part.

        Test cases are ported from
        https://github.com/distribution/distribution/blob/v2.7.1/reference/normalize_test.go#L468-L528.
        """
        test_cases = [
            {
                'input': 'test.com/foo',
                'domain': 'test.com',
                'name': 'foo',
            },
            {
                'input': 'test_com/foo',
                'domain': 'docker.io',
                'name': 'test_com/foo',
            },
            {
                'input': 'docker/migrator',
                'domain': 'docker.io',
                'name': 'docker/migrator',
            },
            {
                'input': 'test.com:8080/foo',
                'domain': 'test.com:8080',
                'name': 'foo',
            },
            {
                'input': 'test-com:8080/foo',
                'domain': 'test-com:8080',
                'name': 'foo',
            },
            {
                'input': 'foo',
                'domain': 'docker.io',
                'name': 'library/foo',
            },
            {
                'input': 'xn--n3h.com/foo',
                'domain': 'xn--n3h.com',
                'name': 'foo',
            },
            {
                'input': 'xn--n3h.com:18080/foo',
                'domain': 'xn--n3h.com:18080',
                'name': 'foo',
            },
            {
                'input': 'docker.io/foo',
                'domain': 'docker.io',
                'name': 'library/foo',
            },
            {
                'input': 'docker.io/library/foo',
                'domain': 'docker.io',
                'name': 'library/foo',
            },
            {
                'input': 'docker.io/library/foo/bar',
                'domain': 'docker.io',
                'name': 'library/foo/bar',
            },
        ]
        for test_case in test_cases:
            with self.subTest(msg='Testing with case', test_case=test_case):
                domain, name = cli_handler.split_docker_domain(test_case['input'])
                self.assertEqual(domain, test_case['domain'])
                self.assertEqual(name, test_case['name'])