From 5c171eb1548e92d7f7cda87bc6bcc86a56db491e Mon Sep 17 00:00:00 2001 From: Alberto Soutullo Date: Fri, 10 Mar 2023 19:12:50 +0100 Subject: [PATCH] Added tests for wls.star --- src/system_variables.star | 5 +++++ src/tests/test_wls.star | 38 ++++++++++++++++++++++++++++++++++++++ src/wls.star | 15 ++++++++------- tests.star | 11 +++++++---- 4 files changed, 58 insertions(+), 11 deletions(-) diff --git a/src/system_variables.star b/src/system_variables.star index 6d8fcb0..a4f5384 100644 --- a/src/system_variables.star +++ b/src/system_variables.star @@ -97,6 +97,10 @@ WLS_TOMLS_PATH = "/wls/tomls/" WLS_TOPOLOGY_PATH = "/wls/network_topology/" WLS_CONFIG_FILE_FLAG = "--config_file" WLS_TOPOLOGY_FILE_FLAG = "--topology_file" +WLS_CONFIG_ARTIFACT_NAME = "config_file" +WLS_TOPOLOGY_ARTIFACT_NAME = "wls_topology" +WLS_TOMLS_ARTIFACT_NAME = "tomls_artifact" + CONTAINER_WLS_CONFIGURATION_FILE_NAME = "config.json" CONTAINER_TOPOLOGY_FILE_NAME_WLS = "network_data.json" @@ -128,6 +132,7 @@ NOMOS_MODULE = "github.com/logos-co/wakurtosis/src/nomos.star" TEST_ARGUMENTS_MODULE = "github.com/logos-co/wakurtosis/src/tests/test_arguments_parser.star" TEST_FILES_MODULE = "github.com/logos-co/wakurtosis/src/tests/test_file_helpers.star" TEST_WAKU_MODULE = "github.com/logos-co/wakurtosis/src/tests/test_waku_methods.star" +TEST_WLS_MODULE = "github.com/logos-co/wakurtosis/src/tests/test_wls.star" TEST_NODE_BUILDERS_MODULE = "github.com/logos-co/wakurtosis/src/node_builders/tests/test_node_builders.star" TEST_WAKU_BUILDER_MODULE = "github.com/logos-co/wakurtosis/src/node_builders/types/tests/test_waku_builder.star" TEST_GOWAKU_BUILDER_MODULE = "github.com/logos-co/wakurtosis/src/node_builders/types/tests/test_gowaku_builder.star" diff --git a/src/tests/test_wls.star b/src/tests/test_wls.star index e69de29..8ebc3f4 100644 --- a/src/tests/test_wls.star +++ b/src/tests/test_wls.star @@ -0,0 +1,38 @@ +# System Imports +vars = import_module("github.com/logos-co/wakurtosis/src/system_variables.star") + +# Project Imports +wls = import_module(vars.WLS_MODULE) + + +def test_upload_config(plan): + test_config = vars.TEST_FILES_LOCATION + "test_config_file.json" + test = wls.upload_config(plan, test_config, "test_config") + + plan.assert(value=test, assertion="==", target_value="test_config") + + +def test_create_new_topology_information(plan): + test_topology = {} + test = wls.create_new_topology_information(plan, test_topology, "test_topology") + + plan.assert(value=test, assertion="==", target_value="test_topology") + +def test_create_cmd(plan): + config_file = "test.json" + test = wls.create_cmd(config_file) + result = [vars.WLS_CONFIG_FILE_FLAG, vars.WLS_CONFIG_PATH + config_file, + vars.WLS_TOPOLOGY_FILE_FLAG, vars.WLS_TOPOLOGY_PATH + vars.CONTAINER_TOPOLOGY_FILE_NAME_WLS] + + for i in range(len(result)): + plan.assert(value=test[i], assertion="==", target_value=result[i]) + +def test_init(plan): + test_config = vars.TEST_FILES_LOCATION + "test_config_file.json" + test = wls.upload_config(plan, test_config, "test_config_2") + + test_topology = {} + + test_wls_service = wls.init(plan, test_topology, test_config) + + plan.remove_service(vars.WLS_SERVICE_NAME) \ No newline at end of file diff --git a/src/wls.star b/src/wls.star index e93ece6..6cb58ae 100644 --- a/src/wls.star +++ b/src/wls.star @@ -5,15 +5,15 @@ vars = import_module("github.com/logos-co/wakurtosis/src/system_variables.star") files = import_module(vars.FILE_HELPERS_MODULE) templates = import_module(vars.TEMPLATES_MODULE) -def upload_config(plan, config_file): +def upload_config(plan, config_file, artifact_name): config_artifact = plan.upload_files( src=config_file, - name="config_file" + name=artifact_name ) return config_artifact -def create_new_topology_information(plan, network_topology): +def create_new_topology_information(plan, network_topology, network_artifact_name): template = """ {{.information}} """ @@ -27,7 +27,7 @@ def create_new_topology_information(plan, network_topology): data=info, ) }, - name="wls_topology" + name=network_artifact_name ) return artifact_id @@ -47,15 +47,16 @@ def create_cmd(config_file): def init(plan, network_topology, config_file): # Generate simulation config - config_artifact = upload_config(plan, config_file) + config_artifact = upload_config(plan, config_file, vars.WLS_CONFIG_ARTIFACT_NAME) tomls_artifact = plan.upload_files( src = vars.NODE_CONFIG_FILE_LOCATION, - name = "tomls_artifact", + name = vars.WLS_TOMLS_ARTIFACT_NAME, ) # Get complete network topology information - wls_topology = create_new_topology_information(plan, network_topology) + wls_topology = create_new_topology_information(plan, network_topology, + vars.WLS_TOPOLOGY_ARTIFACT_NAME) wls_cmd = create_cmd(config_file) diff --git a/tests.star b/tests.star index d391815..ff433e7 100644 --- a/tests.star +++ b/tests.star @@ -5,6 +5,7 @@ vars = import_module("github.com/logos-co/wakurtosis/src/system_variables.star") args_parser_test = import_module(vars.TEST_ARGUMENTS_MODULE) file_helpers_test = import_module(vars.TEST_FILES_MODULE) waku_test = import_module(vars.TEST_WAKU_MODULE) +wls_test = import_module(vars.TEST_WLS_MODULE) node_builders_test = import_module(vars.TEST_NODE_BUILDERS_MODULE) waku_builder_test = import_module(vars.TEST_WAKU_BUILDER_MODULE) gowaku_builder_test = import_module(vars.TEST_GOWAKU_BUILDER_MODULE) @@ -12,7 +13,9 @@ nwaku_builder_test = import_module(vars.TEST_NWAKU_BUILDER_MODULE) + def run(plan, args): + args_parser_test.test_load_config_args_default(plan) args_parser_test.test_load_config_args_given(plan) @@ -39,7 +42,7 @@ def run(plan, args): nwaku_builder_test.test_prepare_nwaku_service(plan) nwaku_builder_test.test__prepare_nwaku_cmd_in_service(plan) - - - - + wls_test.test_upload_config(plan) + wls_test.test_create_new_topology_information(plan) + wls_test.test_create_cmd(plan) + wls_test.test_init(plan)