From 1b5698b56f40cfe84eef406de00fddabceac07db Mon Sep 17 00:00:00 2001 From: Tomek Mrugalski Date: Mon, 10 Sep 2018 21:41:05 +0200 Subject: [PATCH] [#65,!18] Unit-test added for sanity checking the environment. --- src/lib/yang/tests/translator_unittests.cc | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) 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. -- 2.47.2