Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Packaged tacos have version in file name #912

Merged
merged 2 commits into from
Oct 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion connector-packager/connector_packager/package.py
Original file line number Diff line number Diff line change
@@ -125,7 +125,7 @@ def main():
return

package_dest_path = Path(args.dest)
package_name = xmlparser.class_name + PACKAGED_EXTENSION
package_name = xmlparser.class_name + "-v" + xmlparser.connector_version + PACKAGED_EXTENSION

if not jdk_create_jar(path_from_args, files_to_package, package_name, package_dest_path):
logger.info("Taco packaging failed. Check " + str(log_file) + " for more information.")
6 changes: 6 additions & 0 deletions connector-packager/connector_packager/xml_parser.py
Original file line number Diff line number Diff line change
@@ -39,6 +39,7 @@ def __init__(self, path_to_folder: Path):
self.class_name = None # Get this from the class name in the manifest file
self.file_list = [] # list of files to package
self.loc_strings = [] # list of loc strings so we can make sure they are covered in the resource files.
self.connector_version = None # Get ths from the plugin-version attribute in the manifest
self.null_oauth_config_found = False # whether or not we found a null oauth config
self.num_oauth_configs_found = 0 # number of oauth configs found, so we can fail the connector if there are non-null cconfigs and a null config

@@ -245,6 +246,11 @@ def parse_file(self, file_to_parse: ConnectorFile) -> bool:
file_to_parse.file_name)
return False

# Set the connector version
if 'plugin-version' in child.attrib:
logging.debug("Found connector version: " + child.attrib['plugin-version'])
self.connector_version = child.attrib['plugin-version']

# If an attribute has @string, then add that string to the loc_strings list.
for key, value in child.attrib.items():
if value.startswith(TRANSLATABLE_STRING_PREFIX):
2 changes: 1 addition & 1 deletion connector-packager/tests/test_package.py
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ class TestPackage(unittest.TestCase):

def test_package_main(self):

expected_package_name = "postgres_odbc"
expected_package_name = "postgres_odbc-v0.0.0"
expected_dest_directory = Path("tests/test_resources/jars")
files_directory = Path("tests/test_resources/valid_connector")

30 changes: 20 additions & 10 deletions connector-packager/tests/test_xml_parser.py
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@ def test_generate_file_list(self):

# Test valid connector
expected_class_name = "postgres_odbc"
expected_connector_version = "0.0.0"
expected_file_list = [
ConnectorFile("manifest.xml", "manifest"),
ConnectorFile("connection-dialog.tcd", "connection-dialog"),
@@ -21,40 +22,43 @@ def test_generate_file_list(self):
ConnectorFile("connectionResolver.tdr", "connection-resolver"),
ConnectorFile("resources-en_US.xml", "resource")]

actual_file_list, actual_class_name = self.parser_test_case(TEST_FOLDER / Path("valid_connector"),
actual_file_list, actual_class_name, actual_connector_version = self.parser_test_case(TEST_FOLDER / Path("valid_connector"),
expected_file_list, expected_class_name)

self.assertTrue(actual_file_list, "Valid connector did not return a file list")
self.assertTrue(sorted(actual_file_list) == sorted(expected_file_list),
"Actual file list does not match expected for valid connector")
self.assertTrue(actual_class_name == expected_class_name,
"Actual class name does not match expected for valid connector")
self.assertTrue(actual_connector_version == expected_connector_version,
"Actual connector version does not match expected for valid connector")

print("\nTest invalid connector. Throws XML validation error.")

actual_file_list, actual_class_name = self.parser_test_case(TEST_FOLDER / Path("broken_xml"),
actual_file_list, actual_class_name, actual_connector_version = self.parser_test_case(TEST_FOLDER / Path("broken_xml"),
expected_file_list, expected_class_name)
self.assertFalse(actual_file_list, "Invalid connector returned a file list when it should not have")

print("\nTest connector with class name mismatch. Throws XML validation error.")
actual_file_list, actual_class_name = self.parser_test_case(TEST_FOLDER / Path("wrong_class"),
actual_file_list, actual_class_name, actual_connector_version = self.parser_test_case(TEST_FOLDER / Path("wrong_class"),
expected_file_list, expected_class_name)
self.assertFalse(actual_file_list, "Connector with class name mismatch returned a file list when it shouldn't")

# Test connector with non-https url
actual_file_list, actual_class_name = self.parser_test_case(TEST_FOLDER / Path("non_https"),
actual_file_list, actual_class_name, actual_connector_version = self.parser_test_case(TEST_FOLDER / Path("non_https"),
expected_file_list, expected_class_name)
self.assertFalse(actual_file_list, "Connector with non-https urls returned a file list when it shouldn't")

# Test connector with missing English translation
actual_file_list, actual_class_name = self.parser_test_case(TEST_FOLDER / Path("missing_english_translation"),
# Test connector with missing English transaltion
actual_file_list, actual_class_name, actual_connector_version = self.parser_test_case(TEST_FOLDER / Path("missing_english_translation"),
expected_file_list, expected_class_name)
self.assertFalse(actual_file_list, "Connector with localized strings but without a resources-en_US.xml file "
"returned a file list when it shouldn't")

def test_generate_file_list_mcd(self):
# Test modular dialog connector
expected_class_name = "postgres_mcd"
expected_connector_version = "0.0.1"
expected_file_list = [
ConnectorFile("manifest.xml", "manifest"),
ConnectorFile("connectionFields.xml", "connection-fields"),
@@ -64,18 +68,21 @@ def test_generate_file_list_mcd(self):
ConnectorFile("connectionResolver.xml", "connection-resolver"),
ConnectorFile("connectionProperties.js", "script")]

actual_file_list, actual_class_name = self.parser_test_case(TEST_FOLDER / Path("modular_dialog_connector"),
actual_file_list, actual_class_name, actual_connector_version = self.parser_test_case(TEST_FOLDER / Path("modular_dialog_connector"),
expected_file_list, expected_class_name)

self.assertTrue(actual_file_list, "Valid connector did not return a file list")
self.assertTrue(sorted(actual_file_list) == sorted(expected_file_list),
"Actual file list does not match expected for valid connector")
self.assertTrue(actual_class_name == expected_class_name,
"Actual class name does not match expected for valid connector")
self.assertTrue(actual_connector_version == expected_connector_version,
"Actual connector version does not match expected for valid connector")

def test_generate_file_list_oauth(self):
# Test oauth connector
expected_class_name = "test_oauth"
expected_connector_version = "0.0.1"
expected_file_list = [
ConnectorFile("manifest.xml", "manifest"),
ConnectorFile("connectionFields.xml", "connection-fields"),
@@ -86,20 +93,23 @@ def test_generate_file_list_oauth(self):
ConnectorFile("connectionResolver.xml", "connection-resolver"),
ConnectorFile("connectionProperties.js", "script")]

actual_file_list, actual_class_name = self.parser_test_case(TEST_FOLDER / Path("oauth_connector"),
actual_file_list, actual_class_name, actual_connector_version = self.parser_test_case(TEST_FOLDER / Path("oauth_connector"),
expected_file_list, expected_class_name)

self.assertTrue(actual_file_list, "Valid connector did not return a file list")
self.assertTrue(sorted(actual_file_list) == sorted(expected_file_list),
"Actual file list does not match expected for valid connector")
self.assertTrue(actual_class_name == expected_class_name,
"Actual class name does not match expected for valid connector")
self.assertTrue(actual_connector_version == expected_connector_version,
"Actual connector version does not match expected for valid connector")

def parser_test_case(self, test_folder, expected_file_list, expected_class_name):

xml_parser = XMLParser(test_folder)

actual_file_list = xml_parser.generate_file_list()
actual_class_name = xml_parser.class_name
actual_connector_version = xml_parser.connector_version

return actual_file_list, actual_class_name
return actual_file_list, actual_class_name, actual_connector_version