Skip to content

Commit

Permalink
Creating babelfisgpg_unit Extension (babelfish-for-postgresql#1586)
Browse files Browse the repository at this point in the history
Description
At present, babelfish encompasses various testing frameworks such as JDBC, Python, .NET, and fuzz tests. Each of these frameworks serves specific purposes and relies on client drivers. However, we lack a framework dedicated to unit testing. This is the motivation behind this to create a unit testing framework for babelfish.

In this commit, we add unit testing framework which enable us to test any piece of our codebase. The babelfishpg_unit directory is added as a new extension within the contrib folder present in babelfish_extensions. It contains the necessary files for the unit testing framework. Here's a brief explanation of each file:

Makefile: This file specifies the build instructions for the babelfishpg_unit extension.
babelfishpg_unit.control: This files contain metadata and control information about the extension.
babelfishpg_unit.h: This header file contains any necessary macros, definitions, or utility functions required for the unit tests.
babelfishpg_unit—1.0.0.sql: This SQL script defines the necessary functions and setup for running the tests. It acts as the entry point for invoking the unit tests. Once it is invoked, it will trigger the execution of all the tests or specific tests.
babelfishpg_unit.c: This file serves as the main entry point for the unit tests. It includes the necessary headers and implements the logic to execute all the defined tests.
test_money.c, ...: These are the individual test files which contains the test cases and assertions specific to a particular area of functionality or component being tested.
log_files: It is a folder which contains log files created after each test run
Issues Resolved
I have developed the framework in such a way that we can run multiple tests by passing multiple parameters. With this framework, all test functions associated with multiple specified parameters can be successfully executed.

Signed-off-by: Yenni Shashank [email protected]
  • Loading branch information
shashank-yenni authored and ahmed-shameem committed Aug 17, 2023
1 parent c365072 commit ba0e003
Show file tree
Hide file tree
Showing 6 changed files with 893 additions and 0 deletions.
12 changes: 12 additions & 0 deletions contrib/babelfishpg_unit/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
MODULE_big = babelfishpg_unit
EXTENSION = babelfishpg_unit # the extension's name
DATA = babelfishpg_unit--1.0.0.sql # script file to install
OBJS = $(SRCS:.c=.o) # object files

# source code files
SRCS = babelfishpg_unit.c test_money.c \

# for posgres build
PG_CONFIG = pg_config
PGXS := $(shell $(PG_CONFIG) --pgxs)
include $(PGXS)
16 changes: 16 additions & 0 deletions contrib/babelfishpg_unit/babelfishpg_unit--1.0.0.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
--complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION babelfishpg_unit" to load this file. \quit


-- Invoke all tests
CREATE OR REPLACE FUNCTION babelfishpg_unit_run_tests() RETURNS
TABLE(TEST_NAME text, STATUS text, "runtime(µs)" bigint, ENABLED text)
as 'babelfishpg_unit', 'babelfishpg_unit_run_tests'
LANGUAGE C IMMUTABLE STRICT;


-- Invoke specific tests by passing test_name, cateogry_name or JIRA associated with
CREATE OR REPLACE FUNCTION babelfishpg_unit_run_tests(VARIADIC name text[]) RETURNS
TABLE(TEST_NAME text, STATUS text, "runtime(µs)" bigint, ENABLED text)
as 'babelfishpg_unit', 'babelfishpg_unit_run_tests'
LANGUAGE C IMMUTABLE STRICT;
Loading

0 comments on commit ba0e003

Please sign in to comment.