forked from zeromsi/pipeline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_koparse.py
executable file
·65 lines (50 loc) · 2.91 KB
/
test_koparse.py
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
#!/usr/bin/env python3.6
import os
import unittest
import koparse
IMAGE_BASE = "gcr.io/tekton-releases/github.com/tektoncd/pipeline/cmd/"
PATH_TO_TEST_RELEASE_YAML = os.path.join(os.path.dirname(
os.path.abspath(__file__)), "test_release.yaml")
PATH_TO_WRONG_FILE = os.path.join(os.path.dirname(
os.path.abspath(__file__)), "koparse.py")
BUILT_IMAGES = [
"gcr.io/tekton-releases/github.com/tektoncd/pipeline/cmd/kubeconfigwriter@sha256:68453f5bb4b76c0eab98964754114d4f79d3a50413872520d8919a6786ea2b35",
"gcr.io/tekton-releases/github.com/tektoncd/pipeline/cmd/creds-init@sha256:67448da79e4731ab534b91df08da547bc434ab08e41d905858f2244e70290f48",
"gcr.io/tekton-releases/github.com/tektoncd/pipeline/cmd/git-init@sha256:7d5520efa2d55e1346c424797988c541327ee52ef810a840b5c6f278a9de934a",
"gcr.io/tekton-releases/github.com/tektoncd/pipeline/cmd/controller@sha256:bdc6f22a44944c829983c30213091b60f490b41f89577e8492f6a2936be0df41",
"gcr.io/tekton-releases/github.com/tektoncd/pipeline/cmd/webhook@sha256:cca7069a11aaf0d9d214306d456bc40b2e33e5839429bf07c123ad964d495d8a",
]
EXPECTED_IMAGES = [
"gcr.io/tekton-releases/github.com/tektoncd/pipeline/cmd/kubeconfigwriter",
"gcr.io/tekton-releases/github.com/tektoncd/pipeline/cmd/creds-init",
"gcr.io/tekton-releases/github.com/tektoncd/pipeline/cmd/git-init",
"gcr.io/tekton-releases/github.com/tektoncd/pipeline/cmd/controller",
"gcr.io/tekton-releases/github.com/tektoncd/pipeline/cmd/webhook",
]
class TestKoparse(unittest.TestCase):
def test_parse_release(self):
images = koparse.parse_release(IMAGE_BASE, PATH_TO_TEST_RELEASE_YAML)
self.assertListEqual(images, BUILT_IMAGES)
def test_parse_release_no_file(self):
with self.assertRaises(IOError):
koparse.parse_release(IMAGE_BASE, "whoops")
def test_parse_release_wrong_contents(self):
images = koparse.parse_release(IMAGE_BASE, PATH_TO_WRONG_FILE)
self.assertEqual(images, [])
def test_compare_expected_images(self):
koparse.compare_expected_images(EXPECTED_IMAGES, BUILT_IMAGES)
def test_compare_expected_images_bad_format(self):
with self.assertRaises(koparse.BadActualImageFormatError):
koparse.compare_expected_images(EXPECTED_IMAGES, EXPECTED_IMAGES)
def test_compare_expected_images_missing(self):
extra_expected = (EXPECTED_IMAGES[:] +
["gcr.io/knative-releases/something-else"])
with self.assertRaises(koparse.ImagesMismatchError):
koparse.compare_expected_images(extra_expected, BUILT_IMAGES)
def test_compare_expected_images_too_many(self):
extra_actual = (BUILT_IMAGES[:] +
["gcr.io/knative-releases/something-else@sha256:somedigest"])
with self.assertRaises(koparse.ImagesMismatchError):
koparse.compare_expected_images(EXPECTED_IMAGES, extra_actual)
if __name__ == "__main__":
unittest.main()