diff --git a/tests/npbackup-cli-test-linux.yaml b/tests/npbackup-cli-test-linux.yaml new file mode 100644 index 0000000..2860eb4 --- /dev/null +++ b/tests/npbackup-cli-test-linux.yaml @@ -0,0 +1,92 @@ +conf_version: 3.0 +repos: + default: + repo_uri: ./test + repo_group: default_group + backup_opts: + paths: [] + tags: [] + minimum_backup_size_error: 80.0 Mib + exclude_files_larger_than: 0.0 Kib + repo_opts: + repo_password: test + upload_speed: 100.0 Mib + download_speed: 0.0 Kib + retention_policy: {} + prometheus: {} + env: + env_variables: {} + encrypted_env_variables: {} +groups: + default_group: + backup_opts: + paths: [] + source_type: + tags: [] + compression: auto + use_fs_snapshot: true + ignore_cloud_files: true + exclude_caches: true + one_file_system: true + priority: low + excludes_case_ignore: false + exclude_files: + - excludes/generic_excluded_extensions + - excludes/generic_excludes + - excludes/windows_excludes + - excludes/linux_excludes + exclude_patterns: + - + exclude_files_larger_than: + additional_parameters: + additional_backup_only_parameters: + minimum_backup_size_error: 10 MiB + pre_exec_commands: [] + pre_exec_per_command_timeout: 3600 + pre_exec_failure_is_fatal: false + post_exec_commands: [] + post_exec_per_command_timeout: 3600 + post_exec_failure_is_fatal: false + post_exec_execute_even_on_backup_error: true + repo_opts: + repo_password: + repo_password_command: + minimum_backup_age: 1440 + upload_speed: 100 Mib + download_speed: 0 Mib + backend_connections: 0 + retention_policy: + last: 3 + hourly: 72 + daily: 30 + weekly: 4 + monthly: 12 + yearly: 3 + tags: [] + keep_within: true + ntp_server: + prometheus: + backup_job: ${MACHINE_ID} + group: ${MACHINE_GROUP} + env: + env_variables: {} + encrypted_env_variables: {} +identity: + machine_id: ${HOSTNAME}__Zo6u + machine_group: +global_prometheus: + metrics: false + instance: ${MACHINE_ID} + destination: + http_username: + http_password: + additional_labels: + - +global_options: + auto_upgrade: true + auto_upgrade_interval: 10 + auto_upgrade_server_url: + auto_upgrade_server_username: + auto_upgrade_server_password: + auto_upgrade_host_identity: ${MACHINE_ID} + auto_upgrade_group: ${MACHINE_GROUP} diff --git a/tests/npbackup-cli-test-windows.yaml b/tests/npbackup-cli-test-windows.yaml new file mode 100644 index 0000000..2860eb4 --- /dev/null +++ b/tests/npbackup-cli-test-windows.yaml @@ -0,0 +1,92 @@ +conf_version: 3.0 +repos: + default: + repo_uri: ./test + repo_group: default_group + backup_opts: + paths: [] + tags: [] + minimum_backup_size_error: 80.0 Mib + exclude_files_larger_than: 0.0 Kib + repo_opts: + repo_password: test + upload_speed: 100.0 Mib + download_speed: 0.0 Kib + retention_policy: {} + prometheus: {} + env: + env_variables: {} + encrypted_env_variables: {} +groups: + default_group: + backup_opts: + paths: [] + source_type: + tags: [] + compression: auto + use_fs_snapshot: true + ignore_cloud_files: true + exclude_caches: true + one_file_system: true + priority: low + excludes_case_ignore: false + exclude_files: + - excludes/generic_excluded_extensions + - excludes/generic_excludes + - excludes/windows_excludes + - excludes/linux_excludes + exclude_patterns: + - + exclude_files_larger_than: + additional_parameters: + additional_backup_only_parameters: + minimum_backup_size_error: 10 MiB + pre_exec_commands: [] + pre_exec_per_command_timeout: 3600 + pre_exec_failure_is_fatal: false + post_exec_commands: [] + post_exec_per_command_timeout: 3600 + post_exec_failure_is_fatal: false + post_exec_execute_even_on_backup_error: true + repo_opts: + repo_password: + repo_password_command: + minimum_backup_age: 1440 + upload_speed: 100 Mib + download_speed: 0 Mib + backend_connections: 0 + retention_policy: + last: 3 + hourly: 72 + daily: 30 + weekly: 4 + monthly: 12 + yearly: 3 + tags: [] + keep_within: true + ntp_server: + prometheus: + backup_job: ${MACHINE_ID} + group: ${MACHINE_GROUP} + env: + env_variables: {} + encrypted_env_variables: {} +identity: + machine_id: ${HOSTNAME}__Zo6u + machine_group: +global_prometheus: + metrics: false + instance: ${MACHINE_ID} + destination: + http_username: + http_password: + additional_labels: + - +global_options: + auto_upgrade: true + auto_upgrade_interval: 10 + auto_upgrade_server_url: + auto_upgrade_server_username: + auto_upgrade_server_password: + auto_upgrade_host_identity: ${MACHINE_ID} + auto_upgrade_group: ${MACHINE_GROUP} diff --git a/tests/test_npbackup-cli.py b/tests/test_npbackup-cli.py index b3e40db..6222039 100644 --- a/tests/test_npbackup-cli.py +++ b/tests/test_npbackup-cli.py @@ -6,7 +6,7 @@ __intname__ = "npbackup_cli_tests" __author__ = "Orsiris de Jong" __copyright__ = "Copyright (C) 2022-2024 NetInvent" __license__ = "BSD-3-Clause" -__build__ = "2024011501" +__build__ = "2024042301" __compat__ = "python3.6+" @@ -15,8 +15,17 @@ Simple test where we launch the GUI and hope it doesn't die """ import sys +import os from io import StringIO from npbackup import __main__ +from npbackup.path_helper import CURRENT_DIR, CURRENT_EXECUTABLE + + +if os.name == 'nt': + CONF_FILE = "npbackup-cli-test-windows.yaml" +else: + CONF_FILE = "npbackup-cli-test-windows.yaml" +CONF_FILE = os.path.join(CURRENT_DIR, CONF_FILE) class RedirectedStdout: @@ -57,17 +66,18 @@ def test_npbackup_cli_wrong_config_path(): assert 'Config file npbackup-non-existent.conf cannot be read' in str(logs), "There should be a critical error when config file is not given" -def test_npbackup_cli_snapshots(): - sys.argv = ['', '-c', 'npbackup-test.conf', '--snapshots'] +def test_npbackup_cli_show_config(): + sys.argv = ['', '-c', CONF_FILE, '--show-config'] try: with RedirectedStdout() as logs: __main__.main() except SystemExit: - print(logs) + print(str(logs)) + assert "__(o_O)__" in str(logs), "Obfuscation does not work" + - -def test_npbackup_cli_create_backup(): - sys.argv = ['', '-c' 'npbackup-cli-test.conf', '-b'] +def _no_test_npbackup_cli_create_backup(): + sys.argv = ['', '-c' './npbackup-cli-test.conf', '-b'] try: with RedirectedStdout() as logs: e = __main__.main() @@ -76,8 +86,46 @@ def test_npbackup_cli_create_backup(): print(logs) +def _no_test_npbackup_cli_snapshots(): + sys.argv = ['', '-c', 'npbackup-test.conf', '--snapshots'] + try: + with RedirectedStdout() as logs: + __main__.main() + except SystemExit: + print(logs) + + +def _no_test_npbackup_cli_restore(): + sys.argv = ['', '-c' './npbackup-cli-test.conf', '-r', './restored'] + try: + with RedirectedStdout() as logs: + e = __main__.main() + print(e) + except SystemExit: + print(logs) + + +def _no_test_npbackup_cli_list(): + sys.argv = ['', '-c' './npbackup-cli-test.conf', '--ls snapshots'] + try: + with RedirectedStdout() as logs: + e = __main__.main() + print(e) + except SystemExit: + print(logs) + if __name__ == "__main__": test_npbackup_cli_no_config() test_npbackup_cli_wrong_config_path() - test_npbackup_cli_snapshots() \ No newline at end of file + test_npbackup_cli_show_config() + # TODO + #test_npbackup_cli_create_backup() + #test_npbackup_cli_snapshots() + #test_npbackup_cli_restore() + #test_npbackup_cli_list() + # This one should is pretty hard to test without having repo with multiple different date snapshots + # We need to create a "fake" repo starting in let's say 2020 and put our date back to 2023 to test our standard + # policy + # We can also have a forget test which should fail because of bogus permissions + #test_npbackup_cli_forget() \ No newline at end of file