56 lines
2.8 KiB
C++
56 lines
2.8 KiB
C++
#include <catch2/catch_test_macros.hpp>
|
|
|
|
#include "matador/object/attribute_definition_generator.hpp"
|
|
#include "matador/object/schema.hpp"
|
|
|
|
#include "../test/models/product.hpp"
|
|
#include "../test/models/optional.hpp"
|
|
|
|
using namespace matador::object;
|
|
using namespace matador::utils;
|
|
|
|
TEST_CASE("Generate column definitions from object", "[column][definition][generator]") {
|
|
schema repo("main");
|
|
|
|
auto columns = attribute_definition_generator::generate<matador::test::product>(repo);
|
|
|
|
const std::vector expected_columns = {
|
|
attribute_definition{"product_name", basic_type::type_varchar, constraints::PRIMARY_KEY, null_option::NOT_NULL },
|
|
attribute_definition{"supplier_id", basic_type::type_uint32, constraints::FOREIGN_KEY, null_option::NOT_NULL },
|
|
attribute_definition{"category_id", basic_type::type_uint32, constraints::FOREIGN_KEY, null_option::NOT_NULL },
|
|
attribute_definition{"quantity_per_unit", basic_type::type_varchar, null_attributes, null_option::NOT_NULL },
|
|
attribute_definition{"unit_price", basic_type::type_uint32, null_attributes, null_option::NOT_NULL },
|
|
attribute_definition{"units_in_stock", basic_type::type_uint32, null_attributes, null_option::NOT_NULL },
|
|
attribute_definition{"units_in_order", basic_type::type_uint32, null_attributes, null_option::NOT_NULL },
|
|
attribute_definition{"reorder_level", basic_type::type_uint32, null_attributes, null_option::NOT_NULL },
|
|
attribute_definition{"discontinued", basic_type::type_bool, null_attributes, null_option::NOT_NULL }
|
|
};
|
|
REQUIRE(!columns.empty());
|
|
REQUIRE(columns.size() == expected_columns.size());
|
|
|
|
for (size_t i = 0; i != expected_columns.size(); ++i) {
|
|
REQUIRE(expected_columns[i].name() == columns[i].name());
|
|
REQUIRE(expected_columns[i].attributes().options() == columns[i].attributes().options() );
|
|
REQUIRE(expected_columns[i].type() == columns[i].type() );
|
|
}
|
|
}
|
|
|
|
TEST_CASE("Generate columns from object with nullable columns", "[column generator]") {
|
|
schema repo("main");
|
|
|
|
auto columns = attribute_definition_generator::generate<matador::test::optional>(repo);
|
|
|
|
const std::vector expected_columns = {
|
|
attribute_definition{"id", basic_type::type_uint32, constraints::PRIMARY_KEY, null_option::NOT_NULL },
|
|
attribute_definition{"name", basic_type::type_varchar, null_attributes, null_option::NOT_NULL },
|
|
attribute_definition{"age", basic_type::type_uint32, null_attributes, null_option::NOT_NULL }
|
|
};
|
|
REQUIRE(!columns.empty());
|
|
REQUIRE(columns.size() == expected_columns.size());
|
|
|
|
for (size_t i = 0; i != expected_columns.size(); ++i) {
|
|
REQUIRE(expected_columns[i].name() == columns[i].name());
|
|
REQUIRE(expected_columns[i].attributes().options() == columns[i].attributes().options() );
|
|
REQUIRE(expected_columns[i].type() == columns[i].type() );
|
|
}
|
|
} |