Skip to content

feat: allow env variables on schema registry url and ksql url #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions kafkashell/data/shell-config.schema
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
"examples": [
"http://localhost:8081"
],
"pattern": "^https?://(.*)$"
"pattern": "^https?://(.*)$|^\\$.*$"
},
"ksql_server_url": {
"type": "string",
Expand All @@ -151,7 +151,7 @@
"examples": [
"http://localhost:8088"
],
"pattern": "^https?://(.*)$"
"pattern": "^https?://(.*)$|^\\$.*$"
},
"command_prefix": {
"type": "string",
Expand Down
22 changes: 22 additions & 0 deletions tests/data/test-environment-variables-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
version: 1
enable:
history: true
save_on_exit: true
auto_complete: true
auto_suggest: true
inline_help: true
fuzzy_search: true
cluster: local
clusters:
local:
bootstrap_servers: $BOOTSTRAP_SERVERS
zookeeper_connect: $ZOOKEEPER_CONNECT
schema_registry_url: $SCHEMA_REGISTRY_URL
ksql_server_url: $KSQL_SERVER_URL
command_prefix: ''
test:
bootstrap_servers: test:9092
zookeeper_connect: test:2181
schema_registry_url: https://test:8081
ksql_server_url: https://test:8088
command_prefix: ''
19 changes: 16 additions & 3 deletions tests/test_config.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import json
import os
import sys

import mock
import oyaml as yaml
import pytest

from tests.context import kafkashell
Expand Down Expand Up @@ -137,14 +137,27 @@ def test_get_config(mock_expanduser, test_input, expected):
@mock.patch(print_patch_name)
@mock.patch("sys.exit")
@pytest.mark.parametrize("test_input,expected", test_config_data)
def test_validate_config_invalid(mock_exit, mock_print, test_input, expected):
def test_validate_config_valid(mock_exit, mock_print, test_input, expected):
with open("tests/data/test-config.yaml") as f:
config = json.load(f)
config = yaml.safe_load(f)
returned_config = kafkashell.config.validate_config(config)

assert not mock_print.called
assert not mock_exit.called
assert config == returned_config


@mock.patch(print_patch_name)
@mock.patch("sys.exit")
@pytest.mark.parametrize("test_input,expected", test_config_data)
def test_validate_config_is_valid_with_environment_variables(mock_exit, mock_print, test_input, expected):
with open("tests/data/test-environment-variables-config.yaml") as f:
config = yaml.safe_load(f)
returned_config = kafkashell.config.validate_config(config)

assert not mock_print.called
assert not mock_exit.called
assert config == returned_config


@mock.patch(print_patch_name)
Expand Down
5 changes: 5 additions & 0 deletions tests/test_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ def test_default_config_schema():
validate_schema(json_value, "shell-config", "Default user config")


def test_environment_variable_config_schema():
json_value = get_test_config("test-environment-variables")
validate_schema(json_value, "shell-config", "Environment variable user config")


def test_invalid_configs():
json_value = get_test_config("test-invalid-ksql")
message = validate_invalid_schema(json_value, "shell-config")
Expand Down