Certainly! Here's a step-by-step guide to add your test SQL script to your AGE source code.
After having your function installed at the source code (Congrats) you have to attach you test suite with it to be able to get it merged into the project's repo.
So if you need to learn how to add your first function to your source code, you can find that here on my blog.
Firstly you must be aware of the testing strategy that is followed.
We assert SQL script with its output with a pre-run script output.
For example:
INSERT 1 INTO tbl;
SELECT * FROM tbl;
-----
num
-----
1
That is the output SQL for example test.out
and the SQL script it self will be having the commands only
i.e.
INSERT 1 INTO tbl;
SELECT * FROM tbl;
So that, we can compare the pre-made output with the SQL script new output.
The apache age tests are on regress directory.
it contains:
- expected
- sql
those the directories which we will have to add our test suite into.
the SQL script into sql directory and sql.out into expected directory.
But if we are having a very large script, how can we get the output file contains the SQL commands and their output directly without having to make copy and paste.
How can we automate that?
For example after having adding the age_fact() function; factorial function.
I have created the following script for testing:
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
LOAD 'age';
SET search_path TO ag_catalog;
SELECT create_graph('math_test');
-- Factorial function tests age_fact()
-- 0! = 1
SELECT * FROM age_fact(0);
-- 1! = 1
SELECT * FROM age_fact(1);
-- 5! = 120
SELECT * FROM age_fact(5);
-- 10! = 3628800
SELECT * FROM age_fact(100);
-- 20! = 2432902008176640000
SELECT * FROM age_fact(500);
-- Overflow test
SELECT * FROM age_fact(32178);
-- Inside the cypher query
-- At CREATE clause
SELECT * FROM cypher('math_test', $$
CREATE (n:Node {value: fact(5)})
RETURN n.value
$$) AS (value agtype);
-- At MATCH clause
SELECT * FROM cypher('math_test', $$
MATCH (n:Node {value: fact(5)})
RETURN n.value
$$) AS (value agtype);
-- At RETURN clause
SELECT * FROM cypher('math_test', $$
MATCH (n:Node {value: fact(5)})
RETURN fact(toInteger(n.value))
$$) AS (value agtype);
-- At WHERE clause
SELECT * FROM cypher('math_test', $$
MATCH (n:Node)
WHERE n.value = fact(5)
RETURN n.value
$$) AS (value agtype);
-- At SET clause
SELECT * FROM cypher('math_test', $$
MATCH (n:Node)
SET n.value = fact(3)
RETURN n.value
$$) AS (value agtype);
-- CLEANUP
SELECT * FROM drop_graph('math_test', true);
-- End of math.sql
Having Apache license on top of the SQL script is mandatory
The key point of solving the problem of making the output manually is
FAIL then PASS
- Run the regression tests
- Get it failed and get the output/your_test.out
- Move that to expected.out after making sure of that is the expected output
- Re-run the tests
- (everything passes)
Top comments (0)