diff --git a/receptorctl/receptorctl/cli.py b/receptorctl/receptorctl/cli.py index 0116a8f34..02185d823 100644 --- a/receptorctl/receptorctl/cli.py +++ b/receptorctl/receptorctl/cli.py @@ -13,6 +13,30 @@ import pkg_resources from .socket_interface import ReceptorControl +# HACK: Static test parameters var +test_params = dict() + +def populate_ctx_with_test_data(ctx): + """ Populate the ctx with Receptor test data. + + This is a HACK while doesn't have a proper way to do this. + Probably will be require some fundamental changes to the + receptorctl code. + + The goal is to have a test environment aligned with the + official Click documentation: + - https://click.palletsprojects.com/en/8.0.x/testing/ + """ + ctx.obj = dict() + ctx.obj['rc'] = ReceptorControl( + "/tmp/receptorctltest/node1.sock", + config = None, + tlsclient = None, + rootcas = None, + key = None, + cert = None, + insecureskipverify = None + ) class IgnoreRequiredWithHelp(click.Group): # allows user to call --help without needing to provide required=true parameters @@ -45,6 +69,10 @@ def cli(ctx, socket, config, tlsclient, rootcas, key, cert, insecureskipverify): ctx.obj = dict() ctx.obj['rc'] = ReceptorControl(socket, config=config, tlsclient=tlsclient, rootcas=rootcas, key=key, cert=cert, insecureskipverify=insecureskipverify) def get_rc(ctx): + # HACK: allows testing + if not ctx.obj: + populate_ctx_with_test_data(ctx) + return ctx.obj['rc']