-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathbacon_test.py
108 lines (84 loc) · 3.64 KB
/
bacon_test.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
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
import bacon_install
import os
import shutil
import subprocess
import tempfile
import unittest
class TestBacon(unittest.TestCase):
def test_create_folder_if_absent(self):
with tempfile.TemporaryDirectory() as f:
# make sure no exceptions thrown
bacon_install.create_folder_if_absent(f)
# create a temp_folder and delete it
temp_folder = tempfile.mkdtemp()
shutil.rmtree(temp_folder)
# see if create_folder_if_absent creates it back
bacon_install.create_folder_if_absent(temp_folder)
self.assertTrue(os.path.exists(temp_folder))
def test_download_link(self):
with tempfile.TemporaryDirectory() as f:
bacon_install.download_link(
"https://repo1.maven.org/maven2/org/jboss/pnc/bacon/cli/maven-metadata.xml",
f, "testme")
self.assertTrue(os.path.exists(os.path.join(f, "testme")))
def test_calculate_sha1(self):
f = tempfile.NamedTemporaryFile(delete=False)
f.write(b"hello\n")
f.close()
self.assertEqual(
bacon_install.calculate_sha1(f.name),
"f572d396fae9206628714fb2ce00f72e94f2258f")
# cleanup
os.remove(f.name)
def test_bacon_install(self):
bacon_jar_location = tempfile.mkdtemp()
shell_location = tempfile.mkdtemp()
maven_link = "https://repo1.maven.org/maven2/org/jboss/pnc/bacon/cli/"
install = bacon_install.BaconInstall(
bacon_jar_location,
shell_location,
maven_link)
install.run()
self.assertTrue(os.path.exists(os.path.join(bacon_jar_location, "bacon.jar")))
self.assertTrue(os.path.exists(os.path.join(shell_location, "bacon")))
self.assertTrue(os.path.exists(os.path.join(shell_location, "da")))
self.assertTrue(os.path.exists(os.path.join(shell_location, "pnc")))
self.assertTrue(os.path.exists(os.path.join(shell_location, "pig")))
# test if bacon.jar runs
bacon_version = subprocess.run([
"java",
"-jar",
os.path.join(bacon_jar_location, "bacon.jar"),
"--version"],
stdout=subprocess.PIPE)
self.assertIn("Bacon version", str(bacon_version.stdout))
self.assertEqual(bacon_version.returncode, 0)
# cleanup
shutil.rmtree(bacon_jar_location)
shutil.rmtree(shell_location)
def test_bacon_install_with_version(self):
bacon_jar_location = tempfile.mkdtemp()
shell_location = tempfile.mkdtemp()
maven_link = "https://repo1.maven.org/maven2/org/jboss/pnc/bacon/cli/"
install = bacon_install.BaconInstall(
bacon_jar_location,
shell_location,
maven_link,
version="2.1.8")
install.run()
self.assertTrue(os.path.exists(os.path.join(bacon_jar_location, "bacon.jar")))
self.assertTrue(os.path.exists(os.path.join(shell_location, "bacon")))
self.assertTrue(os.path.exists(os.path.join(shell_location, "da")))
self.assertTrue(os.path.exists(os.path.join(shell_location, "pnc")))
self.assertTrue(os.path.exists(os.path.join(shell_location, "pig")))
bacon_version = subprocess.run([
"java",
"-jar",
os.path.join(bacon_jar_location, "bacon.jar"),
"--version"],
stdout=subprocess.PIPE)
self.assertTrue("2.1.8", str(bacon_version.stdout))
self.assertEqual(bacon_version.returncode, 0)
# cleanup
shutil.rmtree(bacon_jar_location)
shutil.rmtree(shell_location)