-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathtest_utils.py
More file actions
154 lines (139 loc) · 5.05 KB
/
test_utils.py
File metadata and controls
154 lines (139 loc) · 5.05 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# Copyright (c) Contributors to the aswf-docker Project. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
"""
Tests for the utility commands
"""
import unittest
import logging
from click.testing import CliRunner
from aswfdocker import utils, index, constants
from aswfdocker.cli import aswfdocker
class TestUtils(unittest.TestCase):
def test_get_docker_org(self):
self.assertEqual(utils.get_docker_org("", ""), "aswftesting")
self.assertEqual(
utils.get_docker_org(
constants.MAIN_GITHUB_ASWF_DOCKER_URL,
"refs/heads/main",
),
"aswf",
)
self.assertEqual(
utils.get_docker_org(
constants.MAIN_GITHUB_ASWF_DOCKER_URL,
"refs/heads/testing",
),
"aswftesting",
)
self.assertEqual(
utils.get_docker_org(
"https://github.com/randomfork/aswf-docker", "refs/heads/main"
),
"aswflocaltesting",
)
self.assertEqual(
utils.get_docker_org(
"https://github.com/randomfork/aswf-docker", "refs/heads/randombranch"
),
"aswflocaltesting",
)
def test_get_docker_push(self):
self.assertFalse(utils.get_docker_push("", ""))
self.assertTrue(
utils.get_docker_push(
constants.MAIN_GITHUB_ASWF_DOCKER_URL,
"refs/heads/main",
)
)
self.assertTrue(
utils.get_docker_push(
constants.MAIN_GITHUB_ASWF_DOCKER_URL,
"refs/heads/testing",
)
)
self.assertFalse(
utils.get_docker_push(
"https://github.com/randomfork/aswf-docker", "refs/heads/main"
)
)
self.assertFalse(
utils.get_docker_push(
"https://github.com/randomfork/aswf-docker", "refs/heads/randombranch"
)
)
def test_image_def_from_name(self):
with self.assertRaises(RuntimeError):
utils.get_image_spec("aswf/ci-package-openvdb_2018")
self.assertEqual(
utils.get_image_spec("aswftesting/ci-common:1"),
("aswftesting", constants.ImageType.IMAGE, "common", "1"),
)
self.assertEqual(
utils.get_image_spec("aswf/ci-package-openvdb:2018"),
("aswf", constants.ImageType.PACKAGE, "openvdb", "2018"),
)
self.assertEqual(
utils.get_image_spec("refs/tags/aswf/ci-package-openvdb/2018"),
("aswf", constants.ImageType.PACKAGE, "openvdb", "2018"),
)
self.assertEqual(
utils.get_image_spec("aswf/ci-package-clang:1-clang6"),
("aswf", constants.ImageType.PACKAGE, "clang", "1-clang6"),
)
class TestUtilsCli(unittest.TestCase):
def setUp(self):
self._log_handlers = logging.getLogger("").handlers
logging.getLogger("").handlers = []
self.maxDiff = None
def tearDown(self):
logging.getLogger("").handlers = self._log_handlers
def test_cli_getdockerorg(self):
runner = CliRunner()
result = runner.invoke(aswfdocker.cli, ["getdockerorg"])
self.assertEqual(result.exit_code, 0)
self.assertEqual(result.output, "aswftesting")
def test_cli_getdockerorgforced(self):
runner = CliRunner()
result = runner.invoke(
aswfdocker.cli,
[
"--repo-uri",
"https://github.com/AcademySoftwareFoundation/aswf-docker",
"--source-branch",
"refs/heads/main",
"getdockerorg",
],
)
self.assertEqual(result.exit_code, 0)
self.assertEqual(result.output, "aswf")
def test_cli_getdockerpush(self):
runner = CliRunner()
result = runner.invoke(aswfdocker.cli, ["getdockerpush"])
self.assertEqual(result.exit_code, 0)
self.assertEqual(result.output, "false")
def test_cli_packages(self):
runner = CliRunner()
result = runner.invoke(aswfdocker.cli, ["packages"], catch_exceptions=False)
self.assertEqual(result.exit_code, 0)
pkgs = result.output.split("\n")
self.assertGreater(len(pkgs), 20)
clang_version = list(
index.Index().iter_versions(constants.ImageType.PACKAGE, "openssl")
)[0]
self.assertEqual(
pkgs[0],
f"common-wrappers/ci-package-openssl:{clang_version}",
)
def test_cli_images(self):
runner = CliRunner()
result = runner.invoke(aswfdocker.cli, ["images"], catch_exceptions=False)
self.assertEqual(result.exit_code, 0)
imgs = result.output.split("\n")
self.assertGreater(len(imgs), 15)
baseos_gl_conan_version = list(
index.Index().iter_versions(constants.ImageType.IMAGE, "baseos-gl-conan")
)[0]
self.assertEqual(
imgs[0],
f"baseos-gl-conan/ci-baseos-gl-conan:{baseos_gl_conan_version}",
)