summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorA. Wilcox <AWilcox@Wilcox-Tech.com>2020-08-22 15:59:49 -0500
committerA. Wilcox <AWilcox@Wilcox-Tech.com>2020-08-22 16:15:30 -0500
commit5595a79c6c5c73203f55d3a759a7af921ed34c1a (patch)
tree5f3fb9b1dfcbac7318717cdc404fbec60966d311
parent0c7ba43adfd65f4906f9f668a947736e6f092d42 (diff)
downloadhorizon-5595a79c6c5c73203f55d3a759a7af921ed34c1a.tar.gz
horizon-5595a79c6c5c73203f55d3a759a7af921ed34c1a.tar.bz2
horizon-5595a79c6c5c73203f55d3a759a7af921ed34c1a.tar.xz
horizon-5595a79c6c5c73203f55d3a759a7af921ed34c1a.zip
Improve test coverage of metadata keys
-rw-r--r--hscript/meta.cc42
-rw-r--r--tests/fixtures/0222-complete.installfile1
-rw-r--r--tests/fixtures/0246-hostname-nonalnum.installfile5
-rw-r--r--tests/fixtures/0247-version-basic.installfile6
-rw-r--r--tests/fixtures/0248-version-invalid.installfile6
-rw-r--r--tests/fixtures/0249-bootloader-ppc.installfile7
-rw-r--r--tests/fixtures/0250-bootloader-x86efi.installfile7
-rw-r--r--tests/fixtures/0251-bootloader-x86bios.installfile7
-rw-r--r--tests/fixtures/0252-bootloader-alpha.installfile7
-rw-r--r--tests/spec/validator_spec.rb45
10 files changed, 112 insertions, 21 deletions
diff --git a/hscript/meta.cc b/hscript/meta.cc
index 1227e60..10b0589 100644
--- a/hscript/meta.cc
+++ b/hscript/meta.cc
@@ -214,8 +214,8 @@ bool Arch::execute() const {
}
arch_f << this->value() << std::endl;
-#endif
- return true;
+#endif /* HAS_INSTALL_ENV */
+ return true; /* LCOV_EXCL_LINE */
}
@@ -742,39 +742,47 @@ const std::string my_arch(const Horizon::Script *script) {
bool Bootloader::validate() const {
const std::string arch = my_arch(script);
+ bool valid_selection;
/* 'true' and 'false' are always valid. */
if(_value == "true" || _value == "false") return true;
if(arch == "ppc64") {
const static std::set<std::string> valid_ppc64 = {"grub-ieee1275"};
- return valid_ppc64.find(this->value()) != valid_ppc64.end();
+ valid_selection = valid_ppc64.find(this->value()) != valid_ppc64.end();
} else if(arch == "ppc") {
const static std::set<std::string> valid_ppc = {"grub-ieee1275",
"iquik"};
- return valid_ppc.find(this->value()) != valid_ppc.end();
+ valid_selection = valid_ppc.find(this->value()) != valid_ppc.end();
} else if(arch == "aarch64") {
const static std::set<std::string> valid_arm64 = {"grub-efi"};
- return valid_arm64.find(this->value()) != valid_arm64.end();
+ valid_selection = valid_arm64.find(this->value()) != valid_arm64.end();
} else if(arch == "armv7") {
const static std::set<std::string> valid_arm = {};
- return valid_arm.find(this->value()) != valid_arm.end();
+ valid_selection = valid_arm.find(this->value()) != valid_arm.end();
} else if(arch == "pmmx") {
const static std::set<std::string> valid_pmmx = {"grub-bios",
"grub-efi"};
- return valid_pmmx.find(this->value()) != valid_pmmx.end();
+ valid_selection = valid_pmmx.find(this->value()) != valid_pmmx.end();
} else if(arch == "x86_64") {
const static std::set<std::string> valid_x86 = {"grub-bios",
"grub-efi"};
- return valid_x86.find(this->value()) != valid_x86.end();
+ valid_selection = valid_x86.find(this->value()) != valid_x86.end();
} else if(arch == "mips64" || arch == "mips" ||
arch == "mips64el" || arch == "mipsel") {
const static std::set<std::string> valid_mips = {};
- return valid_mips.find(this->value()) != valid_mips.end();
+ valid_selection = valid_mips.find(this->value()) != valid_mips.end();
} else {
output_error(pos, "bootloader: unknown architecture", arch);
return false;
}
+
+ if(!valid_selection) {
+ output_error(pos, "bootloader: architecture does not support loader",
+ this->value());
+ }
+
+ return valid_selection;
}
bool Bootloader::execute() const {
@@ -794,7 +802,7 @@ bool Bootloader::execute() const {
if(fs::exists("/sys/firmware/efi")) {
method = "grub-efi";
} else
-#endif
+#endif /* HAS_INSTALL_ENV */
method = "grub-bios";
} else {
output_error(pos, "bootloader: no default for architecture", arch);
@@ -838,8 +846,8 @@ bool Bootloader::execute() const {
mount(nullptr, efipath.c_str(), nullptr,
MS_REMOUNT | MS_RDONLY | MS_NOEXEC | MS_NODEV | MS_NOSUID |
MS_RELATIME, nullptr);
-#endif
- return true;
+#endif /* HAS_INSTALL_ENV */
+ return true; /* LCOV_EXCL_LINE */
}
else if(method == "grub-bios") {
if(script->options().test(Simulate)) {
@@ -862,8 +870,8 @@ bool Bootloader::execute() const {
output_error(pos, "bootloader: failed to install GRUB");
return false;
}
-#endif
- return true;
+#endif /* HAS_INSTALL_ENV */
+ return true; /* LCOV_EXCL_LINE */
}
else if(method == "iquik") {
output_error(pos, "bootloader: iQUIK is not yet supported");
@@ -890,9 +898,9 @@ bool Bootloader::execute() const {
output_error(pos, "bootloader: failed to install GRUB");
return false;
}
-#endif
- return true;
+#endif /* HAS_INSTALL_ENV */
+ return true; /* LCOV_EXCL_LINE */
}
- return false;
+ return false; /* LCOV_EXCL_LINE */
}
diff --git a/tests/fixtures/0222-complete.installfile b/tests/fixtures/0222-complete.installfile
index c82063f..0c54cbf 100644
--- a/tests/fixtures/0222-complete.installfile
+++ b/tests/fixtures/0222-complete.installfile
@@ -9,6 +9,7 @@ disklabel /dev/sda gpt
partition /dev/sda 1 fill
fs /dev/sda1 ext4
mount /dev/sda1 /
+version current
repository https://distfiles.adelielinux.org/adelie/current/system
repository https://distfiles.adelielinux.org/adelie/current/user
signingkey /etc/apk/keys/packages@adelielinux.org.pub
diff --git a/tests/fixtures/0246-hostname-nonalnum.installfile b/tests/fixtures/0246-hostname-nonalnum.installfile
new file mode 100644
index 0000000..49d9240
--- /dev/null
+++ b/tests/fixtures/0246-hostname-nonalnum.installfile
@@ -0,0 +1,5 @@
+network true
+hostname -invalid-.foo.bar
+pkginstall adelie-base
+rootpw $6$gumtLGmHwOVIRpQR$2M9PUO24hy5mofzWWf9a.YLbzOgOlUby1g0hDj.wG67E2wrrvys59fq02PPdxBdbgkLZFtjfEx6MHZwMBamwu/
+mount /dev/sda1 /
diff --git a/tests/fixtures/0247-version-basic.installfile b/tests/fixtures/0247-version-basic.installfile
new file mode 100644
index 0000000..67c310f
--- /dev/null
+++ b/tests/fixtures/0247-version-basic.installfile
@@ -0,0 +1,6 @@
+network false
+hostname 123lonelycorgi.street
+pkginstall adelie-base
+rootpw $6$gumtLGmHwOVIRpQR$2M9PUO24hy5mofzWWf9a.YLbzOgOlUby1g0hDj.wG67E2wrrvys59fq02PPdxBdbgkLZFtjfEx6MHZwMBamwu/
+mount /dev/sda1 /
+version 1.0
diff --git a/tests/fixtures/0248-version-invalid.installfile b/tests/fixtures/0248-version-invalid.installfile
new file mode 100644
index 0000000..3f733cd
--- /dev/null
+++ b/tests/fixtures/0248-version-invalid.installfile
@@ -0,0 +1,6 @@
+network false
+hostname 123lonelycorgi.street
+pkginstall adelie-base
+rootpw $6$gumtLGmHwOVIRpQR$2M9PUO24hy5mofzWWf9a.YLbzOgOlUby1g0hDj.wG67E2wrrvys59fq02PPdxBdbgkLZFtjfEx6MHZwMBamwu/
+mount /dev/sda1 /
+version !invalid
diff --git a/tests/fixtures/0249-bootloader-ppc.installfile b/tests/fixtures/0249-bootloader-ppc.installfile
new file mode 100644
index 0000000..3124cda
--- /dev/null
+++ b/tests/fixtures/0249-bootloader-ppc.installfile
@@ -0,0 +1,7 @@
+network false
+hostname test.machine
+pkginstall adelie-base
+rootpw $6$gumtLGmHwOVIRpQR$2M9PUO24hy5mofzWWf9a.YLbzOgOlUby1g0hDj.wG67E2wrrvys59fq02PPdxBdbgkLZFtjfEx6MHZwMBamwu/
+mount /dev/sda1 /
+arch ppc
+bootloader yaboot
diff --git a/tests/fixtures/0250-bootloader-x86efi.installfile b/tests/fixtures/0250-bootloader-x86efi.installfile
new file mode 100644
index 0000000..bb18a9a
--- /dev/null
+++ b/tests/fixtures/0250-bootloader-x86efi.installfile
@@ -0,0 +1,7 @@
+network false
+hostname test.machine
+pkginstall adelie-base
+rootpw $6$gumtLGmHwOVIRpQR$2M9PUO24hy5mofzWWf9a.YLbzOgOlUby1g0hDj.wG67E2wrrvys59fq02PPdxBdbgkLZFtjfEx6MHZwMBamwu/
+mount /dev/sda1 /
+arch pmmx
+bootloader grub-efi
diff --git a/tests/fixtures/0251-bootloader-x86bios.installfile b/tests/fixtures/0251-bootloader-x86bios.installfile
new file mode 100644
index 0000000..dbc461d
--- /dev/null
+++ b/tests/fixtures/0251-bootloader-x86bios.installfile
@@ -0,0 +1,7 @@
+network false
+hostname test.machine
+pkginstall adelie-base
+rootpw $6$gumtLGmHwOVIRpQR$2M9PUO24hy5mofzWWf9a.YLbzOgOlUby1g0hDj.wG67E2wrrvys59fq02PPdxBdbgkLZFtjfEx6MHZwMBamwu/
+mount /dev/sda1 /
+arch x86_64
+bootloader grub-bios
diff --git a/tests/fixtures/0252-bootloader-alpha.installfile b/tests/fixtures/0252-bootloader-alpha.installfile
new file mode 100644
index 0000000..d522901
--- /dev/null
+++ b/tests/fixtures/0252-bootloader-alpha.installfile
@@ -0,0 +1,7 @@
+network false
+hostname test.machine
+pkginstall adelie-base
+rootpw $6$gumtLGmHwOVIRpQR$2M9PUO24hy5mofzWWf9a.YLbzOgOlUby1g0hDj.wG67E2wrrvys59fq02PPdxBdbgkLZFtjfEx6MHZwMBamwu/
+mount /dev/sda1 /
+arch alpha
+bootloader aboot
diff --git a/tests/spec/validator_spec.rb b/tests/spec/validator_spec.rb
index d2d121a..ceed3c2 100644
--- a/tests/spec/validator_spec.rb
+++ b/tests/spec/validator_spec.rb
@@ -133,11 +133,10 @@ RSpec.describe 'HorizonScript validation', :type => :aruba do
expect(last_command_started).to have_output(/error: .*hostname.*/)
end
# Runner.Validate.hostname.Begin.
- it "with non-alphabetical first character" do
- use_fixture '0024-numeric-hostname.installfile'
+ it "with non-alphanumeric first character" do
+ use_fixture '0246-hostname-nonalnum.installfile'
run_validate
- expect(last_command_started).to have_output(PARSER_SUCCESS)
- expect(last_command_started).to have_output(VALIDATOR_SUCCESS)
+ expect(last_command_started).to have_output(/error: .*hostname.*/)
end
# Runner.Validate.hostname.Length
it "with >320 characters" do
@@ -689,6 +688,19 @@ RSpec.describe 'HorizonScript validation', :type => :aruba do
expect(last_command_started).to have_output(/error: .*signingkey.*too many/)
end
end
+ context "for 'version' key" do
+ it "succeeds with a basic version string" do
+ use_fixture '0247-version-basic.installfile'
+ run_validate
+ expect(last_command_started).to have_output(PARSER_SUCCESS)
+ expect(last_command_started).to have_output(VALIDATOR_SUCCESS)
+ end
+ it "fails with an invalid version string" do
+ use_fixture '0248-version-invalid.installfile'
+ run_validate
+ expect(last_command_started).to have_output(/error: .*version.*/)
+ end
+ end
context "for 'pkginstall' key" do
it "warns when a package is listed twice in the same line" do
use_fixture '0216-pkginstall-dup-single.installfile'
@@ -1135,6 +1147,31 @@ RSpec.describe 'HorizonScript validation', :type => :aruba do
expect(last_command_started).to have_output(/error: .*fs.*already/)
end
end
+ context "for 'bootloader' key" do
+ it "succeeds with valid values" do
+ use_fixture '0250-bootloader-x86efi.installfile'
+ run_validate
+ expect(last_command_started).to have_output(PARSER_SUCCESS)
+ expect(last_command_started).to have_output(VALIDATOR_SUCCESS)
+ use_fixture '0251-bootloader-x86bios.installfile'
+ run_validate
+ expect(last_command_started).to have_output(PARSER_SUCCESS)
+ expect(last_command_started).to have_output(VALIDATOR_SUCCESS)
+ end
+ it "fails with invalid values" do
+ use_fixture '0240-bootloader-invalid.installfile'
+ run_validate
+ expect(last_command_started).to have_output(/error: .*bootloader.*/)
+ use_fixture '0249-bootloader-ppc.installfile'
+ run_validate
+ expect(last_command_started).to have_output(/error: .*bootloader.*/)
+ end
+ it "fails with unprepared architectures" do
+ use_fixture '0252-bootloader-alpha.installfile'
+ run_validate
+ expect(last_command_started).to have_output(/error: .*bootloader.*/)
+ end
+ end
context "for 'keymap' key" do
it "succeeds with a simple value" do
use_fixture '0178-keymap-basic.installfile'