From: Tomek Mrugalski Date: Mon, 10 Sep 2018 19:41:05 +0000 (+0200) Subject: [#65,!18] Unit-test added for sanity checking the environment. X-Git-Tag: 65-libyang-control-socket_base~1^2~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1b5698b56f40cfe84eef406de00fddabceac07db;p=thirdparty%2Fkea.git [#65,!18] Unit-test added for sanity checking the environment. --- diff --git a/src/lib/yang/tests/translator_unittests.cc b/src/lib/yang/tests/translator_unittests.cc index 49ab57d659..263de9be90 100644 --- a/src/lib/yang/tests/translator_unittests.cc +++ b/src/lib/yang/tests/translator_unittests.cc @@ -18,6 +18,41 @@ using namespace isc::yang; namespace { +const std::string TEST_MODULE="example-module"; + +// This test verifies if there are test models installed and accessible. +// To run those tests properly, the following models need to be installed: +// - example-module +// - test-module +TEST(TranslatorBasicTest, testEnvironmentCheck) { + // Get a connection. + S_Connection conn(new Connection("translator unittests")); + // Get a session. + S_Session sess(new Session(conn, SR_DS_CANDIDATE)); + + S_Yang_Schemas schemas = sess->list_schemas(); + + size_t schema_cnt = schemas->schema_cnt(); + std::cout << "There are " << schema_cnt << " YANG schema(s) installed:" << endl; + + bool found = false; + for (int i = 0; i < schema_cnt; i++) { + string name(schemas->schema(i)->module_name()); + if (name == TEST_MODULE) { + found = true; + } + std::cout << "Schema " << i << ": " << name << endl; + } + + EXPECT_TRUE(found) << "\nERROR: Module used in unit-tests " << TEST_MODULE + << " is not installed. The environment is not suitable for\n" + << "ERROR: running unit-tests. Please locate example-module.yang " + << "and issue the following command:\n" + << "ERROR: sysrepoctl --install --yang=example-module.yang\n" + << "ERROR:\n" + << "ERROR: Following tests will most likely fail.\n"; +} + // Test constructor. TEST(TranslatorBasicTest, constructor) { // Get a connection.