-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The bacon_test.py is run on the cli module test phase. If the tests fail, the compilation will also fail. bacon_test.py is used to test the bacon install script.
- Loading branch information
1 parent
48f0a04
commit de3eb5f
Showing
2 changed files
with
131 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters