#include #include #include #include #include #include #include "../../collection_fixture.hpp" using namespace std; using namespace facter::facts; using namespace facter::facts::resolvers; using namespace facter::testing; struct empty_zone_resolver : zone_resolver { protected: virtual data collect_data(collection& facts) override { data result; return result; } }; struct test_zone_resolver : zone_resolver { protected: virtual data collect_data(collection& facts) override { data result; result.current_zone_name = "current"; zone z; z.uuid = "uuid"; z.status = "status"; z.path = "path"; z.name = "name"; z.brand = "brand"; z.id = "id"; z.ip_type = "ip type"; result.zones.emplace_back(move(z)); return result; } }; SCENARIO("using the Solaris zone resolver") { collection_fixture facts; WHEN("data is not present") { facts.add(make_shared()); THEN("only the zone count should be added") { REQUIRE(facts.size() == 1u); auto value = facts.get(fact::zones); REQUIRE(value); REQUIRE(value->value() == 0); } } WHEN("data is present") { facts.add(make_shared()); THEN("a structured fact is added") { REQUIRE(facts.size() == 10u); auto mval = facts.get(fact::solaris_zones); REQUIRE(mval); REQUIRE(mval->size() == 2u); auto sval = mval->get("current"); REQUIRE(sval); REQUIRE(sval->value() == "current"); mval = mval->get("zones"); REQUIRE(mval); REQUIRE(mval->size() == 1u); mval = mval->get("name"); REQUIRE(mval); REQUIRE(mval->size() == 6u); sval = mval->get("uuid"); REQUIRE(sval); REQUIRE(sval->value() == "uuid"); sval = mval->get("status"); REQUIRE(sval); REQUIRE(sval->value() == "status"); sval = mval->get("path"); REQUIRE(sval); REQUIRE(sval->value() == "path"); sval = mval->get("brand"); REQUIRE(sval); REQUIRE(sval->value() == "brand"); sval = mval->get("id"); REQUIRE(sval); REQUIRE(sval->value() == "id"); sval = mval->get("ip_type"); REQUIRE(sval); REQUIRE(sval->value() == "ip type"); } THEN("flat facts are added") { REQUIRE(facts.size() == 10u); auto ival = facts.get(fact::zones); REQUIRE(ival); REQUIRE(ival->value() == 1); auto sval = facts.get(fact::zonename); REQUIRE(sval); REQUIRE(sval->value() == "current"); sval = facts.get(string("zone_name_") + fact::zone_iptype); REQUIRE(sval); REQUIRE(sval->value() == "ip type"); sval = facts.get(string("zone_name_") + fact::zone_brand); REQUIRE(sval); REQUIRE(sval->value() == "brand"); sval = facts.get(string("zone_name_") + fact::zone_uuid); REQUIRE(sval); REQUIRE(sval->value() == "uuid"); sval = facts.get(string("zone_name_") + fact::zone_id); REQUIRE(sval); REQUIRE(sval->value() == "id"); sval = facts.get(string("zone_name_") + fact::zone_name); REQUIRE(sval); REQUIRE(sval->value() == "name"); sval = facts.get(string("zone_name_") + fact::zone_path); REQUIRE(sval); REQUIRE(sval->value() == "path"); sval = facts.get(string("zone_name_") + fact::zone_status); REQUIRE(sval); REQUIRE(sval->value() == "status"); } } }