Comments (6)
The example uses a user defined MySQL function, so something like this:
begin delimiter //
create function insert_stuff(url, string, domain, src)
returns boolean
begin
insert into table values(url, string, domain, src);
return -- some indication if all was well
end //
end delimiter //
-- Insert stuff.
SELECT tap.ok(
insert_stuff( 'www.foo.com', '1,2,3', @domain_id, @src_id ),
'insert_stuff() should return true'
);
from mytap.
What if the insertion fails due to constraints? I wanted to test that an insertion would fail. I could do this inside a scripting language outside of SQL, but inside SQL?...
from mytap.
I usually solve this with a helper procedure: check in the procedure for the errors in the error handler and fill a temp table accordingly. Then I use tap.ok to test for the expected value in the table.
from mytap.
Can you give an example on how that would work?
from mytap.
Two thoughts here:
- if you want to check in a function if a certain statements fails or succeeds, that's not possible in MySQL. MySQL simply lacks that feature.
- if you want to check if a certain statement correctly inserts the provided data, that's more of an end-to-end test and outside the scope of MyTAP. You're better off testing that in the app that adds the data.
The primary focus of MyTAP is providing a test framework for schema validation.
from mytap.
To @hepabolu's point
Unlike postgresql and the pgTAP project which spawned this project, MySQL doesn't allow you to pass arbitrary SQL to a stored function and then execute it, dynamic SQL only works in stored procedures. Your insert statement can't be the first argument to any of the tap emitting functions, neither can you CALL a stored procedure which could run it inline within a SELECT statement containing the tap emitting function. The example you quote is a function returning TRUE within a stored function - which is legal in MySQL. MyTAP will allow you to test whether the table and the columns you wish to insert into exist and a multitude of other properties on those schema objects but it wont run an arbitrary insert statement and tell you whether they succeeded or failed.
from mytap.
Related Issues (20)
- test results in multiple rows HOT 2
- Setting up Travis jobs to test the scripts against various MySQL versions HOT 14
- Check for timezone information HOT 7
- Split out version specific code
- Installer HOT 9
- MySQL Version 8.0 support HOT 9
- Allow the usage of unix domain socket HOT 4
- Test user/role privileges HOT 10
- Refactor HOT 6
- Aurora Mysql Support HOT 7
- Mariadb support HOT 7
- How to test stored procedure? HOT 2
- Problems installing mytap HOT 7
- POC: Implement `runtests()` in myTAP HOT 6
- Typo in column name HOT 2
- RANGE COLUMNS not supported in tap.partition_method_is
- Question: is it possible to use mytap to check deadlock issue? HOT 5
- Site is Down HOT 1
- Convert Travis tasks to GitHub actions
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mytap.