Skip to content
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

[#99] Wrong default for clustering in config set #102

Merged
merged 3 commits into from
Aug 1, 2024
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
2 changes: 1 addition & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
@@ -1 +1 @@

[#99] Correct default value display in prompt for Redis and MongoDB cluster setting (PR: #102)
17 changes: 6 additions & 11 deletions src/commands/config/config_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,14 +216,11 @@ def _redis(self) -> Dict:
default=self._settings.get("redis.port", 6379),
type=int,
)
cluster_default_value = "yes" if self._settings.get("redis.cluster") else "no"
redis_cluster = self.prompt(
"Is it a Redis cluster? (yes/no) ",
hide_input=False,
cluster_default_value = self._settings.get("redis.cluster", False)
redis_cluster = self.confirm(
"Is it a Redis cluster?",
default=cluster_default_value,
type=bool,
)

return {
"redis.port": redis_port,
"redis.container_name": f"das-cli-redis-{redis_port}",
Expand Down Expand Up @@ -255,12 +252,10 @@ def _mongodb(self) -> dict:
# hide_input=True, # When hide_input is set I cannot set the answers based on a text file making impossible to test this command
default=self._settings.get("mongodb.password", "admin"),
)
cluster_default_value = "yes" if self._settings.get("mongodb.cluster") else "no"
is_mongodb_cluster = self.prompt(
"Is it a MongoDB cluster? (yes/no) ",
hide_input=False,
cluster_default_value = self._settings.get("mongodb.cluster", False)
is_mongodb_cluster = self.confirm(
"Is it a MongoDB cluster?",
default=cluster_default_value,
type=bool,
)
cluster_secret_key = self._settings.get(
"mongodb.cluster_secret_key",
Expand Down
3 changes: 3 additions & 0 deletions src/common/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ def prompt(
show_choices,
)

def confirm(self, text: str, **kwarg):
return click.confirm(text=text, **kwarg)

def stdout(
self,
content: Any,
Expand Down
46 changes: 46 additions & 0 deletions tests/integration/test_config.bats
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,49 @@ EOF
assert_not_equal "$jupyter_notebook_port" "$old_jupyter_notebook_port"

}

@test "setting default values for configuration" {
[ -f "$das_config_file" ]

local old_redis_port="$(get_config ".redis.port")"
local old_redis_cluster="$(get_config ".redis.cluster")"
local old_mongodb_port="$(get_config ".mongodb.port")"
local old_mongodb_username="$(get_config ".mongodb.username")"
local old_mongodb_password="$(get_config ".mongodb.password")"
local old_mongodb_cluster="$(get_config ".mongodb.cluster")"
local old_jupyter_notebook_port="$(get_config ".jupyter_notebook.port")"

local redis_port=""
local redis_cluster=""
local mongodb_port=""
local mongodb_username=""
local mongodb_password=""
local mongodb_cluster=""
local jupyter_notebook_port=""

run das-cli config set <<EOF
$redis_port
$redis_cluster
$mongodb_port
$mongodb_username
$mongodb_password
$mongodb_cluster
$jupyter_notebook_port
EOF

assert_not_equal "$(get_config ".redis.port")" "$redis_port"
assert_not_equal "$(get_config ".redis.cluster")" "$(human_to_boolean "$redis_cluster")"
assert_not_equal "$(get_config ".mongodb.port")" "$mongodb_port"
assert_not_equal "$(get_config ".mongodb.username")" "$mongodb_username"
assert_not_equal "$(get_config ".mongodb.password")" "$mongodb_password"
assert_not_equal "$(get_config ".mongodb.cluster")" "$(human_to_boolean "$mongodb_cluster")"
assert_not_equal "$(get_config ".jupyter_notebook.port")" "$jupyter_notebook_port"

assert_equal "$old_redis_port" "$(get_config ".redis.port")"
assert_equal "$old_redis_cluster" "$(get_config ".redis.cluster")"
assert_equal "$old_mongodb_port" "$(get_config ".mongodb.port")"
assert_equal "$old_mongodb_username" "$(get_config ".mongodb.username")"
assert_equal "$old_mongodb_password" "$(get_config ".mongodb.password")"
assert_equal "$old_mongodb_cluster" "$(get_config ".mongodb.cluster")"
assert_equal "$old_jupyter_notebook_port" "$(get_config ".jupyter_notebook.port")"
}