Skip to content

Commit

Permalink
Merge pull request #912 from tableau/pv/taco-version-name
Browse files Browse the repository at this point in the history
Packaged tacos have version in file name
  • Loading branch information
pvanderknyff committed Oct 31, 2023
2 parents 6c6bcf8 + 1a51e52 commit 429ebe8
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
2 changes: 1 addition & 1 deletion connector-packager/connector_packager/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down
6 changes: 6 additions & 0 deletions connector-packager/connector_packager/xml_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion connector-packager/tests/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
30 changes: 20 additions & 10 deletions connector-packager/tests/test_xml_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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"),
Expand All @@ -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"),
Expand All @@ -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

0 comments on commit 429ebe8

Please sign in to comment.