diff options
author | Roger Leigh <rleigh@debian.org> | 2012-03-25 19:53:26 +0100 |
---|---|---|
committer | Roger Leigh <rleigh@debian.org> | 2012-04-03 21:35:18 +0100 |
commit | 036fe3ddbb9029367a7faf42eed50f0e21dc716f (patch) | |
tree | 1922e060b5ec2e128800322a7dc7258e2f1b8b4c /test | |
parent | 046829da98ac40511b395ffdf16a840814e3bf0a (diff) | |
download | schroot-036fe3ddbb9029367a7faf42eed50f0e21dc716f.tar.gz |
sbuild: Add sbuild::chroot_facet_userdata and --option option
Diffstat (limited to 'test')
-rw-r--r-- | test/.gitignore | 1 | ||||
-rw-r--r-- | test/Makefile.am | 7 | ||||
-rw-r--r-- | test/sbuild-chroot-facet-userdata.cc | 156 | ||||
-rw-r--r-- | test/test-sbuild-chroot.h | 21 |
4 files changed, 185 insertions, 0 deletions
diff --git a/test/.gitignore b/test/.gitignore index ab5602c1..2252e2e5 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -7,6 +7,7 @@ sbuild-chroot-btrfs-snapshot sbuild-chroot-lvm-snapshot sbuild-chroot-plain sbuild-chroot-config +sbuild-chroot-facet-userdata sbuild-environment sbuild-keyfile sbuild-lock diff --git a/test/Makefile.am b/test/Makefile.am index 003f7f2f..e3fe5d16 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -36,6 +36,7 @@ noinst_PROGRAMS = \ sbuild-chroot-lvm-snapshot \ sbuild-chroot-btrfs-snapshot \ sbuild-chroot-config \ + sbuild-chroot-facet-userdata \ sbuild-environment \ sbuild-keyfile \ sbuild-lock \ @@ -60,6 +61,7 @@ TESTS = setup-test-data \ sbuild-chroot-lvm-snapshot \ sbuild-chroot-btrfs-snapshot \ sbuild-chroot-config \ + sbuild-chroot-facet-userdata \ sbuild-environment \ sbuild-keyfile \ sbuild-log \ @@ -138,6 +140,11 @@ sbuild_chroot_loopback_SOURCES = \ test-sbuild-chroot.h sbuild_chroot_loopback_LDADD = libtest.la +sbuild_chroot_facet_userdata_SOURCES = \ + sbuild-chroot-facet-userdata.cc \ + test-sbuild-chroot.h +sbuild_chroot_facet_userdata_LDADD = libtest.la + sbuild_chroot_config_SOURCES = sbuild-chroot-config.cc sbuild_chroot_config_LDADD = libtest.la diff --git a/test/sbuild-chroot-facet-userdata.cc b/test/sbuild-chroot-facet-userdata.cc new file mode 100644 index 00000000..f6674773 --- /dev/null +++ b/test/sbuild-chroot-facet-userdata.cc @@ -0,0 +1,156 @@ +/* Copyright © 2006-2008 Roger Leigh <rleigh@debian.org> + * + * schroot is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * schroot is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see + * <http://www.gnu.org/licenses/>. + * + *********************************************************************/ + +#include <config.h> + +#include <sbuild/sbuild-chroot-directory.h> +#include <sbuild/sbuild-chroot-facet-userdata.h> + +#include <cppunit/extensions/HelperMacros.h> + +using namespace CppUnit; + +using sbuild::_; + +class test_chroot_facet_userdata : public TestFixture +{ + CPPUNIT_TEST_SUITE(test_chroot_facet_userdata); + CPPUNIT_TEST(test_data_set); + CPPUNIT_TEST_EXCEPTION(test_data_fail1, sbuild::chroot_facet_userdata::error); + CPPUNIT_TEST_EXCEPTION(test_data_fail2, sbuild::chroot_facet_userdata::error); + CPPUNIT_TEST(test_user_set); + CPPUNIT_TEST_EXCEPTION(test_user_fail1, sbuild::chroot_facet_userdata::error); + CPPUNIT_TEST_EXCEPTION(test_user_fail2, sbuild::chroot_facet_userdata::error); + CPPUNIT_TEST(test_root_set); + CPPUNIT_TEST_EXCEPTION(test_root_fail, sbuild::chroot_facet_userdata::error); + CPPUNIT_TEST_SUITE_END(); + +public: + test_chroot_facet_userdata(): + chroot(), + userdata() + {} + + void setUp() + { + chroot = sbuild::chroot::create("directory"); + CPPUNIT_ASSERT(chroot); + + userdata = chroot->get_facet<sbuild::chroot_facet_userdata>(); + CPPUNIT_ASSERT(userdata); + + sbuild::string_set userkeys; + userkeys.insert("sbuild.resolver"); + userkeys.insert("debian.dist"); + userkeys.insert("sbuild.purge"); + sbuild::string_set rootkeys; + rootkeys.insert("debian.apt-update"); + userdata->set_user_modifiable_keys(userkeys); + userdata->set_root_modifiable_keys(rootkeys); + } + + void tearDown() + { + this->chroot = sbuild::chroot::ptr(); + this->userdata = sbuild::chroot_facet_userdata::ptr(); + } + + void test_data_set() + { + userdata->set_data("custom.test1", "testval"); + userdata->set_data("sbuild.resolver", "apt"); + + std::string t1; + CPPUNIT_ASSERT(userdata->get_data("custom.test1", t1)); + CPPUNIT_ASSERT(t1 == "testval"); + + std::string t2; + CPPUNIT_ASSERT(userdata->get_data("sbuild.resolver", t2)); + CPPUNIT_ASSERT(t2 == "apt"); + + std::string t3("invalid"); + CPPUNIT_ASSERT(!userdata->get_data("invalidkey", t3)); + CPPUNIT_ASSERT(t3 == "invalid"); + } + + void test_data_fail1() + { + userdata->set_data("custom", "testval"); + } + + void test_data_fail2() + { + userdata->set_data("custom.key.set", "testval1"); + userdata->set_data("custom.key_set", "testval2"); + } + + void test_user_set() + { + sbuild::string_map d; + d.insert(std::make_pair("sbuild.resolver", "aptitude")); + userdata->set_user_data(d); + + std::string t1; + CPPUNIT_ASSERT(userdata->get_data("sbuild.resolver", t1)); + CPPUNIT_ASSERT(t1 == "aptitude"); + } + + void test_user_fail1() + { + sbuild::string_map d; + d.insert(std::make_pair("sbuild.apt-update", "true")); + userdata->set_user_data(d); + } + + void test_user_fail2() + { + // Use root key. + sbuild::string_map d; + d.insert(std::make_pair("debian.apt-update", "false")); + userdata->set_user_data(d); + } + + void test_root_set() + { + sbuild::string_map d; + d.insert(std::make_pair("sbuild.resolver", "aptitude")); + d.insert(std::make_pair("debian.apt-update", "false")); + userdata->set_root_data(d); + + std::string t1; + CPPUNIT_ASSERT(userdata->get_data("sbuild.resolver", t1)); + CPPUNIT_ASSERT(t1 == "aptitude"); + + std::string t2; + CPPUNIT_ASSERT(userdata->get_data("debian.apt-update", t2)); + CPPUNIT_ASSERT(t2 == "false"); + } + + void test_root_fail() + { + sbuild::string_map d; + d.insert(std::make_pair("invalid.key", "testv")); + userdata->set_root_data(d); + } + +private: + sbuild::chroot::ptr chroot; + sbuild::chroot_facet_userdata::ptr userdata; +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(test_chroot_facet_userdata); diff --git a/test/test-sbuild-chroot.h b/test/test-sbuild-chroot.h index b68c2e94..efd1d1c6 100644 --- a/test/test-sbuild-chroot.h +++ b/test/test-sbuild-chroot.h @@ -27,7 +27,9 @@ #include <sbuild/sbuild-chroot-facet-source.h> #include <sbuild/sbuild-chroot-facet-source-clonable.h> #include <sbuild/sbuild-chroot-facet-union.h> +#include <sbuild/sbuild-chroot-facet-userdata.h> #include <sbuild/sbuild-i18n.h> +#include <sbuild/sbuild-types.h> #include <sbuild/sbuild-util.h> #include <algorithm> @@ -168,6 +170,21 @@ public: usrc->set_source_groups(sbuild::split_string("sgroup1,sgroup2", ",")); usrc->set_source_root_groups(sbuild::split_string("sgroup3,sgroup4", ",")); } + + sbuild::chroot_facet_userdata::ptr pusr + (chroot->get_facet<sbuild::chroot_facet_userdata>()); + if (pusr) + { + pusr->set_data("custom.test1", "testval"); + sbuild::string_set userkeys; + userkeys.insert("sbuild.resolver"); + userkeys.insert("debian.dist"); + userkeys.insert("sbuild.purge"); + sbuild::string_set rootkeys; + rootkeys.insert("debian.apt-update"); + pusr->set_user_modifiable_keys(userkeys); + pusr->set_root_modifiable_keys(rootkeys); + } } void tearDown() @@ -181,6 +198,7 @@ public: env.add("SESSION_ID", "test-name"); env.add("CHROOT_DESCRIPTION", "test-description"); env.add("CHROOT_SCRIPT_CONFIG", sbuild::normalname(std::string(SCHROOT_SYSCONF_DIR) + "/default/config")); + env.add("CUSTOM_TEST1", "testval"); } void setup_keyfile_chroot (sbuild::keyfile& keyfile, @@ -198,6 +216,9 @@ public: keyfile.set_value(group, "script-config", "default/config"); keyfile.set_value(group, "message-verbosity", "quiet"); keyfile.set_value(group, "preserve-environment", "false"); + keyfile.set_value(group, "user-modifiable-keys", "debian.dist,sbuild.purge,sbuild.resolver"); + keyfile.set_value(group, "root-modifiable-keys", "debian.apt-update"); + keyfile.set_value(group, "custom.test1", "testval"); } void setup_keyfile_session (sbuild::keyfile& keyfile, |