Added tests for wls.star

This commit is contained in:
Alberto Soutullo 2023-03-10 19:12:50 +01:00
parent 23c612153d
commit 5c171eb154
4 changed files with 58 additions and 11 deletions

View File

@ -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"

View File

@ -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)

View File

@ -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)

View File

@ -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)