From 70bad0b00d7a46964597a227ccec2c342bff3f70 Mon Sep 17 00:00:00 2001 From: Jaroslav Rohel Date: Mon, 6 Nov 2023 22:19:52 +0100 Subject: [PATCH] Add tests for dnf5 config-manager --- .../config-manager-addrepo.feature | 437 ++++++++++++++++++ .../plugins-core/config-manager-opts.feature | 371 +++++++++++++++ .../plugins-core/config-manager-vars.feature | 121 +++++ 3 files changed, 929 insertions(+) create mode 100644 dnf-behave-tests/dnf/plugins-core/config-manager-addrepo.feature create mode 100644 dnf-behave-tests/dnf/plugins-core/config-manager-opts.feature create mode 100644 dnf-behave-tests/dnf/plugins-core/config-manager-vars.feature diff --git a/dnf-behave-tests/dnf/plugins-core/config-manager-addrepo.feature b/dnf-behave-tests/dnf/plugins-core/config-manager-addrepo.feature new file mode 100644 index 000000000..7b5d03039 --- /dev/null +++ b/dnf-behave-tests/dnf/plugins-core/config-manager-addrepo.feature @@ -0,0 +1,437 @@ +@dnf5 +Feature: dnf "config-manager" command - test "addrepo" subcommand + + +Background: + Given I enable plugin "config_manager" + And I create file "/etc/yum.repos.d/repo1.repo" with + """ + [repo1] + name=repo1 test repository + enabled=1 + baseurl=http://something1.com/os/ + """ + And I create file "/etc/yum.repos.d/repo2.repo" with + """ + [repo2] + name=repo2 test repository + enabled=0 + baseurl=http://something2.com/os/ + """ + + +Scenario: test "addrepo" from "baseurl", "enabled=1" is set by default + When I execute dnf with args "config-manager addrepo --set=baseurl=http://something.com/os/" + Then the exit code is 0 + And file "/etc/yum.repos.d/something.com_os_.repo" contents is + """ + [something.com_os_] + name=created by dnf5 config-manager + enabled=1 + baseurl=http://something.com/os/ + """ + + +Scenario: test "addrepo" from "baseurl" with user defined repository id (--id=) + When I execute dnf with args "config-manager addrepo --id=test --set=baseurl=http://something.com/os/" + Then the exit code is 0 + And file "/etc/yum.repos.d/test.repo" contents is + """ + [test] + name=created by dnf5 config-manager + enabled=1 + baseurl=http://something.com/os/ + """ + + +Scenario: test "addrepo" from "baseurl" with user defined destination file name (--save-filename=) + When I execute dnf with args "config-manager addrepo --save-filename=test.repo --set=baseurl=http://something.com/os/" + Then the exit code is 0 + And file "/etc/yum.repos.d/test.repo" contents is + """ + [something.com_os_] + name=created by dnf5 config-manager + enabled=1 + baseurl=http://something.com/os/ + """ + + +Scenario: "addrepo" from "baseurl" with user defined destination file name, test adding the .repo extension to the filename + When I execute dnf with args "config-manager addrepo --save-filename=test --set=baseurl=http://something.com/os/" + Then the exit code is 0 + And file "/etc/yum.repos.d/test.repo" contents is + """ + [something.com_os_] + name=created by dnf5 config-manager + enabled=1 + baseurl=http://something.com/os/ + """ + + +Scenario: when run addrepo without URL + When I execute dnf with args "config-manager addrepo --id=test_repo --set=excludepkgs=iftop" + Then the exit code is 2 + And stderr contains "One of --from-repofile=, --set=baseurl=, --set=mirrorlist=, --set=metalink= must be set to a non-empty URL" + + +Scenario: test "addrepo" from "baseurl", set more options + When I execute dnf with args "config-manager addrepo --set=baseurl=http://something.com/os/ --set=gpgcheck=1 --set=metadata_expire=7d" + Then the exit code is 0 + And file "/etc/yum.repos.d/something.com_os_.repo" contents is + """ + [something.com_os_] + name=created by dnf5 config-manager + enabled=1 + baseurl=http://something.com/os/ + gpgcheck=1 + metadata_expire=7d + """ + + +Scenario: test "addrepo" from "baseurl", set option multiple times with the same value is OK + When I execute dnf with args "config-manager addrepo --set=baseurl=http://something.com/os/ --set=gpgcheck=1 --set=metadata_expire=7d --set=gpgcheck=1" + Then the exit code is 0 + And file "/etc/yum.repos.d/something.com_os_.repo" contents is + """ + [something.com_os_] + name=created by dnf5 config-manager + enabled=1 + baseurl=http://something.com/os/ + gpgcheck=1 + metadata_expire=7d + """ + + +Scenario: test "addrepo" from "baseurl", set option more times with different value + When I execute dnf with args "config-manager addrepo --set=baseurl=http://something.com/os/ --set=gpgcheck=1 --set=metadata_expire=7d --set=gpgcheck=0" + Then the exit code is 1 + And stderr contains "Sets the "gpgcheck" option again with a different value: "1" != "0"" + + +Scenario: test setting non-existent option + When I execute dnf with args "config-manager addrepo --set=baseurl=http://something.com/os/ --set=nonexistent=1" + Then the exit code is 1 + And stderr contains "Cannot set repository option "nonexistent=1": Option "nonexistent" not found" + + +Scenario: tests for setting an invalid value + When I execute dnf with args "config-manager addrepo --set=baseurl=http://something.com/os/ --set=gpgcheck=XX" + Then the exit code is 1 + And stderr contains "Cannot set repository option "gpgcheck=XX": Invalid boolean value "XX"" + + +Scenario: test "addrepo" from "baseurl", destination directory does not exist + Given I delete directory "/etc/yum.repos.d/" + When I execute dnf with args "config-manager addrepo --id=test --set=baseurl=http://something.com/os/" + Then the exit code is 1 + And stderr contains "Directory ".*/etc/yum.repos.d" does not exist. Add "--create-missing-dir" to create missing directories" + + +Scenario: test "addrepo" from "baseurl", destination directory does not exist, "--create-missing-dir" creates missing directory + Given I delete directory "/etc/yum.repos.d/" + When I execute dnf with args "config-manager addrepo --id=test --set=baseurl=http://something.com/os/ --create-missing-dir" + Then the exit code is 0 + And file "/etc/yum.repos.d/test.repo" contents is + """ + [test] + name=created by dnf5 config-manager + enabled=1 + baseurl=http://something.com/os/ + """ + + +Scenario: test "addrepo" from "baseurl", a file was found instead of destination directory + Given I delete directory "/etc/yum.repos.d/" + And I create file "/etc/yum.repos.d" with + """ + """ + When I execute dnf with args "config-manager addrepo --id=test --set=baseurl=http://something.com/os/" + Then the exit code is 1 + And stderr contains "The path ".*/etc/yum.repos.d" exists, but it is not a directory or a symlink to a directory" + + +Scenario: test "addrepo" from "baseurl", a symlink to non-existent object was found instead of destination directory + Given I delete directory "/etc/yum.repos.d/" + And I create symlink "/etc/yum.repos.d" to file "/non-exist" + When I execute dnf with args "config-manager addrepo --id=test --set=baseurl=http://something.com/os/" + Then the exit code is 1 + And stderr contains "The path ".*/etc/yum.repos.d" exists, but it is a symlink to a non-existent object" + + +Scenario: test "addrepo" from "baseurl", destination repo file already exists + When I execute dnf with args "config-manager addrepo --id=repo1 --set=baseurl=http://something.com/os/" + Then the exit code is 1 + And stderr contains "File \".*/etc/yum.repos.d/repo1.repo\" already exists and configures repositories with IDs \"repo1\". Add "--add-or-replace" or "--overwrite"" + + +Scenario: test "addrepo" from "baseurl", repository id already exists + When I execute dnf with args "config-manager addrepo --id=repo1 --set=baseurl=http://something.com/os/ --save-filename=another_repo1.repo" + Then the exit code is 1 + And stderr contains "A repository with id \"repo1\" already configured in file: .*/etc/yum.repos.d/repo1.repo" + + +Scenario: test "addrepo" from "baseurl", overwrite existing repo file (--overwrite), the repo id already exists but in the overwritten file so no problem + When I execute dnf with args "config-manager addrepo --id=repo1 --set=baseurl=http://something.com/os/ --overwrite" + Then the exit code is 0 + And file "/etc/yum.repos.d/repo1.repo" contents is + """ + [repo1] + name=created by dnf5 config-manager + enabled=1 + baseurl=http://something.com/os/ + """ + + +Scenario: test "addrepo" from "baseurl", add repo to existing file (--add-or-replace) + When I execute dnf with args "config-manager addrepo --id=test --set=baseurl=http://something.com/os/ --save-filename=repo1.repo --add-or-replace" + Then the exit code is 0 + And file "/etc/yum.repos.d/repo1.repo" contents is + """ + [repo1] + name=repo1 test repository + enabled=1 + baseurl=http://something1.com/os/ + [test] + name=created by dnf5 config-manager + enabled=1 + baseurl=http://something.com/os/ + """ + + +Scenario: test "addrepo" from "baseurl", replace repo in existing file (--add-or-replace), if the new repo has the same id, it will replace the existing repo + When I execute dnf with args "config-manager addrepo --id=repo1 --set=baseurl=http://something.com/os/ --add-or-replace" + Then the exit code is 0 + And file "/etc/yum.repos.d/repo1.repo" contents is + """ + [repo1] + name=created by dnf5 config-manager + enabled=1 + baseurl=http://something.com/os/ + """ + + +Scenario: test "addrepo" from repofile + Given I create file "/{context.dnf.tempdir}/tmp/test.repo" with + """ + [test] + name=repository file + enabled=0 + baseurl=http://something.com/os/ + """ + And I execute dnf with args "config-manager addrepo --from-repofile={context.dnf.tempdir}/tmp/test.repo" + Then the exit code is 0 + And file "/etc/yum.repos.d/test.repo" contents is + """ + [test] + name=repository file + enabled=0 + baseurl=http://something.com/os/ + """ + + +Scenario: "addrepo" from repofile, source file without .repo extension, adding the .repo extension to the destination filename + Given I create file "/{context.dnf.tempdir}/tmp/test" with + """ + [test] + name=repository file + enabled=0 + baseurl=http://something.com/os/ + """ + And I execute dnf with args "config-manager addrepo --from-repofile={context.dnf.tempdir}/tmp/test" + Then the exit code is 0 + And file "/etc/yum.repos.d/test.repo" contents is + """ + [test] + name=repository file + enabled=0 + baseurl=http://something.com/os/ + """ + + +Scenario: test "addrepo" from repofile with user defined destination file name (--save-filename=) + Given I create file "/{context.dnf.tempdir}/tmp/original.repo" with + """ + [test] + name=repository file + enabled=0 + baseurl=http://something.com/os/ + """ + When I execute dnf with args "config-manager addrepo --from-repofile={context.dnf.tempdir}/tmp/original.repo --save-filename=test.repo" + Then the exit code is 0 + And file "/etc/yum.repos.d/test.repo" contents is + """ + [test] + name=repository file + enabled=0 + baseurl=http://something.com/os/ + """ + + +Scenario: test "addrepo" from repofile with user defined destination file name (--save-filename=), adding the .repo extension to the destination filename + Given I create file "/{context.dnf.tempdir}/tmp/original.repo" with + """ + [test] + name=repository file + enabled=0 + baseurl=http://something.com/os/ + """ + When I execute dnf with args "config-manager addrepo --from-repofile={context.dnf.tempdir}/tmp/original.repo --save-filename=test" + Then the exit code is 0 + And file "/etc/yum.repos.d/test.repo" contents is + """ + [test] + name=repository file + enabled=0 + baseurl=http://something.com/os/ + """ + + +Scenario: test "addrepo" from repofile, destination directory does not exist + Given I delete directory "/etc/yum.repos.d/" + And I create file "/{context.dnf.tempdir}/tmp/test.repo" with + """ + [test] + name=repository file + enabled=0 + baseurl=http://something.com/os/ + """ + When I execute dnf with args "config-manager addrepo --from-repofile={context.dnf.tempdir}/tmp/test.repo" + Then the exit code is 1 + And stderr contains "Directory ".*/etc/yum.repos.d" does not exist. Add "--create-missing-dir" to create missing directories" + + +Scenario: test "addrepo" from repofile, destination directory does not exist, "--create-missing-dir" creates missing directory + Given I delete directory "/etc/yum.repos.d/" + And I create file "/{context.dnf.tempdir}/tmp/test.repo" with + """ + [test] + name=repository file + enabled=0 + baseurl=http://something.com/os/ + """ + When I execute dnf with args "config-manager addrepo --from-repofile={context.dnf.tempdir}/tmp/test.repo --create-missing-dir" + Then the exit code is 0 + And file "/etc/yum.repos.d/test.repo" contents is + """ + [test] + name=repository file + enabled=0 + baseurl=http://something.com/os/ + """ + + +Scenario: test "addrepo" from repofile, a file was found instead of destination directory + Given I delete directory "/etc/yum.repos.d/" + And I create file "/etc/yum.repos.d" with + """ + """ + And I create file "/{context.dnf.tempdir}/tmp/test.repo" with + """ + [test] + name=repository file + enabled=0 + baseurl=http://something.com/os/ + """ + When I execute dnf with args "config-manager addrepo --from-repofile={context.dnf.tempdir}/tmp/test.repo" + Then the exit code is 1 + And stderr contains "The path ".*/etc/yum.repos.d" exists, but it is not a directory or a symlink to a directory" + + +Scenario: test "addrepo" from repofile, a symlink to non-existent object was found instead of destination directory + Given I delete directory "/etc/yum.repos.d/" + And I create symlink "/etc/yum.repos.d" to file "/non-exist" + And I create file "/{context.dnf.tempdir}/tmp/test.repo" with + """ + [test] + name=repository file + enabled=0 + baseurl=http://something.com/os/ + """ + When I execute dnf with args "config-manager addrepo --from-repofile={context.dnf.tempdir}/tmp/test.repo" + Then the exit code is 1 + And stderr contains "The path ".*/etc/yum.repos.d" exists, but it is a symlink to a non-existent object" + + +Scenario: test "addrepo" from repofile, destination repo file already exists + Given I create file "/{context.dnf.tempdir}/tmp/repo1.repo" with + """ + [repo1] + name=repository file + enabled=0 + baseurl=http://something.com/os/ + """ + When I execute dnf with args "config-manager addrepo --from-repofile={context.dnf.tempdir}/tmp/repo1.repo" + Then the exit code is 1 + And stderr contains "File \".*/etc/yum.repos.d/repo1.repo\" already exists and configures repositories with IDs \"repo1\". Add "--overwrite" to overwrite" + + +Scenario: test "addrepo" from repofile, repository id already exists + Given I create file "/{context.dnf.tempdir}/tmp/test.repo" with + """ + [repo1] + name=repository file + enabled=0 + baseurl=http://something.com/os/ + """ + When I execute dnf with args "config-manager addrepo --from-repofile={context.dnf.tempdir}/tmp/test.repo" + Then the exit code is 1 + And stderr contains "A repository with id \"repo1\" already configured in file: .*/etc/yum.repos.d/repo1.repo" + + +Scenario: test "addrepo" from repofile, overwrite existing repo file (--overwrite), the repo id already exists but in the overwritten file so no problem + Given I create file "/{context.dnf.tempdir}/tmp/repo1.repo" with + """ + [repo1] + name=repository file + enabled=0 + baseurl=http://something.com/os/ + """ + When I execute dnf with args "config-manager addrepo --from-repofile={context.dnf.tempdir}/tmp/repo1.repo --overwrite" + Then the exit code is 0 + And file "/etc/yum.repos.d/repo1.repo" contents is + """ + [repo1] + name=repository file + enabled=0 + baseurl=http://something.com/os/ + """ + + +Scenario: test "addrepo" from repofile defined by file:/// URL + Given I create file "/{context.dnf.tempdir}/tmp/test.repo" with + """ + [test] + name=repository file + enabled=0 + baseurl=http://something.com/os/ + """ + And I execute dnf with args "config-manager addrepo --from-repofile=file:///{context.dnf.tempdir}/tmp/test.repo" + Then the exit code is 0 + And file "/etc/yum.repos.d/test.repo" contents is + """ + [test] + name=repository file + enabled=0 + baseurl=http://something.com/os/ + """ + + +Scenario: test "addrepo" from remote repofile (download from http) + Given I create directory "/remotedir" + And I create file "/remotedir/test.repo" with + """ + [test] + name=repository file + enabled=0 + baseurl=http://something.com/os/ + """ + And I set up a http server for directory "/remotedir" + When I execute dnf with args "config-manager addrepo --from-repofile=http://localhost:{context.dnf.ports[/remotedir]}/test.repo" + Then the exit code is 0 + And file "/etc/yum.repos.d/test.repo" contents is + """ + [test] + name=repository file + enabled=0 + baseurl=http://something.com/os/ + """ diff --git a/dnf-behave-tests/dnf/plugins-core/config-manager-opts.feature b/dnf-behave-tests/dnf/plugins-core/config-manager-opts.feature new file mode 100644 index 000000000..51a47d94a --- /dev/null +++ b/dnf-behave-tests/dnf/plugins-core/config-manager-opts.feature @@ -0,0 +1,371 @@ +@dnf5 +Feature: dnf "config-manager" command - test missing subcommand, "setopt" and "unsetopt" subcommands + + +Background: + Given I enable plugin "config_manager" + And I create file "/etc/yum.repos.d/repo1.repo" with + """ + [repo1] + name=repository file + enabled=1 + baseurl=http://something1.com/os/ + """ + And I create file "/etc/yum.repos.d/repo2.repo" with + """ + [repo2] + name=repository file + enabled=0 + baseurl=http://something2.com/os/ + """ + And I create file "/etc/yum.repos.d/test_repo.repo" with + """ + [test_repo] + name=repository file + enabled=1 + baseurl=http://something3.com/os/ + """ + + +Scenario: when run "config-manager" without subcommand + When I execute dnf with args "config-manager" + Then the exit code is 2 + And stderr contains "Missing command" + + +Scenario: set new main option + Given I create file "/etc/dnf/dnf.conf" with + """ + [main] + best=True + """ + When I execute dnf with args "config-manager setopt skip_unavailable=1" + Then the exit code is 0 + And file "/etc/dnf/dnf.conf" contents is + """ + [main] + best=True + skip_unavailable=1 + """ + + +Scenario: set main option multiple times with the same value is OK + Given I create file "/etc/dnf/dnf.conf" with + """ + [main] + best=True + """ + When I execute dnf with args "config-manager setopt skip_unavailable=1 best=False skip_unavailable=1" + Then the exit code is 0 + And file "/etc/dnf/dnf.conf" contents is + """ + [main] + best=False + skip_unavailable=1 + """ + + +Scenario: set main option more times with different value + Given I create file "/etc/dnf/dnf.conf" with + """ + [main] + best=True + """ + When I execute dnf with args "config-manager setopt skip_unavailable=1 best=False skip_unavailable=0" + Then the exit code is 1 + And stderr contains "Sets the "skip_unavailable" option again with a different value: "1" != "0"" + + +Scenario: setting non-existent main option + Given I create file "/etc/dnf/dnf.conf" with + """ + [main] + best=True + """ + When I execute dnf with args "config-manager setopt nonexistent=1" + Then the exit code is 1 + And stderr contains "Cannot set option: "nonexistent=1": Option "nonexistent" not found" + + +Scenario: main option - tests for setting an invalid value + Given I create file "/etc/dnf/dnf.conf" with + """ + [main] + best=True + """ + When I execute dnf with args "config-manager setopt best=XX" + Then the exit code is 1 + And stderr contains "Cannot set option: "best=XX": Invalid boolean value "XX"" + + +Scenario: change the value of main option + Given I create file "/etc/dnf/dnf.conf" with + """ + [main] + best=True + skip_unavailable=True + """ + When I execute dnf with args "config-manager setopt best=False" + Then the exit code is 0 + And file "/etc/dnf/dnf.conf" contents is + """ + [main] + best=False + skip_unavailable=True + """ + + +Scenario: unset/remove an main option + Given I create file "/etc/dnf/dnf.conf" with + """ + [main] + best=True + skip_unavailable=True + """ + When I execute dnf with args "config-manager unsetopt best" + Then the exit code is 0 + And file "/etc/dnf/dnf.conf" contents is + """ + [main] + skip_unavailable=True + """ + + +Scenario: unset/remove an main option, trying to unset an not set option is OK + Given I create file "/etc/dnf/dnf.conf" with + """ + [main] + best=True + skip_unavailable=True + """ + When I execute dnf with args "config-manager unsetopt best installroot" + Then the exit code is 0 + And file "/etc/dnf/dnf.conf" contents is + """ + [main] + skip_unavailable=True + """ + + +Scenario: repository configuration overrides - new option to "repo1" + Given I create directory "/etc/dnf/repos.override.d/" + When I execute dnf with args "config-manager setopt repo1.skip_if_unavailable=1" + Then the exit code is 0 + And file "/etc/dnf/repos.override.d/99-config_manager.repo" contents is + """ + # Generated by dnf5 config-manager. + # Do not modify this file manually, use dnf5 config-manager instead. + [repo1] + skip_if_unavailable=1 + """ + + +Scenario: repository configuration overrides - set option multiple times with the same value is OK + Given I create directory "/etc/dnf/repos.override.d/" + When I execute dnf with args "config-manager setopt repo1.skip_if_unavailable=1 repo1.priority=50 repo1.skip_if_unavailable=1" + Then the exit code is 0 + """ + # Generated by dnf5 config-manager. + # Do not modify this file manually, use dnf5 config-manager instead. + [repo1] + priority=50 + skip_if_unavailable=1 + """ + + +Scenario: repository configuration overrides - set option more times with different value + Given I create directory "/etc/dnf/repos.override.d/" + When I execute dnf with args "config-manager setopt repo1.skip_if_unavailable=1 repo1.priority=50 repo1.skip_if_unavailable=0" + Then the exit code is 1 + And stderr contains "Sets the "skip_if_unavailable" option of the repository "repo1" again with a different value: "1" != "0"" + + +Scenario: setting non-existent repo option + Given I create directory "/etc/dnf/repos.override.d/" + When I execute dnf with args "config-manager setopt repo1.nonexistent=1" + Then the exit code is 1 + And stderr contains "Cannot set repository option "repo1.nonexistent=1": Option "nonexistent" not found" + + +Scenario: repo option - tests for setting an invalid value + Given I create directory "/etc/dnf/repos.override.d/" + When I execute dnf with args "config-manager setopt repo1.skip_if_unavailable=XX" + Then the exit code is 1 + And stderr contains "Cannot set repository option "repo1.skip_if_unavailable=XX": Invalid boolean value "XX"" + + +Scenario: repository configuration overrides, "id" of non-existent repo + Given I create directory "/etc/dnf/repos.override.d/" + When I execute dnf with args "config-manager setopt non-exist-repo.skip_if_unavailable=1" + Then the exit code is 1 + And stderr contains "No matching repository to modify: non-exist-repo" + + +Scenario: repository configuration overrides - new option, globs in repo id + Given I create directory "/etc/dnf/repos.override.d/" + When I execute dnf with args "config-manager setopt r?p*.skip_if_unavailable=1" + Then the exit code is 0 + And file "/etc/dnf/repos.override.d/99-config_manager.repo" contents is + """ + # Generated by dnf5 config-manager. + # Do not modify this file manually, use dnf5 config-manager instead. + [repo1] + skip_if_unavailable=1 + [repo2] + skip_if_unavailable=1 + """ + +Scenario: repository configuration overrides - globs in repo id, set option more times with different value + Given I create directory "/etc/dnf/repos.override.d/" + When I execute dnf with args "config-manager setopt r?p*.skip_if_unavailable=1 repo1.priority=50 repo2.skip_if_unavailable=0" + Then the exit code is 1 + And stderr contains "Sets the "skip_if_unavailable" option of the repository "repo2" again with a different value: "1" != "0"" + + +Scenario: repository configuration overrides, glob does not match any repo "id" + Given I create directory "/etc/dnf/repos.override.d/" + When I execute dnf with args "config-manager setopt non*repo.skip_if_unavailable=1" + Then the exit code is 1 + And stderr contains "No matching repository to modify: non\*repo" + + +Scenario: repository configuration overrides - new option, missing destination directory + When I execute dnf with args "config-manager setopt repo1.skip_if_unavailable=1" + Then the exit code is 1 + And stderr contains "Directory ".*/etc/dnf/repos.override.d" does not exist. Add "--create-missing-dir" to create missing directories" + + +Scenario: repository configuration overrides - new option, "--create-missing-dir" creates missing destination directory + When I execute dnf with args "config-manager setopt repo1.skip_if_unavailable=1 --create-missing-dir" + Then the exit code is 0 + And file "/etc/dnf/repos.override.d/99-config_manager.repo" contents is + """ + # Generated by dnf5 config-manager. + # Do not modify this file manually, use dnf5 config-manager instead. + [repo1] + skip_if_unavailable=1 + """ + + +Scenario: repository configuration overrides - new option, a file was found instead of destination directory + Given I create file "/etc/dnf/repos.override.d" with + """ + """ + When I execute dnf with args "config-manager setopt repo1.skip_if_unavailable=1" + Then the exit code is 1 + And stderr contains "The path ".*/etc/dnf/repos.override.d" exists, but it is not a directory or a symlink to a directory" + + +Scenario: repository configuration overrides - new option, a symlink to non-existent object was found instead of destination directory + Given I create symlink "/etc/dnf/repos.override.d" to file "/non-exist" + When I execute dnf with args "config-manager setopt repo1.skip_if_unavailable=1" + Then the exit code is 1 + And stderr contains "The path ".*/etc/dnf/repos.override.d" exists, but it is a symlink to a non-existent object" + + +Scenario: repository configuration overrides - unset/remove option + Given I create file "/etc/dnf/repos.override.d/99-config_manager.repo" with + """ + [repo1] + enabled=0 + priority=40 + skip_if_unavailable=1 + [repo2] + enabled=1 + priority=50 + skip_if_unavailable=0 + """ + When I execute dnf with args "config-manager unsetopt repo1.priority" + Then the exit code is 0 + And file "/etc/dnf/repos.override.d/99-config_manager.repo" contents is + """ + [repo1] + enabled=0 + skip_if_unavailable=1 + [repo2] + enabled=1 + priority=50 + skip_if_unavailable=0 + """ + + +Scenario: repository configuration overrides - unset/remove option, globs in repo id + Given I create file "/etc/dnf/repos.override.d/99-config_manager.repo" with + """ + [repo1] + enabled=0 + priority=40 + skip_if_unavailable=1 + [repo2] + enabled=1 + priority=50 + skip_if_unavailable=0 + [test_repo] + enabled=1 + priotity=80 + skip_if_unavailable=0 + """ + When I execute dnf with args "config-manager unsetopt r*o?.priority" + Then the exit code is 0 + And file "/etc/dnf/repos.override.d/99-config_manager.repo" contents is + """ + [repo1] + enabled=0 + skip_if_unavailable=1 + [repo2] + enabled=1 + skip_if_unavailable=0 + [test_repo] + enabled=1 + priotity=80 + skip_if_unavailable=0 + """ + + +Scenario: repository configuration overrides - unset/remove option, trying to unset an not set option is OK + Given I create file "/etc/dnf/repos.override.d/99-config_manager.repo" with + """ + [repo1] + enabled=0 + priority=40 + skip_if_unavailable=1 + [repo2] + enabled=1 + priority=50 + skip_if_unavailable=0 + """ + When I execute dnf with args "config-manager unsetopt repo1.cost repo1.priority" + Then the exit code is 0 + And file "/etc/dnf/repos.override.d/99-config_manager.repo" contents is + """ + [repo1] + enabled=0 + skip_if_unavailable=1 + [repo2] + enabled=1 + priority=50 + skip_if_unavailable=0 + """ + + +Scenario: repository configuration overrides - unset/remove option, empty section is removed + Given I create file "/etc/dnf/repos.override.d/99-config_manager.repo" with + """ + [repo1] + enabled=0 + priority=40 + skip_if_unavailable=1 + [repo2] + enabled=1 + priority=50 + skip_if_unavailable=0 + """ + When I execute dnf with args "config-manager unsetopt repo1.enabled repo1.priority repo1.skip_if_unavailable" + Then the exit code is 0 + And file "/etc/dnf/repos.override.d/99-config_manager.repo" contents is + """ + [repo2] + enabled=1 + priority=50 + skip_if_unavailable=0 + """ diff --git a/dnf-behave-tests/dnf/plugins-core/config-manager-vars.feature b/dnf-behave-tests/dnf/plugins-core/config-manager-vars.feature new file mode 100644 index 000000000..5b7d701c6 --- /dev/null +++ b/dnf-behave-tests/dnf/plugins-core/config-manager-vars.feature @@ -0,0 +1,121 @@ +@dnf5 +Feature: dnf "config-manager" command - test "setvar" and "unsetvar" subcommands + + +Scenario: set new variables + Given I create directory "/etc/dnf/vars/" + When I execute dnf with args "config-manager setvar mvar1=value1 mvar2=value2" + Then the exit code is 0 + And file "/etc/dnf/vars/mvar1" contents is + """ + value1 + """ + And file "/etc/dnf/vars/mvar2" contents is + """ + value2 + """ + + +Scenario: set variable multiple times times with the same value is OK + Given I create directory "/etc/dnf/vars/" + When I execute dnf with args "config-manager setvar mvar1=value1 mvar2=value2 mvar1=value1" + Then the exit code is 0 + And file "/etc/dnf/vars/mvar1" contents is + """ + value1 + """ + And file "/etc/dnf/vars/mvar2" contents is + """ + value2 + """ + + +Scenario: set variable more times with different value + Given I create directory "/etc/dnf/vars/" + When I execute dnf with args "config-manager setvar mvar1=value1 mvar2=value2 mvar1=other_value" + Then the exit code is 1 + And stderr contains "Sets the "mvar1" variable again with a different value: "value1" != "other_value"" + + +Scenario: set new variables, missing destination directory + When I execute dnf with args "config-manager setvar mvar1=value1 mvar2=value2" + Then the exit code is 1 + And stderr contains "Directory ".*/etc/dnf/vars" does not exist. Add "--create-missing-dir" to create missing directories" + + +Scenario: set new variables, "--create-missing-dir" creates missing destination directory + When I execute dnf with args "config-manager setvar --create-missing-dir mvar1=value1 mvar2=value2" + Then the exit code is 0 + And file "/etc/dnf/vars/mvar1" contents is + """ + value1 + """ + And file "/etc/dnf/vars/mvar2" contents is + """ + value2 + """ + + +Scenario: set new variables, a file was found instead of a directory + Given I create file "/etc/dnf/vars" with + """ + """ + When I execute dnf with args "config-manager setvar mvar1=value1 mvar2=value2" + Then the exit code is 1 + And stderr contains "The path ".*/etc/dnf/vars" exists, but it is not a directory or a symlink to a directory" + + +Scenario: set new variables, a symlink to non-existent object was found instead of a directory + Given I create symlink "/etc/dnf/vars" to file "/non-exist" + When I execute dnf with args "config-manager setvar mvar1=value1 mvar2=value2" + Then the exit code is 1 + And stderr contains "The path ".*/etc/dnf/vars" exists, but it is a symlink to a non-existent object" + + +Scenario: change the value of an existing variable + Given I create file "/etc/dnf/vars/mvar1" with + """ + orig_value1 + """ + And I execute dnf with args "config-manager setvar mvar1=value1" + Then the exit code is 0 + And file "/etc/dnf/vars/mvar1" contents is + """ + value1 + """ + + +Scenario: unset/remove an existing variable + Given I create file "/etc/dnf/vars/mvar1" with + """ + orig_value1 + """ + And I create file "/etc/dnf/vars/mvar2" with + """ + orig_value2 + """ + And I execute dnf with args "config-manager unsetvar mvar1" + Then the exit code is 0 + And file "/etc/dnf/vars/mvar1" does not exist + And file "/etc/dnf/vars/mvar2" contents is + """ + orig_value2 + """ + + +Scenario: unset/remove an existing variable, removing non-existent variable is OK + Given I create file "/etc/dnf/vars/mvar1" with + """ + orig_value1 + """ + And I create file "/etc/dnf/vars/mvar2" with + """ + orig_value2 + """ + And I execute dnf with args "config-manager unsetvar mvar1 nonexistvar" + Then the exit code is 0 + And file "/etc/dnf/vars/mvar1" does not exist + And file "/etc/dnf/vars/mvar2" contents is + """ + orig_value2 + """