Skip to content

Commit

Permalink
Added hack to cli.py to allow pytest code
Browse files Browse the repository at this point in the history
  • Loading branch information
thenets committed Oct 18, 2021
1 parent 5881aba commit 89d2931
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions receptorctl/receptorctl/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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']


Expand Down

0 comments on commit 89d2931

Please sign in to comment.