Skip to content

Commit

Permalink
[#99] Wrong default for clustering in config set (#102)
Browse files Browse the repository at this point in the history
* test: setting default values for configuration

* fix: default bool prompts

* Update changelog file
  • Loading branch information
levisingularity authored Aug 1, 2024
1 parent 415587e commit 22ccd2d
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 12 deletions.
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")"
}

0 comments on commit 22ccd2d

Please sign in to comment.