-
-
Notifications
You must be signed in to change notification settings - Fork 530
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add bats tests for config file generation
- Loading branch information
Showing
2 changed files
with
151 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
142 changes: 142 additions & 0 deletions
142
integration-tests/bats/sql-server-config-file-generation.bats
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
#!/usr/bin/env bats | ||
load "$BATS_TEST_DIRNAME/helper/common.bash" | ||
load "$BATS_TEST_DIRNAME/helper/query-server-common.bash" | ||
|
||
CONFIG_FILE_NAME=config.yaml | ||
|
||
DATABASE_DIRS=( | ||
. | ||
mydir | ||
nest1/nest2/nest3 | ||
) | ||
|
||
setup() { | ||
setup_common | ||
} | ||
|
||
teardown() { | ||
stop_sql_server | ||
teardown_common | ||
} | ||
|
||
@test "sql-server-config-file-generation: config file is generated if one doesn't exist" { | ||
for data_dir in "${DATABASE_DIRS[@]}"; do | ||
if [[ "$data_dir" != "." ]]; then | ||
mkdir -p "$data_dir" | ||
fi | ||
|
||
start_sql_server_with_args --data-dir "$data_dir" --host 0.0.0.0 --user dolt | ||
|
||
[[ -f "$data_dir/$CONFIG_FILE_NAME" ]] || false | ||
|
||
rm "$data_dir/$CONFIG_FILE_NAME" | ||
stop_sql_server | ||
done | ||
} | ||
|
||
@test "sql-server-config-file-generation: config file isn't generated if one already exists" { | ||
for data_dir in "${DATABASE_DIRS[@]}"; do | ||
if [[ "$data_dir" != "." ]]; then | ||
mkdir -p "$data_dir" | ||
fi | ||
|
||
echo "Don't overwrite me!" >"$data_dir/$CONFIG_FILE_NAME" | ||
|
||
start_sql_server_with_args --data-dir "$data_dir" --host 0.0.0.0 --user dolt | ||
|
||
run cat "$data_dir/$CONFIG_FILE_NAME" | ||
[ $status -eq 0 ] | ||
[[ "$output" =~ "Don't overwrite me!" ]] || false | ||
|
||
rm "$data_dir/$CONFIG_FILE_NAME" | ||
stop_sql_server | ||
done | ||
} | ||
|
||
@test "sql-server-config-file-generation: config file isn't generated if a config is specified in args" { | ||
for data_dir in "${DATABASE_DIRS[@]}"; do | ||
if [[ "$data_dir" != "." ]]; then | ||
mkdir -p "$data_dir" | ||
fi | ||
|
||
NOT_CONFIG_FILE_NAME="not-$CONFIG_FILE_NAME" | ||
PORT=$(definePORT) | ||
|
||
cat >"$data_dir/$NOT_CONFIG_FILE_NAME" <<EOF | ||
user: | ||
name: dolt | ||
listener: | ||
host: 0.0.0.0 | ||
port: $PORT | ||
data_dir: $data_dir | ||
# Don't overwrite me! | ||
EOF | ||
|
||
start_sql_server_with_args_no_port --config "$data_dir/$NOT_CONFIG_FILE_NAME" | ||
|
||
[[ ! -f "$data_dir/$CONFIG_FILE_NAME" ]] || false | ||
|
||
run cat "$data_dir/$NOT_CONFIG_FILE_NAME" | ||
[ $status -eq 0 ] | ||
[[ "$output" =~ "Don't overwrite me!" ]] || false | ||
|
||
rm "$data_dir/$NOT_CONFIG_FILE_NAME" | ||
stop_sql_server | ||
done | ||
} | ||
|
||
@test "sql-server-config-file-generation: generated config file has fields set to arg-provided values" { | ||
start_sql_server_with_args \ | ||
--readonly \ | ||
--no-auto-commit \ | ||
--persistence-behavior ignore \ | ||
--max-connections 77 \ | ||
--timeout 7777777 \ | ||
--allow-cleartext-passwords true \ | ||
--host 0.0.0.0 \ | ||
--user dolt | ||
|
||
run cat "$CONFIG_FILE_NAME" | ||
[ $status -eq 0 ] | ||
[[ "$output" =~ "read_only: true" ]] || false | ||
[[ "$output" =~ "autocommit: false" ]] || false | ||
[[ "$output" =~ "persistence_behavior: ignore" ]] || false | ||
[[ "$output" =~ "max_connections: 77" ]] || false | ||
[[ "$output" =~ "read_timeout_millis: 7777777" ]] || false | ||
[[ "$output" =~ "write_timeout_millis: 7777777" ]] || false | ||
[[ "$output" =~ "allow_cleartext_passwords: true" ]] || false | ||
} | ||
|
||
@test "sql-server-config-file-generation: generated config file has unset fields set to default values" { | ||
start_sql_server_with_args \ | ||
--max-connections 77 \ | ||
--timeout 7777777 \ | ||
--host 0.0.0.0 \ | ||
--user dolt | ||
|
||
run cat "$CONFIG_FILE_NAME" | ||
[ $status -eq 0 ] | ||
|
||
# not default (set by args) | ||
[[ "$output" =~ "max_connections: 77" ]] || false | ||
[[ "$output" =~ "read_timeout_millis: 7777777" ]] || false | ||
[[ "$output" =~ "write_timeout_millis: 7777777" ]] || false | ||
|
||
# default (not set by args) | ||
[[ "$output" =~ "read_only: false" ]] || false | ||
[[ "$output" =~ "autocommit: true" ]] || false | ||
[[ "$output" =~ "persistence_behavior: load" ]] || false | ||
[[ "$output" =~ "allow_cleartext_passwords: false" ]] || false | ||
} | ||
|
||
@test "sql-server-config-file-generation: generated config file has placeholders for unset fields with no default values" { | ||
start_sql_server | ||
|
||
run cat "$CONFIG_FILE_NAME" | ||
[ $status -eq 0 ] | ||
[[ "$output" =~ "# tls_key:" ]] || false | ||
[[ "$output" =~ "# tls_cert:" ]] || false | ||
} |