Git Product home page Git Product logo

Comments (6)

hepabolu avatar hepabolu commented on September 13, 2024

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.

CMCDragonkai avatar CMCDragonkai commented on September 13, 2024

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.

hepabolu avatar hepabolu commented on September 13, 2024

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.

CMCDragonkai avatar CMCDragonkai commented on September 13, 2024

Can you give an example on how that would work?

from mytap.

hepabolu avatar hepabolu commented on September 13, 2024

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.

animalcarpet avatar animalcarpet commented on September 13, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.